[antlr-interest] How to implement case insensitive keyword in antlr3
Gavin Lambert
antlr at mirality.co.nz
Fri Aug 17 01:35:16 PDT 2007
At 12:00 17/08/2007, Hub Dog wrote:
> I am just porting an antlr v2 project to antlr3.The
> keyword of language is case insensitive.In the antlr v2, there
> is a caseSensitiveLiterals option for lexer.
>But it seems there is not such an option in v3. Does someone know
>how to implement case insensitive keyword in antlr3 .
The two main approaches I've heard mentioned for this are:
1. override the standard lexer matching and lookahead routines and
get them to do case-insensitive matching
2. write your rules in this sort of format:
PRINT: ('P'|'p')('R'|'r')('I'|'i')('N'|'n')('T'|'t');
(This last one is a bit of a hassle but even if you've got lots of
tokens it's pretty easy to knock up a one-shot codegen program
that takes a list of keywords and outputs something like the
above.)
Not that I've ever actually done either of these, since for the
most part I'm only parsing languages I've invented myself, so I
chose to make them case-sensitive :)
More information about the antlr-interest
mailing list