[antlr-interest] Invalid rule text
Dr. Michael Gerz
michael.gerz at teststep.org
Mon Jun 9 14:50:26 PDT 2008
Hi guys,
this is a cry for help!
In my tree grammar, there is a rule that looks like this:
expressionList
@after { System.out.println($expressionList.text); }
:
{ System.out.println("Start"); }
( expression { System.out.println($expression.text); } )+
{ System.out.println("End: "); }
;
When this rule is entered, it outputs one or more <expression>'s.
However, at the end (@after), it only outputs the first element of the
expressionList.
How is that possible? Shouldn't "$expressionList.text" comprise all
individual expressions at the end of the rule? Shouldn't I get the
complete expressionList, when I refer to the rule as follows?
componentCreation
: ^(Create Identifier
( expressionList
-> template
(id={$Identifier.text},el={$expressionList.text})
"((<id>) cm.registerComponent(\"<id>\", new
<id>(<el>), true))"
| /* empty */
-> template (id={$Identifier.text})
"((<id>) cm.registerComponent(\"<id>\", new
<id>(), true))"
)
)
;
In "componentCreation", the code generation for the first template
fails, because only the first element of expressionList is in <el>.
Instead, it should be a string like "a, b, c"
BTW: Grammar options are { k = 1; ASTLabelType = CommonTree;
output = template; rewrite = true; }
Any suggestions? To me this looks like a serious bug in ANTLR...
Thanks in advance!
Michael
More information about the antlr-interest
mailing list