[antlr-interest] $TOKEN.pos absolute location
Basil Shkara
bshkara at gmail.com
Thu Dec 20 12:08:00 PST 2007
Thanks Jim,
You're right. $rule.start will return the absolute location.
However in ObjC, you receive an ANTLRToken object so to get at the
value, send the message: tokenIndex to return an unsigned int which
you can then use.
So something like this: [$rule.start tokenIndex] will work.
However I have noticed that sending tokenIndex on the ANTLRToken
returned from $rule.stop in the ObjC target will always return the
value 0 which seems like a bug in the templates.
This is in the latest ObjC.stg from fisheye.
Regards,
Basil.
On 20/12/2007, at 3:40 AM, Jim Idle wrote:
> In the other targets this is just the .start element. I would think it
> is the same for objc.
>
> Jim
>
>> -----Original Message-----
>> From: Basil Shkara [mailto:bshkara at gmail.com]
>> Sent: Wednesday, December 19, 2007 3:34 AM
>> To: antlr-interest at antlr.org
>> Subject: [antlr-interest] $TOKEN.pos absolute location
>>
>> Hi,
>>
>> Using $TOKEN.pos gives you the position relative to $TOKEN's line.
>> Is
>> there an easy way of receiving the position relative to all
>> characters
>> occurring beforehand?
>>
>> So rather than receiving pos=43, line=2 - is it possible to receive
>> pos=80, assuming that there are 79 characters before $TOKEN?
>>
>> I am currently using the ObjC target and am using a lot of messy
>> instance variables to count every token as
More information about the antlr-interest
mailing list