[antlr-interest] testing subrules and noviable alt upon eof
David Holroyd
dave at badgers-in-foil.co.uk
Wed Jun 4 09:46:13 PDT 2008
On Wed, Jun 04, 2008 at 11:40:10AM -0400, Brent Yates wrote:
> I believe that this is a problem with the DFA's produced for rules which end
> in conditional alternates. The DFA's fire the exception if a token is seen
> that is not in the expected set for the grammar as a whole. This makes
> calling the rules in isolation a problem. Dr. Parr is aware of the issue.
> The only work around I know of right now is to add "Test" rules for the
> problem cases which end in EOF.
Another option I've used is to append to the test input a token which
appears in the follow set for the rule. After invoking the rule in the
unit test, I assert that the next unconsumed token in the input is the
one which I appended.
e.g. something like,
AS3Parser parser = createParserOn(expr + ")");
parser.forIter();
assertRemainingInputIs(parser.getTokenStream(), AS3Parser.RPAREN, expr);
with,
private static void assertRemainingInputIs(TokenStream input,
int expectedTokenType,
String value)
{
assertEquals("Unexpected tokens in input: "+value,
expectedTokenType, input.LA(1));
}
I prefer this, because while it's still a bit messy, it puts the
mess in the tests rather than in the grammar.
ta,
dave
--
http://david.holroyd.me.uk/
More information about the antlr-interest
mailing list