[antlr-interest] Keywords as identifiers in ANTLR 3.0
Gavin Lambert
antlr at mirality.co.nz
Wed Aug 29 05:37:17 PDT 2007
At 00:20 30/08/2007, Ayende Rahien wrote:
>Thanks for the help. I do have the need to handle select (and
>other SQL elements).
>How can I handle that?
I answered that one in the last paragraph :) The way I prefer is
to do something like this:
1. Create a new parser rule 'identifier' that accepts IDENTIFIER
as well as any of the (non-fragment) keyword tokens that can also
potentially be identifiers when used out-of-context.
2. Change any existing parser rules to use 'identifier' instead of
'IDENTIFIER'.
Incidentally, a different approach you might want to take for the
original "order by" issue is to convert ORDER_BY into a parser
rule and make both ORDER and BY non-fragment rules. That way you
don't need to worry about the whitespace any more (it will have
already been removed by that stage), and (combined with the above)
makes it a bit easier to treat every keyword as an identifier when
used out of place.
Are you really sure you need to do this, though? I didn't think
regular SQL permitted this sort of thing, since it leads to evil
typo behaviour.
More information about the antlr-interest
mailing list