[stringtemplate-interest] Output formatting issue (formatting
constraints and other)
stefan
stefan at amiq.ro
Thu May 26 02:11:17 PDT 2005
A streight forward application of the stringtemplate would be a code
beautifier, as those present in Eclipse, Netbeans etc.
Next lines are some older notices of mine :
_____________________________________________________________
Lets say that we have the classic java method :
.................
public static SomeResultClass getYooopie(String _str, SomeOtherClass _soc) {
____________________
}
.................
and the templates:
.................
method(access_modif,static_modif,result,id b_op,a_op,args, b_cp, a_cp) ::=<<
$access_modif$ $static_modif$ $result$ $id$$b_op$($a_op$$args$$b_cp$)$a_cp$ {
$body$
}
>>
parameter(type, id) ::= "$type$ $id$";
.................
I would like to reprint it in conformance with some basic composition
rules (constraints) like:
- [0] line length ("should be shorter than 80 chars")
- [1] "one parameter/line and one under the other" (split point before
each parameter)
- [2] "put on the line as much as possible" (split point at the end of
the line)
- [3] "put on the line as much as possible but do not split in two the
parameters" (split point is at the and of the line and before parameter) (eg.
can not have "String" on current line and "_str" on the next)
As I see it right now, a constraint would be a combination of [0] and
one of the other rules. For rules [1-3] I have to do two things:
a) specify the split points by marking them in stringtemplate (otherwise
default split points are inserted before each $$ element)
b) apply constraint at write time
Open questions :
- should I insert split points by default in front of each $$?
- should I evaluate chunks length without completely writing them: delay
chunk write till the constraint is resolved? (the complete write is ordered
by enclosing template)
______________________________________________________________________
As soon as I will start working on a code beautifier I'll give more
feedback,
Stefan.
On Thursday 26 May 2005 02:37, Terence Parr wrote:
> On May 25, 2005, at 10:19 AM, jobapply wrote:
> >> It relies on the controller to wrap objects in the appropriate
> >> "renderer" object. I'm adding a mapping concept in the next version
> >> that lets you pass in a collection of renderers, one for each
> >> locale,
> >> so you could generically say format dates in this way. :)
> >
> > I used to think of renderers as of a part of code..
>
> Well they are implemented in code, but used by view
>
> > Could you explain how
> > {$header|truncate:40:"..."}.
> > example will be handled with "renderers"?
>
> The problem is the "40". What if you need to do truncate but not in
> the middle of an HTML tag? I have been thinking about size of
> strings as you have seen on the list. I wonder if a truncate
> operator would be useful in general. I can easily make a renderer
> that truncates, but there is no way to pass it an argument...that is
> specifically disallowed in general as it would be too much like code,
> but perhaps a special operator would satisfy everybody :)
>
> Ter
> --
> CS Professor & Grad Director, University of San Francisco
> Creator, ANTLR Parser Generator, http://www.antlr.org
> Cofounder, http://www.jguru.com
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list