[stringtemplate-interest] Wrapping long arithmetic expressions
Terence Parr
parrt at cs.usfca.edu
Tue Apr 21 12:48:06 PDT 2009
Hi Mike,
Hmm....yeah, ST tries not to split individual elements. That said, it
should handle
properly so that they get auto indented. So your expr values are just
long strings? If they are developed from string templates, you can
leave them as templates rather than rendering them to string and
passing them in as an attribute. would that help? Knowing where to
split something might be difficult even in your own writer unless you
parse the output.
Ter
On Apr 9, 2009, at 4:04 PM, Mike Graham wrote:
>
> 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.
>
>
>
>
>
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list