[stringtemplate-interest] Trying to output StringTemplate with values
Louis Burroughs
louis.burroughs at gmail.com
Mon Aug 29 07:48:16 PDT 2011
Hey,
I am using Antlr to parse ESQL code, pull out unique values and store it in
an intermediate form (StringTemplate) for reuse. I am having a tough time
getting StringTemplate to output the compiled template with all of it's
values. I can get Antlr to parse the code and create the template, I just
can't get it to output a String or File in the format I am looking for. I
get the feeling I am either over-complicating this or missing something.
Here is the esql code I am starting with:
CREATE PROCEDURE CopyMessageHeaders() BEGIN
DECLARE I INTEGER 1;
DECLARE J INTEGER;
SET J = CARDINALITY(InputRoot.*[]);
WHILE I < J DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END;
Here is a template I would like to see (I created this manually):
CopyMessageHeadersProc()::= <<
<Procedure("CREATE","CopyMessageHeaders","",{
<["I","J"],["INTEGER","INTEGER"],["1","CARDINALITY(InputRoot.*[])"]:{var,type,val|<Declare(var,"",type,val)>}>
<While("I","<","J",false,{
<["OutputRoot.*[I]","I"],["InputRoot.*[I]","I +
1"],[false,false]:{a,b,c|<Set(a,b,c)>}>})>})>
>>
Constructed from these base templates:
Procedure(ACTION,NAME,ARGS,BODY)::="<ACTION> PROCEDURE
<NAME>(<ARGS>)<\n><BodyStruct(BODY)>"
BodyStruct(BODY)::="BEGIN<\n><\ ><BODY><\n>END;"
Declare(VAR_LIST, MODIFIERS, TYPE, VALUE)::="DECLARE
<VAR_LIST:{v|<v><last(v)>}> <MODIFIERS:{m|<m><last(m)>}> <TYPE>
<if(VALUE)><VALUE><endif>;<\n>"
While(VAR,TEST,VALUE,quote,WHILE_BODY)::="WHILE (<VAR> <TEST>
<QuoteString(quote,VALUE)>) DO <WHILE_BODY>END WHILE;"
Set(VARIABLE,VALUE,quote)::= "SET <VARIABLE> =
<QuoteString(quote,VALUE)>;<\n>"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110829/834417a7/attachment.html
More information about the stringtemplate-interest
mailing list