tags:

views:

191

answers:

3

Let's say that I want to match "beer", but don't care about case sensitivity.

Currently I am defining a token to be ('b'|'B' 'e'|'E' 'e'|'E' 'r'|'R') but I have a lot of such and don't really want to handle 'verilythisisaverylongtokenindeedomyyesitis'.

The antlr wiki seems to suggest that it can't be done (in antlr) ... http://www.antlr.org/wiki/pages/viewpage.action?pageId=1782 but I just wondered if anyone had some clever tricks ...

+3  A: 

How about define a lexer token for each permissible identifier character, then construct the parser token as a series of those?

beer: B E E R;

A : 'A'|'a';
B: 'B'|'b';

etc.

Jonathan Feinberg
+1 for that. @mawg: in case you're wondering if there's a built-in option to do something like this, there isn't: http://www.antlr.org/wiki/pages/viewpage.action?pageId=1782
Bart Kiers
+1  A: 

I'm not familiar with antlr but case insensitive matching is normally done by transforming your strings to a definite case (normally lowercase) then comparing.

Tom Duckering
A: 

In most languages you could always convert your string to be search to lower case, then compare against a lower case search string. Is this possible in antlr? I am not familiar with it.

Jeremy