Search in sources :

Example 21 with SemanticPipeline

use of org.antlr.v4.semantics.SemanticPipeline in project antlr4 by tunnelvisionlabs.

the class TestCodeGeneration method getEvalInfoForString.

public List<String> getEvalInfoForString(String grammarString, String pattern) throws RecognitionException {
    ErrorQueue equeue = new ErrorQueue();
    Grammar g = new Grammar(grammarString);
    List<String> evals = new ArrayList<String>();
    if (g.ast != null && !g.ast.hasErrors) {
        SemanticPipeline sem = new SemanticPipeline(g);
        sem.process();
        ATNFactory factory = new ParserATNFactory(g);
        if (g.isLexer())
            factory = new LexerATNFactory((LexerGrammar) g);
        g.atn = factory.createATN();
        CodeGenerator gen = new CodeGenerator(g);
        ST outputFileST = gen.generateParser();
        // STViz viz = outputFileST.inspect();
        // try {
        // viz.waitForClose();
        // }
        // catch (Exception e) {
        // e.printStackTrace();
        // }
        boolean debug = false;
        DebugInterpreter interp = new DebugInterpreter(outputFileST.groupThatCreatedThisInstance, outputFileST.impl.nativeGroup.errMgr, debug);
        InstanceScope scope = new InstanceScope(null, outputFileST);
        StringWriter sw = new StringWriter();
        AutoIndentWriter out = new AutoIndentWriter(sw);
        interp.exec(out, scope);
        for (String e : interp.evals) {
            if (e.contains(pattern)) {
                evals.add(e);
            }
        }
    }
    if (equeue.size() > 0) {
        System.err.println(equeue.toString());
    }
    return evals;
}
Also used : SemanticPipeline(org.antlr.v4.semantics.SemanticPipeline) ST(org.stringtemplate.v4.ST) ArrayList(java.util.ArrayList) Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) CodeGenerator(org.antlr.v4.codegen.CodeGenerator) LexerATNFactory(org.antlr.v4.automata.LexerATNFactory) AutoIndentWriter(org.stringtemplate.v4.AutoIndentWriter) ParserATNFactory(org.antlr.v4.automata.ParserATNFactory) StringWriter(java.io.StringWriter) ParserATNFactory(org.antlr.v4.automata.ParserATNFactory) ATNFactory(org.antlr.v4.automata.ATNFactory) LexerATNFactory(org.antlr.v4.automata.LexerATNFactory) InstanceScope(org.stringtemplate.v4.InstanceScope)

Example 22 with SemanticPipeline

use of org.antlr.v4.semantics.SemanticPipeline in project antlr4 by antlr.

the class BaseRuntimeTestSupport method semanticProcess.

protected void semanticProcess(Grammar g) {
    if (g.ast != null && !g.ast.hasErrors) {
        // System.out.println(g.ast.toStringTree());
        Tool antlr = new Tool();
        SemanticPipeline sem = new SemanticPipeline(g);
        sem.process();
        if (g.getImportedGrammars() != null) {
            // process imported grammars (if any)
            for (Grammar imp : g.getImportedGrammars()) {
                antlr.processNonCombinedGrammar(imp, false);
            }
        }
    }
}
Also used : SemanticPipeline(org.antlr.v4.semantics.SemanticPipeline) Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Tool(org.antlr.v4.Tool)

Aggregations

SemanticPipeline (org.antlr.v4.semantics.SemanticPipeline)20 Grammar (org.antlr.v4.tool.Grammar)17 LexerGrammar (org.antlr.v4.tool.LexerGrammar)17 ATNFactory (org.antlr.v4.automata.ATNFactory)12 LexerATNFactory (org.antlr.v4.automata.LexerATNFactory)12 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)12 CodeGenerator (org.antlr.v4.codegen.CodeGenerator)9 ST (org.stringtemplate.v4.ST)9 Tool (org.antlr.v4.Tool)8 STGroup (org.stringtemplate.v4.STGroup)7 STGroupString (org.stringtemplate.v4.STGroupString)7 ErrorQueue (org.antlr.v4.test.runtime.ErrorQueue)6 AnalysisPipeline (org.antlr.v4.analysis.AnalysisPipeline)5 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)5 CodeGenPipeline (org.antlr.v4.codegen.CodeGenPipeline)3 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 LeftRecursiveRule (org.antlr.v4.tool.LeftRecursiveRule)2 Rule (org.antlr.v4.tool.Rule)2 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)2