[antlr-interest] Unit testing grammar productions and injecting EOF

Kaleb Pederson kaleb.pederson at gmail.com
Tue Oct 6 13:33:09 PDT 2009


On Tue, Oct 6, 2009 at 7:13 AM, Daniels, Troy (US SSA)
<troy.daniels at baesystems.com> wrote:
>
>> As a workaround, I changed my production, adding EOF as an
>> optional terminal as follows:
>>
>> objectMember : functionExpression EOF? | ID EOF?;
>>
>> Everything now works but I'm curious if a better solution for
>> testing individual grammar productions exists.  Suggestions
>> or alternatives?
>>
>
> While it's not the best answer, you could change your test code so that
> instead of passing "foo", it passed "foo junk".  That way, your fix is
> in the test code, and the production grammar says what you want it to
> say.  Better would be for Antlr to include EOF in the follow set if it's
> possible.

Thanks for the suggestion Troy.  You're right, that's certainly a
valid workaround.  I could look through the generated follow set and
choose one of the permitted tokens, but that would clutter the tests
and leave them less readable.  Of course, if I don't clutter the tests
with the extra symbol, I have to clutter the grammar with the extra
EOF, but I'm preferential to that at the moment as it currently only
occurs in that one production, but I'll keep your suggestion in mind.

Thanks.

--Kaleb

http://twitter.com/kalebpederson
http://kalebpederson.com


More information about the antlr-interest mailing list