[stringtemplate-interest] Wrapping long arithmetic expressions

Mike Graham mikegraham_uk at yahoo.co.uk
Thu Apr 9 16:04:37 PDT 2009


I've hunted though the archives and document pages, but haven't worked out how to do the following.

I'm writing a utility to document and translate often very long conditional and arithmetic expressions. I'm parsing them with Antlr and rewriting them using StringTemplate in a Antlr tree walker. The results need to be readable and valid C# code. I have a top level template in a group that looks like this:

result(e) ::= <<
TheResult = $expr$;
>>

However, since $expr$ can get very long (may hundreds of characters). I'd really like to be able to do something like this:

result(e) ::= <<
TheResult = <$expr$; anchor, wrap> ;
>>

so that I can wrap the expression at whitespace neatly aligned to the =. But the wrap works only for lists with separators and I end up with an arithmetic expression with infix operators.

I guess the correct solution is to write a new StringTemplateWriter, but I'm not sure if the anchor/wrap would be recognised in this context by StringTemplate. Could anyone say of this is a viable solution? Is there an easier way of doing this that I've overlooked? Grateful for any suggestions.

Best regards,

-- Mike.





      


More information about the stringtemplate-interest mailing list