[antlr-interest] Parsing with inverse matches

Vipul Delwadia vipul.delwadia at gmail.com
Sun Nov 22 14:20:59 PST 2009


Hi,

Suppose I have a very simple grammar:

line:	x;

x	:	STRING+;

fragment BACKSLASH
	:	'\\';

NOTA:	BACKSLASH A;

A	:	'a';

STRING
	:	(~(A)|NOTA)+;

Now I want x to be able to match any sequence which doesn't have "a"
in it, including sequences which have "\a". This works for the most
part except when I try and match just "\a", at which point I get a
MismatchTokenException (or sometimes a NoViableAltException). However,
in the ANTLRWorks IDE if I parse it using the interpreter starting
from the STRING rule, it seems to match it just fine.

Any ideas?

Cheers,
Vipul


More information about the antlr-interest mailing list