[antlr-interest] ast rewrite
Terence Parr
parrt at cs.usfca.edu
Tue Dec 5 07:55:20 PST 2006
Folks, if you'll read the Java API docs...what I have is correct.
It's not like i haven't tried what I put up there. ;)
JDK: "The substring begins at the specified beginIndex and extends to
the character at index endIndex - 1"
So, using the length means that the substring will not go up to the
end quote. I *think* what is there is correct; except now somebody
changed it ;) Please change it back. Emond, I will get you an
account...can you remind me via private email? Thanks!
Ter
On Dec 4, 2006, at 11:57 PM, Emond Papegaaij wrote:
> On Monday 04 December 2006 18:48, Terence Parr wrote:
>> On Dec 4, 2006, at 6:43 AM, Alexander Gängel wrote:
>>> Ok I found it in the wiki:
>>>
>>> STRING: '\"' CHARS '\"' {setText(getText().substring(1, getText
>>> ().length()));} ;
>>>
>>> but with this I still have the tailing '
>>>
>>> I thins the wiki is wrong in this point. (I'mnot sure if I just
>>> misssomething)
>>
>> Hi Alexander. I think it's okay, because the Java API for String
>> says "The substring begins at the specified beginIndex and extends to
>> the character at index endIndex - 1."
>>
>>> I now use this:
>>>
>>> String :
>>> '\'' ~('\'')* '\'' {setText(getText().substring(1, getText
>>> ().length()-1));}
>>> ;
>>
>> Does that work? are you not missing the last character before the
>> last quote?
>
> It should be getText().length()-1. The indices are zero based. I
> always use
> short strings to find the right index:
> str = "'a'", length = 3, charAt(length-1) = ''', substring(1,2) =
> "a"
> Also from the Javadoc: 'Thus the length of the substring is
> endIndex-beginIndex.'
>
> Unfortunately, I can't update the wiki, because I don't have a login.
>
> Best regards,
> Emond
>
More information about the antlr-interest
mailing list