How to append a target string that declared in one template in other string templates?

16 views
Skip to first unread message

Meng Tian

unread,
Apr 8, 2013, 6:45:29 AM4/8/13
to antlr-di...@googlegroups.com
Hi, all

The question context is as follows:

grammar (*.g):

start_rule : /*some production*/ -> rootTemplate($targetString={""})

rule1 :  /*some production*/ -> rule1Template()

rule2 :  /*some production*/ -> rule2Template()

templates (*.stg):

rootTemplate(targetString) ::= <<
<targetString>
>>

rule1Template() ::= <<
I want to append targetString here.
>>

rule2Template() ::= <<
I also want to append targetString here.
>>


Any suggestion would be highly appreciated. Thanks.


Regards,
Meng

Meng Tian

unread,
Apr 9, 2013, 5:49:27 AM4/9/13
to
Maybe I can distill my question a bit as follows:

I want to pass some information obtained by some sub rules to their super rules with a group templates. My current attempt to achieve this is to pass an empty parameter to the super template, and use it in the super template after it has been assigned proper value within the sub templates. E.g.,

Super_Rule
    :  Sub_Rule1 -> superTemplate(informationContainer={""})
    |  Sub_Rule2 -> superTemplate(informationContainer={""}) 
    ;

Sub_Rule1
    : blabla1 -> subTemplate1()
    ;

Sub_Rule2
    : blabla2 -> subTemplate2()
    ;

================================

superTemplate(informationContainer) ::= <<
super_blabla
<informationContainer>
>>

subTemplate1() ::= <<
I want some assignment like "informationContainer=string1" here
>>

subTemplate2() ::= <<
I want some assignment like "informationContainer=string2" here
>>

Besides, if the subrule-assigning method turns out to be not supported by string template, is there any suggestion for an alternative approach? Thank you very much.

Regards,
Meng
Reply all
Reply to author
Forward
0 new messages