[antlr-interest] accessing lexer sub tokens from a rule
hakan eryargi
hakan.eryargi at gmail.com
Sun Jul 19 18:04:06 PDT 2009
hello,
is it possible to access sub tokens of lexer from a rule ? (sorry for
stupid naming) at the bottom is part of my grammar. i want to re-write
primary rule something like:
primary :
a=ABILITY -> ABILITY<ReqNode.A>[$a.scope, $a.id, ($a.INTEGER | $a.FLOAT)? ]
| LPAREN! expression RPAREN!
;
of course i can parse ability in ReqNode.A constructor for my needs
but ability is already parsed by lexer so using it seems wiser. but
how ?
i tried to make ability a rule but generated code couldnt parse my
input complaining about no viable alternative. i'm not sure why, and
also i'm not sure if making ability a rule makes sense. ie: it sounds
like a lexical rule rather than parsing rule
thanks,
hakan
primary :
ABILITY -> ABILITY <ReqNode.A>
| LPAREN! expression RPAREN!
;
ABILITY :
SCOPE WS? COLON WS? ID WS? (COLON WS? (INTEGER | FLOAT))?;
ID :
('a'..'z' | 'A'..'A') ('a'..'z' | 'A'..'A' | DIGIT | '_' )*
;
fragment SCOPE
: /* only query scopes*/
'b' /* building */
| 'l' /* cell */
| 't' /* slot */
| 'c' /* city */
| 'u' /* user */
| 'a' /* any */
;
More information about the antlr-interest
mailing list