[antlr-interest] a range as single token?

fikin nikolai.fiikov at gmail.com
Sat Jan 15 03:09:47 PST 2011


>> what exactly is wrong with this grammar?
>>
>> lines   :       line (NEWLINE line)*;
>> line    :       '\u0020'..'\u007F'*;
>> NEWLINE :       '\r'? '\n';
>
> The range operator works differently inside a parser-rule.
> For example, the rule foo:
>
> foo
>   :  A..C
>   ;
> A : 'a';
> Z : 'z';
> C : 'c';
>
> will match one of the tokens A, Z or C (not one of the characters 'a', 'b'
> or 'c'!).

i also noticed that following works just fine:
lines   :       line (NEWLINE line)*;
line    :       CHAR*;
NEWLINE :       '\r'? '\n';
CHAR    :       '\u0020'..'\u007F';

is there a way i can make a rule token is a sequence of values as
opposing a sequence of tokens?


More information about the antlr-interest mailing list