[antlr-interest] Token position 0, -1
Ale Strooisma
alestrooisma at gmx.net
Mon Jul 9 05:41:54 PDT 2012
Hi Mike,
Rules don't have a location, but you can make a rule return a value, so
if you let your rule return a token, you can do it like this:
target_table
: rv=qualified_identifier -> ^(TABLE_REF_ID[rv] qualified_identifier)
;
And then qualified identifier should look something like this:
qualified_identifier returns [CommonToken rv = null;]
: ... t=SOME_TERMINAL ... {rv=$t;}
;
In my code I made all my rules return their root-token in this way.
If you still have any questions about how or why it works, just ask.
Good luck,
Ale
On 07/09/2012 02:29 PM, Mike Lischke wrote:
> Stefan,
>
>
>> compoundStatement
>> : lc='{' statement* '}'
>> -> ^(SLIST[$lc] statement*)
>> ;
>>
> Is there a similar construct if you have a rule instead of a token? For instance:
>
> target_table:
> qualified_identifier -> ^(TABLE_REF_ID qualified_identifier)
> ;
>
> Here I would like to give the synthetic TABLE_REF_ID token the location info from the qualified_identifier rule.
>
> Mike
>
More information about the antlr-interest
mailing list