[antlr-interest] Inexplicable RewriteEmptyStreamException in parser grammar
Richard Thrippleton
rthrippl at progress.com
Tue May 25 13:01:36 PDT 2010
I'm using the Java target with ANTLR 3.2, and having a problem in a rule in my parser grammar that looks like this:
"variableInit [ String name ]
: ASSIGNMENT id=initializer
-> ^(ASSIGNMENT IDENTIFIER[$ASSIGNMENT, $name] initializer)"
In a particular case where the 'initializer' rule fails to match and issues a syntax error, I'm getting a RewriteEmptyStreamException that cites "rule initializer" popping up from a line that looks like this:
"// 1151:5: -> ^( ASSIGNMENT IDENTIFIER[$ASSIGNMENT, $name] initializer )
{
{
CommonTree root_1 = (CommonTree)adaptor.nil();
root_1 = (CommonTree)adaptor.becomeRoot(stream_ASSIGNMENT.nextNode(), root_1);
adaptor.addChild(root_1, (CommonTree)adaptor.create(IDENTIFIER, ASSIGNMENT179, name));
adaptor.addChild(root_1, stream_initializer.nextTree()); <-------------------- ****This line****
adaptor.addChild(root_0, root_1);
}
}"
In terms of error handling we're just using the default recovery (not overriding it with 'catch'/'rulecatch'). We've overridden reportError to pretty-print the RecognitionExceptions, but that's about it. Should I be needing to do anything special to cope with parsing failures of subrules, or should the default be sufficient to prevent these exceptions? Otherwise, where is the problem likely to lie - a defect elsewhere in my grammar, or in ANTLR?
Cheers,
Richard
More information about the antlr-interest
mailing list