Search in sources :

Example 1 with StringCodeGenPipeline

use of org.snt.inmemantlr.comp.StringCodeGenPipeline in project inmemantlr by julianthome.

the class InmemantlrTool method createPipeline.

/**
 * create code generation pipeline from grammar ast
 *
 * @param ast grammar ast
 * @return string code generation pipeline
 */
public StringCodeGenPipeline createPipeline(GrammarRootAST ast) {
    if (pip.containsKey(ast.getGrammarName()))
        pip.get(ast.getGrammarName());
    LOGGER.debug("create grammar {}", ast.getGrammarName());
    final Grammar g = createGrammar(ast);
    g.fileName = g.name;
    g.loadImportedGrammars();
    StringCodeGenPipeline spip = new StringCodeGenPipeline(g);
    LOGGER.debug("put grammar {}", g.name);
    pip.put(g.name, spip);
    return spip;
}
Also used : StringCodeGenPipeline(org.snt.inmemantlr.comp.StringCodeGenPipeline) InmemantlrLexerGrammar(org.snt.inmemantlr.grammar.InmemantlrLexerGrammar) InmemantlrGrammar(org.snt.inmemantlr.grammar.InmemantlrGrammar)

Example 2 with StringCodeGenPipeline

use of org.snt.inmemantlr.comp.StringCodeGenPipeline 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)2 InmemantlrGrammar (org.snt.inmemantlr.grammar.InmemantlrGrammar)2 InmemantlrLexerGrammar (org.snt.inmemantlr.grammar.InmemantlrLexerGrammar)2 Tuple (org.snt.inmemantlr.utils.Tuple)1