antlr4
antlr4 copied to clipboard
Runtime interpreter does not parse/check/use contextSuperClass
- [check] I have reproduced my issue using the latest version of ANTLR
- [check] I have submitted my issue to antlr4-discussion google group or asked at stackoverflow Here's the starting issue: https://stackoverflow.com/questions/69564585/alternative-numbers-populated-all-to-one-or-zero-for-parserinterpreter After debugging I found this bug which I (think) is with ANTLR
- [check] Responses from the above seem to indicate that my issue could be an ANTLR bug
- [check] I have done a search of the existing issues to make sure I'm not sending in a duplicate
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;
}
@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.