[antlr-interest] check validity of single rule
Philippe Faes
philippe.faes at gmail.com
Mon Dec 31 06:13:51 PST 2007
Thanks Federico and the others,
I think it works fine when I inspect the TokenStream after parsing.
happy 2008
Philippe
On 31 Dec 2007, at 12:56, Federico Di Gregorio wrote:
>
> Il giorno mar, 01/01/2008 alle 00.31 +1300, Gavin Lambert ha scritto:
>> At 23:55 31/12/2007, Philippe Faes wrote:
>>> I am indeed checking rules buried deep in the grammar, and I want to
>>> test individual generation rules.
>>> I have a very large grammar, and it would be painful to create at
>>> foobarTest rule for each existing rule foobar. It's great that antlr
>>> does graceful recovery after errors, but there must be a way to
>>> check if a string confoms to a rule, right?
>>
>> Well, the strings do conform to the rule. The junk afterwards are
>> just presumed to be matched by some (later) rule that you haven't
>> called yet.
>
> I do my tests exactly this way and I explicitly check for EOL using
> the
> lexer to make sure the rule consumed all the input (as it is
> supposed to
> do). Something like:
>
> Assert.AreEqual(YourLexerClass.EOF, lexer.Input.LA(1))
>
> works for me. (Beware of trailing spaces!)
>
> federico
>
> --
> Federico Di Gregorio http://
> people.initd.org/fog
> Debian GNU/Linux Developer
> fog at debian.org
> INIT.D Developer
> fog at initd.org
> La felicità è una tazza di cioccolata calda. Sempre.
> -- Io
More information about the antlr-interest
mailing list