[antlr-interest] Question about lists in tree rewrites

Miguel Ping mblp at mega.ist.utl.pt
Thu Mar 22 16:15:42 PDT 2007

Hi all,

Suppose I got this rule

selectList    : displayedColumn (COMMA displayedColumn )*  ->
^(SELECT_LIST displayedColumn+ );

I know antlr (v3) is smart and sees that 'displayedColumn' repeats at
least once, and manages the list for me in the rewrite rule.
But suppose I am writing a translator, and really need thosesCOMMAS
tokens, how should I do the rewrite rule to include the COMMA's ?
Right now I made a stupid hack:

selectList	: displayedColumn (COMMA otherColumn)*  -> ^(SELECT_LIST
displayedColumn (COMMA otherColumn)* )
	otherColumn	:	displayedColumn; //dummy rule

But as I said, I feel a bit stupid and wonder if is there an easier
way to do this...
Thanks in advance,
Miguel Ping

More information about the antlr-interest mailing list