[antlr-interest] [ST] How subtemplates work?
Terence Parr
parrt at cs.usfca.edu
Tue Mar 11 10:36:14 PDT 2008
On Mar 11, 2008, at 9:57 AM, Cristian Peraferrer wrote:
> Hi!
>
> I have looked for subtemplates working examples or how subtemplates
> work in the ST wiki but I haven't managed to find out.
>
> My question is, with this StringTemplate GroupFile:
>
>
> pnml(xmlns) ::= <<
> <pnml xmlns="$xmlns$">
> $net$
> </pnml>
> >>
hi. must pass net in as attribute if you ref it.
pnml(xmlns, net) ::= ...
> net(id, type) ::= <<
> <net id="$id$" type="$type$">
> foobar
> </net>
> >>
>
>
> How should I implement my .g file to make the pnml template make use
> of net template?
> For example:
>
>
> grammar Test1;
>
> options {output = template;}
>
> s : INT '&' ID '&' net ';' -> pnml(xmlns={$INT.text}) ;
then -> pnml(xmlns={$INT.text}, net={$net.st}) ;
and you're golden.
Ter
>
> net : ID -> net(id={$ID.text},type={$ID.text}) ;
> ID : 'a'..'z'+ ;
> INT : '0'..'9'+ ('.' '0'..'9'+)+ ;
> WS : (' '|'\t'|'\n'|'\r') {skip();} ;
>
> Which is not correct...
>
> Thanks in advance,
> Cris.
>
> --
> GPG Key-ID: 0x564903FA - Jabber ID: corellian at swissjabber.ch
>
More information about the antlr-interest
mailing list