[antlr-interest] help requested for selective whitespace

Martin Probst mail at martin-probst.com
Thu Feb 2 03:42:25 PST 2006


Hi,

maybe I should write a bit more about my other email. As far as I
understand it, your problem is that you want single identifiers like "a"
or "b", always length == 1, to be separated by whitespace. This doesn't
work if you have a rule that consumes exactly one character, as you
cannot be sure if whitespace we're between the identifiers. So my idea
is to just parse longer identifiers like this:
IDENT: ('a' .. 'b')+;
and then check in that Lexer rules if the token was actually longer than
one character, in which case you throw an exception with the error
message:
IDENT: ('a' .. 'b')+ { if ($getText().length() > 1) throw ... };
Does that work for you?

Martin



More information about the antlr-interest mailing list