antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.17k stars 3.28k forks source link

Runtime interpreter does not parse/check/use contextSuperClass #3308

Open JRoper18 opened 3 years ago

JRoper18 commented 3 years ago

With a Java target, just create a grammar like this:

grammar test;
options {
    contextSuperClass=org.antlr.v4.runtime.asdasdasdas;
}

<your grammar here>

And then run the following java code (taken from this page on the ANTLR docs):


final Grammar g = Grammar.load(combinedGrammarFileName);
    LexerInterpreter lexEngine = g.createLexerInterpreter(CharStreams.fromPath(Paths.get(fileName)));
    CommonTokenStream tokens = new CommonTokenStream(lexEngine);
    ParserInterpreter parser = g.createParserInterpreter(tokens);
    ParseTree t = parser.parse(g.getRule(startRule).index);
    System.out.println("parse tree: "+t.toStringTree(parser));
    return t;

And then note that contextSuperClass option isn't parsed (or used). You can also set your options like this and check that RuleContextWithAltNum isn't used:


options {
    contextSuperClass=org.antlr.v4.runtime.RuleContextWithAltNum;
}
bdw429s commented 9 months ago

@JRoper18 Did you find closure on this? It seems it's not just the contextSuperClass that doens't work, but Java semantic predicates and lexer @members{} blocks containing Java code.