[antlr-interest] Parsing Identifiers
Pankaj Rao
pmrao7 at gmail.com
Tue Jun 13 15:38:43 PDT 2006
Hi All,
I have encoutered this special case while writing my parser and I am trying
to figure out the cleanest way to handle this.
What I am trying to do is be able to parse identifiers having characters
beyond alphabets and numbers , for example "?name" or "%name"
My lexer rule for parsing identifiers is as follows:
IDENT
: ('a'..'z' | 'A'..'Z' | '_' | '$' ) ( ('a'..'z' | 'A'..'Z' | '_' | '$' )
| ('0'..'9' ))*
;
So I thought about modyfing my Identifier rule to look for '?'.
IDENT
: ('a'..'z' | 'A'..'Z' | '_' | '$'|'?' ) ( ('a'..'z' | 'A'..'Z' | '_' |
'$' | '?') | ('0'..'9' ))*
;
Parsing "$name" or "_name" seems to work ok with the rule I have. But this
approach doesnt seem to work and after modifying the identifier rule , I
still get an error while trying to parse identifiers of the nature "?name"
etc.
Is there a better way to handle this case or any suggestions on what I might
be doing incorrect.
Thanks a lot.
-Pankaj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060613/fdb6ba49/attachment.html
More information about the antlr-interest
mailing list