[antlr-interest] ArrayIndexOutOfBoundsException
Gavin Lambert
antlr at mirality.co.nz
Fri Feb 1 23:17:39 PST 2008
At 16:48 2/02/2008, Steve Bennett wrote:
>
>I've managed to narrow it down a bit to this rule:
>
>literal_right_bracket
> { !prohibit_literal_right_bracket &&
>(prohibit_literal_link_end <= 0 || input.LA(2)!= RIGHT_BRACKET)
}?
> RIGHT_BRACKET;
>
>As written, the exception occurs in a string like [[foo]] (where
>this rule should not apply due to the semantic predicate). I've
>had this rule for a while and it normally works, so I don't
>know what else I have changed.
Predicates can be hoisted outside the rule they're defined in, to
help in deciding whether that rule should be entered in the first
place or not. I thought that only applied to gated predicates,
but there might be a special case for a leading ungated predicate
(since that's how you had to do it in ANTLR 2).
So my best guess at this point is that it's the call to
input.LA(2), which is occurring when there isn't two characters of
lookahead available (eg. next character is EOF). If that really
is the problem, then failing the predicate early when input.LA(1)
== EOF will probably sort it out.
More information about the antlr-interest
mailing list