[antlr-interest] RewriteEmptyStreamException from antlr-2007-12-31.17 interim 3b1 build
John B. Brodie
jbb at acm.org
Thu Jan 3 15:58:45 PST 2008
Greetings!
<Apologies in advance if this message is inappropriate for this list>
I am using the antlr-2007-12-31.17.tar.gz interim build of 3b1
(playing with tree rewrites via output=AST in a tree grammar)
and discovered a minor hiccup when parsing erroneous an input.
(note this is in PARSING not tree walking nor rewriting)
this Test.g grammar:
grammar Test;
options {
output = AST;
ASTLabelType = CommonTree;
}
tokens{ ROOT; }
start : ( a )* required=b EOF -> ^(ROOT a* $required) ;
a : 'a' ;
b : 'b' ;
obtains this exception when trying to PARSE a sentence that is just the
letter a :
line 0:-1 mismatched input '<EOF>' expecting 'b'
org.antlr.runtime.tree.RewriteEmptyStreamException: token required
at org.antlr.runtime.tree.RewriteRuleElementStream._next(RewriteRuleElementStream.java:158)
at org.antlr.runtime.tree.RewriteRuleElementStream.nextTree(RewriteRuleElementStream.java:145)
at TestParser.start(TestParser.java:163)
at TestParser.main(TestParser.java:54)
(note that the TestParser.java line numbers are wrong because I have
removed my test driver from the above Test.g grammar)
but if i change the start rule to be:
start : ( a )* required='b' EOF -> ^(ROOT a* $required) ;
(observe the quotes surrounding b)
everything works kinda sorta as expected: a syntax error message
is displayed (but still with the goofy line 0:-1 location stuff), no
exception thrown, and null AST returned.
If, perhaps, the above is too cryptic; I can try to supply more info...
-jbb
(would the antlr-dev list be better for interim build bug reports?)
More information about the antlr-interest
mailing list