[antlr-interest] [ST] How subtemplates work?

Cristian Peraferrer corellian.c at gmail.com
Tue Mar 11 11:59:58 PDT 2008


On 11/03/2008, at 18:36, Terence Parr wrote:

>
> 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

Thanks!

How it would be written if we have various 'net' like that:

s	:	INT '&' ID '&' net+ ';'

>>
>> 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
>>
>

-- 
GPG Key-ID: 0x564903FA - Jabber ID: corellian at swissjabber.ch



More information about the antlr-interest mailing list