[antlr-interest] Bug? Invalid Java code generated
Sam Barnett-Cormack
s.barnett-cormack at lancaster.ac.uk
Fri Mar 6 02:24:42 PST 2009
Hi all
The attached grammar (which you're probably all tired of) generates Java
code with an error in. I've checked, and the error isn't in a copy
action or predicate - it's in the expansion of $text in a parser
predicate. I don't know if I've used $text incorrectly, because I'm
using it as I understand the documentation says to (including the ANTLR
book).
The error is:
retval cannot be resolved
on: ASN_1Parser.java
line: line 17279
The generated function in question is:
// $ANTLR start synpred26_ASN_1
public final void synpred26_ASN_1_fragment() throws
RecognitionException {
// /home/sdb/workspace/asn.1-parse/grammars/ASN_1.g:583:44: (
nameForm {...}?)
// /home/sdb/workspace/asn.1-parse/grammars/ASN_1.g:583:44:
nameForm {...}?
{
pushFollow(FOLLOW_nameForm_in_synpred26_ASN_13890);
nameForm();
state._fsp--;
if (state.failed) return ;
if (
!((isStandardOIDName(input.toString(retval.start,input.LT(-1))))) ) {
if (state.backtracking>0) {state.failed=true; return ;}
throw new FailedPredicateException(input,
"synpred26_ASN_1", "isStandardOIDName($text)");
}
}
}
// $ANTLR end synpred26_ASN_1
The rule from the grammar (whole thing attached) is:
objIdComponents options{backtrack=true;} : nameForm
{isStandardOIDName($text)}? | numberForm | nameAndNumberForm |
definedValue ;
If this isn't a bug, can someone explain how to pass a function called
in a predicate the text matched so far? If this is a bug, anyone have a
workaround? Please. Thanks!
Sam
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ASN_1.g
Url: http://www.antlr.org/pipermail/antlr-interest/attachments/20090306/f9ffbb1d/attachment.pl
More information about the antlr-interest
mailing list