[antlr-interest] wildcard string in grammar

Tim Williams williamstw at gmail.com
Wed Jul 22 08:06:48 PDT 2009


I need to support wild cards of the form:

a) a*pp?e
b) *pple
c) a?p*
d) appl?

I've worked it out to be:

WILD_STRING: (('a'..'z'|'A'..'Z')* ('*'|'?') ('a'..'z'|'A'..'Z')*)+

This generates the warning "Decision can match input
('a'..'z'|'A'..'Z') using multiple alternatives 1,2 disabling
alternative(s) 2."  When compiled, it seems to "work" even with the
warning.  I *think* I understand that the ambiguity arises from the
fact that after ('*'|'?') has matched, either one of the char patterns
might be selected.  With all my test input it appears to work fine.
I'm wondering if there's an unambiguous way to encode such a pattern
though?

Thanks,
--tim


More information about the antlr-interest mailing list