[antlr-interest] BUG - Antlr does not ignore whitespace in calls to parameterized rules (Java output)
Austin Hastings
Austin_Hastings at Yahoo.com
Fri Oct 12 07:37:58 PDT 2007
This grammar has a parameterized rule, "param[]":
grammar bug;
file: ID param[ $ID.text ] ;
param[String s] : WS ;
ID: 'a';
WS: ' ';
Because of the spaces inside the [ $ID.text ] in the "file" rule, the
output java looks like this:
try {
// bug.g:3:5: ( ID param[ $ID.text ] )
// bug.g:4:2: ID param[ $ID.text ]
{
ID1=(Token)input.LT(1);
match(input,ID,FOLLOW_ID_in_file10);
pushFollow(FOLLOW_param_in_file12);
param( , ID1.getText(), );
_fsp--;
Note the invalid commas in the call to param( , ID1.getText(), )
If I change the "file" rule to eliminate the spaces: file: ID
param[$ID.text] ;
I get this generated java:
try {
// bug.g:3:5: ( ID param[$ID.text] )
// bug.g:4:2: ID param[$ID.text]
{
ID1=(Token)input.LT(1);
match(input,ID,FOLLOW_ID_in_file10);
pushFollow(FOLLOW_param_in_file12);
param(ID1.getText());
_fsp--;
And the call to param is syntactically valid. I don't know enough about
the innards to know if this is a template problem or a core problem.
=Austin
More information about the antlr-interest
mailing list