[antlr-interest] rewrite on List from rule - fails to expand List
Peter Nann
peter.nann at vecommerce.com.au
Thu Apr 17 05:18:39 PDT 2008
OK, I am getting a bit confused about what I can and can't do with
rewrite rules...
When I build a List below (in 'orlist') using the token WORD, as show,
it works fine.
However, if I change WORD to 'w' in orlist, then I get no expanded list
in the output.
(Notice that 'w' is synonymous for WORD in my crafted example)
Is there something special I need to do if I am building a List from a
rule instead of a token?
Here is my grammar:
(Sorry for the confusing names, but I am writing a grammar to translate
another grammar format...)
---------------------- CUT HERE
grammar VeGSL2XML;
options {output=template; rewrite=true;}
gslfile : gramdef* ;
gramdef
: GRAMNAME orlist
-> template(gn={$GRAMNAME.text},gf={$orlist.text})
<<\<rule id="<gn>"\> <gf> \</rule\> >>
;
w : WORD ;
orlist
: '[' ( list+=WORD )* ']'
-> template(list={$list})
<<\<one-of\>\<item\><list:{<it.text>};
separator="</item><item>">\</item\>\</one-of\> >>
;
WORD : ('a'..'z'|'-'|'_'|'\'') ('a'..'z'|'-'|'_'|'\'')* ;
GRAMNAME : ('a'..'z'|'-'|'_'|'\'')* ('A'..'Z')
('a'..'z'|'A'..'Z'|'-'|'_'|'\'')* ;
CMT : '/*' (options {greedy=false;} : .)* '*/' {$channel = HIDDEN;} ;
WS : ( ' ' | '\t' | '\r' | '\n' )+ {$channel = HIDDEN;} ;
---------------------- CUT HERE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080417/767dfc58/attachment.html
More information about the antlr-interest
mailing list