Search in sources :

Example 1 with Tuple

use of org.snt.inmemantlr.utils.Tuple in project inmemantlr by julianthome.

the class InmemantlrTool method process.

/**
 * process all code generation pipeline and return the 'main'
 * grammar and lexer names which are used to load the right classes
 * afterwards
 *
 * @return tuple of lexer and parser names
 */
public Tuple<String, String> process() {
    LOGGER.debug("process grammars");
    StringCodeGenPipeline last = null;
    // order is important here
    Set<StringCodeGenPipeline> pip = getPipelines();
    if (pip.isEmpty())
        throw new IllegalArgumentException("pip must not be empty");
    for (StringCodeGenPipeline p : pip) {
        Grammar g = p.getG();
        LOGGER.debug("process {}", g.name);
        String s = getDepTokVocName(g);
        if (s != null && !s.isEmpty() && tokvok.containsKey(s) && tokvok.get(s) != null) {
            LOGGER.debug("get {}", s);
            String tokvoc = tokvok.get(s);
            if (g instanceof InmemantlrGrammar) {
                LOGGER.debug("import from {}", tokvoc);
                ((InmemantlrGrammar) g).setTokenVocab(tokvoc);
            } else if (g instanceof InmemantlrLexerGrammar) {
                LOGGER.debug("2");
                ((InmemantlrLexerGrammar) g).setTokenVocab(tokvoc);
            }
        }
        if (!isImported(g.name)) {
            process(p.getG());
            p.process();
            setParserLexer(p.getG());
            if (p.hasTokenVocab()) {
                LOGGER.debug("put tokvok {}", g.name);
                tokvok.put(g.name, p.getTokenVocabString());
            }
        }
    }
    if (lexerName.isEmpty())
        throw new IllegalArgumentException("lexerName must not be empty");
    if (parserName.isEmpty())
        throw new IllegalArgumentException("parserName must not be empty");
    return new Tuple<>(parserName, lexerName);
}
Also used : StringCodeGenPipeline(org.snt.inmemantlr.comp.StringCodeGenPipeline) InmemantlrLexerGrammar(org.snt.inmemantlr.grammar.InmemantlrLexerGrammar) InmemantlrLexerGrammar(org.snt.inmemantlr.grammar.InmemantlrLexerGrammar) InmemantlrGrammar(org.snt.inmemantlr.grammar.InmemantlrGrammar) InmemantlrGrammar(org.snt.inmemantlr.grammar.InmemantlrGrammar) Tuple(org.snt.inmemantlr.utils.Tuple)

Aggregations

StringCodeGenPipeline (org.snt.inmemantlr.comp.StringCodeGenPipeline)1 InmemantlrGrammar (org.snt.inmemantlr.grammar.InmemantlrGrammar)1 InmemantlrLexerGrammar (org.snt.inmemantlr.grammar.InmemantlrLexerGrammar)1 Tuple (org.snt.inmemantlr.utils.Tuple)1