[antlr-interest] ANTLR 3.0b4 bug?

Ayal Spitz aspitz at gmail.com
Tue Oct 31 07:51:56 PST 2006


Greetings -

I just started using ANTLR and I'm already a very big fan. I've been
experimenting with building a grammar and have come across a problem
I'm hopping someone out there might have a solution for.

I'm implementing a 'generic delimited input' from Ruby and have been
having 1 heck of a time. I finally came across the XRuby project and
their Ruby grammar work (Good stuff XRuby folks). I copied the segment
of their grammar that deals with generic delimited input. I changed it
to be ANTLR 3 compatible so it looks something like this:

QTest:
{ int dCount = 1; }
  '%q'	delimiter=.
    ({(dCount = trackDelimCount(input.LA(1), delimiter, dCount)) !=
0}? STRING_CHAR)*
    .{ channel = QTest; };

ANTLR seems to like it and goes ahead to generates the code. The
problem I've run into is in the lexer code for this entry. ANTLR
generates a method called mQTest and it has this code:

if ( !((dCount = trackDelimCount(input.LA(1), delimiter, dCount )) != 0) ) {
  throw new FailedPredicateException(input, "QTest", "(delimiterCount
=  trackDelimCount(input.LA(1), delimiter, dCount )) != 0");
}

If I leave the code as is then the results is a lexer that spits up
over my generic delimited input but if I replace the throw with a
'break loop' my problems appear to be solved.

My question is (1) Is this a bug in ANTLR 3.0b4, ie this is what you
get for playing with the bleeding edge? (2) Am I just getting lucky
that the 'break loop' code works? (3) is there a way for me to, in my
grammar, tell ANTLR to replace that throw statement with a 'break
loop'?

Thanks for any help in advance - AYAL


More information about the antlr-interest mailing list