[antlr-interest] Re: pretty printing with stringtemplate
Arnulf Heller
aheller at gmx.at
Wed Jan 4 06:27:55 PST 2006
>
>yes, and you'd write it like this in v3:
>
>options {output=template;}
>
>ifrule : "if" LPAREN boolexpr RPAREN LCURLY s=stmts RCURLY
> -> ifrule(boolexpr={$boolexpr.st}, stmts={$s.slist})
> ;
>
>where stmts must return a list of templates:
>
>stmts returns [List slist]
> : (s+=stat)+ {$slist = $s;}
> ;
>
>stat : ifstat -> {$ifstat.st}
> | ID '=' expr ';' -> assign(lhs={$ID.text}, rhs={$expr.st})
> ;
>
>or something like that. I don't like some of that (too inconvenient)
>but it's ok for now until we learn more about usage patterns.
>
>Terence
Ok. Now I begin to understand how ANTLR3 and ST are supposed to play
together nicely. Very cool.
When I started to play with string template, I [thought that I] was
forced to program java, initialized string templates in user actions,
passed them around between rules ... ugly.
This will make the task to generate valid C++ code out of simple
textual descriptions quite easy.
I vaguely can remember that you alluded to this topic a while ago,
but: Can you give me a hint how to handle the situation that I need
to generate two string templates at the same time, one for the header
and one for the implementation?
Thx,
Arnulf
More information about the antlr-interest
mailing list