[antlr-interest] check validity of single rule

Gavin Lambert antlr at mirality.co.nz
Mon Dec 31 03:31:06 PST 2007


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.

Have another look at what David suggested.  The parser rule will 
only consume the input that matches, so any unconsumed input in 
the stream means that the rule didn't match the complete string -- 
and that sounds like what you're trying to detect.

I don't recall offhand what regular parser rules return, but 
certainly output=AST parser rules return the AST, which includes 
the stop token, which includes a token stream position.  That's 
another way you could check it, though probably more convoluted 
than David's suggestion.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080101/f624f19d/attachment.html 


More information about the antlr-interest mailing list