[antlr-interest] case sensitivity for ANTLR v3 lexers

Thomas Brandon tbrandonau at gmail.com
Fri Aug 3 09:26:53 PDT 2007


On 8/4/07, Andy Tripp <antlr at jazillian.com> wrote:
> So there was this thread back in May about supporting case sensitivity
> in antlrV3.
> Is there any support yet?
> If not, has anyone managed to write a CaseInsensitiveLexer?
> And barring that, is it actually just as simple as changing this one
> line in BaseRecognizer from this:
>         if ( input.LA(1)==ttype ) {
> ...to this...
>        if (Character.toUpperCase(input.LA(1)) ==
> Character.toUpperCase(ttype)) {
>
> Andy
>
Looks like match in BaseRecognizer is only used by the parser. You
want match(int), match(String) and matchRange in Lexer where similar
changes should work. Or you could make a custom InputStream that
returned lower case in LA instead and use all lower case in your
literals. As all token text is gotten using substring this won't
affect that.

Tom.


More information about the antlr-interest mailing list