[antlr-interest] Begins-with/Ends-with ambiguity

Ben Dotte ben.dotte at gmail.com
Fri Jun 20 07:33:01 PDT 2008


Thanks for confirming my suspicions. The lexer rule has held up so far
but I really need to get some unit tests written so these ambiguities
quit sneaking up on me!

On Fri, Jun 20, 2008 at 4:21 AM, Gavin Lambert <antlr at mirality.co.nz> wrote:
> At 03:25 20/06/2008, Ben Dotte wrote:
>>I think I got this solved now by defining a wildcard rule in
>>the lexer like this:
>>
>>TEXT_WITH_WILDCARD
>>       :       (('*' TEXT)|(TEXT '*')) ;
>>
>>Then I just handle the difference between begins-with and ends-with
>>in the AST tree walker. I assume this works because ANTLR is
>>interpreting the entire thing as a single token (if that's the
>>right word), rather than trying to match to a parser rule that
>>ignores spaces.
>
> That's right.  Although you need to be careful when you're using a rule
> (TEXT, in this case) as both a terminal and a non-terminal.  It can
> introduce ambiguity (especially for the suffix case, or if *s are permitted
> elsewhere).
>
> The other way to solve this problem (as you guessed earlier) is to make
> whitespace significant again.
>
>


More information about the antlr-interest mailing list