[antlr-interest] gUnit StringIndexOutOfBoundsException, getText() called where state.tokenStartCharIndex is -1

Jasper Floor jasperfloor at gmail.com
Wed Aug 11 08:59:06 PDT 2010


I have a DSL which is already in production but I am working on an
updated version.

We already have quite a few tests which call the parser but I never
added gUnit tests until this version.

Actually everything was working fine until my latest change where I
started messing with the token stream. I don't think I am doing
anything complicated. Also our other tests work fine so I think the
problem is in gUnit.

Basically I have a rule where I want to remove some elements from the
input string. This is done with setText(unescape(getText())).

The problem occurs in getText(). The state.tokenStartCharIndex is -1
and this is passed to substring which is called in getText(). This
leads to a StringIndexOutOfBoundsException.

I've included the grammar. There is also a Tree Grammar after this but
that isn't relevant. There are probably more problems with the grammar
but at this point I'm only interested in the gUnit errors.
I've changed some names to remove any company specific information but
the grammar itself is unchanged.

mvg,
Jasper


p.s. is it bad etiquette to post the whole grammar and tree grammar to
ask for comments?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: X.g
Type: application/octet-stream
Size: 2087 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20100811/f19de4d8/attachment.obj 


More information about the antlr-interest mailing list