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

Gavin Lambert antlr at mirality.co.nz
Fri Jun 20 02:21:56 PDT 2008


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