[antlr-interest] Why don't parsers support character ranges?
Hannes Schmidt
antlr5 at hannesschmidt.net
Wed Apr 23 18:42:31 PDT 2008
Johannes and Troy,
Thanks, guys. I was afraid that this was my only option. My real-world
grammar has dozens of tokens with non-disjunctive sets of characters. I
guess, I'll have to play trained monkey ...
On 4/23/08 3:39 PM, "Daniels, Troy (US SSA)" <troy.daniels at baesystems.com>
wrote:
>
>
>>
>>
>> You could alternatively use:
>>
>> grammar test4;
>> foo : BEFORE '@' AFTER;
>> BEFORE : A_TO_L | M_TO_Z;
>> AFTER : M_TO_Z;
>> fragment A_TO_L: 'a'..'l';
>> fragment M_TO_Z: 'm'..'z';
>>
>
> Actually, you can't. Nothing will ever match AFTER, since BEFORE will
> consume it. If you make BEFORE and AFTER parser rules, that would work.
>
> grammar test6;
> foo : before '@' after;
> before : A_TO_L | M_TO_Z;
> after : M_TO_Z;
>
> A_TO_L: 'a'..'l';
> M_TO_Z: 'm'..'z';
>
>
> Troy
>
>
>> But I suppose it is easier for error messages, if you leave
>> A_TO_L in for AFTER and check it in a later stage for correctness.
>>
>> grammar test5;
>> foo : ALPHA '@' ALPHA;
>> ALPHA: 'a'..'z';
>>
>> Johannes
>>
More information about the antlr-interest
mailing list