[antlr-interest] Use of the range operator inside parser rules

Bart Kiers bkiers at gmail.com
Sun Nov 27 02:52:44 PST 2011


Hi all,

I seem to remember that the `..` operator inside parser rules matches
"token ranges". For example:

grammar T;
parse : A..C;
A : 'a';
X : 'x';
C : 'c';
D : 'd';

The `parse` rule would match the tokens A, X or C. (Needless to say, I'd
never use it in this way, but I thought it was possible).

However, when trying to generate a lexer & parser from the
grammar with ANTLR 3.1, ANTLR 3.2 and ANTLR 3.3, I get the following error:
>>> error(100): T.g:4:6: syntax error: antlr: T.g:4:6: unexpected token: A

And using ANTLR 3.4, the following:
>>> error(10):  internal error: T.g : java.util.NoSuchElementException:
can't look backwards more than one token in this stream

My question(s):
- was the `..` inside parser rules ever supported to match "token ranges"?
If so, when was this dropped? (I already searched the 3.x release-notes,
but couldn't find anything)
- or am I mistaken, and was it never supported?

Regards,

Bart.


More information about the antlr-interest mailing list