Ulf Wiger (AL/EAB)
Mon Jun 27 17:25:53 CEST 2005
I wrote my own layout engine, but cheated - and let the
token scanner return column numbers rather than just line
numbers. The "layout engine" then laid things out exactly
In order to preserve comments, I made the token scanner
save comments as well. The tricky part was knowing how
to pass them along without messing up the parser.
I finally settled on the perhaps inelegant strategy of
making every other element in the list of tokens a
"comment or whitespace" list.
"%%% The contents of this file are subject to the Erlang Public License,"},
"%%% Contributor(s): ______________________________________."},
One could of course use "annotated tokens" instead. Don't know
what would be the most b/w incompatible change. Perhaps adding
column numbers to the scanner would involve reasonable effort.
> -----Original Message-----
> [mailto:]On Behalf Of
> Richard Carlsson
> Sent: den 27 juni 2005 12:45
> To: Mats Cronqvist (AL/EAB);
> Subject: Re: erl_prettypr
> Mats Cronqvist wrote:
> > i'm trying to make a erl-html filter using syntax-tools
> (works so-so),
> > but i've found this annoying behaviour. if i have this in a
> file (named
> > tst.erl);
> > foo(Bla,X)->%hello
> > Bla.
> > running this beauty;
> > will give this;
> > "foo(Bla,\n X) ->%hello\n Bla.
> > there shouldn't be a line break between Bla and X. and
> indeed, if the
> > comment is removed there isn't.
> > anybody got any advice?
> It's been a while since I wrote that stuff, so I had to try
> it out to see why
> this happens. Although it might certainly be irritating, it's
> not without logic
> (and I don't know if it can be fixed). The comment is
> attached to the nearest
> construct in the parse tree, in this case the variable 'X'
> (and not the
> function clause). Then, the formatting will not like that an
> element in a
> parameter list has an attached comment (because comments must
> end with a line
> break), and will lay out the sequence vertically. (After
> that, the comment will
> be moved outside the ")->" part, but that is by another mechanism.)
> Consider this slight modification, and you might see that
> your example is
> just a special case:
> X, %hello
> Of course, that doesn't make it less irritating, but now you
> know what is
> causing it. Feel free to try to solve the problem. And
> welcome to the wonderful
> world of layout engines.
More information about the erlang-questions