[stringtemplate-interest] Newbie Help

Richard Wilburn rhwilburn at gmail.com
Sat Aug 11 17:49:45 PDT 2007


Hi I am new to StringTemplate :)

I am trying to use StringTemplate to generate source code. I realise that in
order to use string template I need to think in a way similar to functional
programming however its been along time since I have done any so I
struggling a bit. I am trying to generate c# code. In particular a case
statement.

Here is the code that is in template.st


switch(eventlist)
{
    $events:{event|
        case $event$:
        $rulelist:{rule|
            $if(event == rule))$
                //if sender is in eca1's xpath query.
                      //if precondition is satisfied
                           //do action1();
                //elseif sender is in eca2's xpath query (eca2 also listens
for event1)
                     //if precondition
                          //do action2();

            $endif$
        }$
        break;

    }$

    default:
     //add event to event stack and ignore it.
     break;
   }



It appears from the documentation that I cannot do an equivilence operator?
Am I thinking on the correct track with the imperitive style if statement or
is there someother way I must do it.

Essentially as the output I would expect something like (assuming 2 ECA
rules apply to event1 and 1 applies to event2):

switch(eventlist)

{

     case event1:
                //if sender is in eca1's xpath query.
                      //if precondition is satisfied
                           //do action1();
                //elseif sender is in eca2's xpath query (eca2 also listens
for event1)
                     //if precondition
                          //do action2();

                //if sender is in eca1's xpath query.
                      //if precondition is satisfied
                           //do action1();
                //elseif sender is in eca2's xpath query (eca2 also listens
for event1)
                     //if precondition
                          //do action2();
     break;

     case event2:
                 //if sender is in eca1's xpath query.
                      //if precondition is satisfied
                           //do action1();
                //elseif sender is in eca2's xpath query (eca2 also listens
for event1)
                     //if precondition
                          //do action2();
     break;

....

What the output is trying to do is to take an event that occurs (we don't
know what it is until runtime) and try to work out (think c++ style event
loop/message pump)  what it is with the case statement. Then I have a list
of ECA rules (event condition action rules that I want to put in based on
what their event. So event1 could be mouseclicked and event2 could be
keypress. ECA rules 1,2,3,10 could apply to event1 and ECA rule 4 could
apply to event 2. So what i need to do is a comparison to get the ECA rules
in the correct case statement. If I haven't explained anything enough let me
know. Ultimately I am after some sort of string value comparison operator.

Thanks

Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20070812/6fe256e1/attachment.html 


More information about the stringtemplate-interest mailing list