Search in sources :

Example 1 with InmemantlrLexerGrammar

use of org.snt.inmemantlr.grammar.InmemantlrLexerGrammar in project inmemantlr by julianthome.

the class InmemantlrTool method createGrammar.

@Override
public Grammar createGrammar(GrammarRootAST ast) {
    final Grammar g;
    LOGGER.debug("ast " + ast.getGrammarName());
    if (ast.grammarType == ANTLRParser.LEXER) {
        g = new InmemantlrLexerGrammar(this, ast);
    } else {
        g = new InmemantlrGrammar(this, ast);
    }
    // ensure each node has pointer to surrounding grammar
    GrammarTransformPipeline.setGrammarPtr(g, ast);
    return g;
}
Also used : InmemantlrLexerGrammar(org.snt.inmemantlr.grammar.InmemantlrLexerGrammar) InmemantlrLexerGrammar(org.snt.inmemantlr.grammar.InmemantlrLexerGrammar) InmemantlrGrammar(org.snt.inmemantlr.grammar.InmemantlrGrammar) InmemantlrGrammar(org.snt.inmemantlr.grammar.InmemantlrGrammar)

Example 2 with InmemantlrLexerGrammar

use of org.snt.inmemantlr.grammar.InmemantlrLexerGrammar 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

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