erl_prettypr

Richard Carlsson richardc@REDACTED
Mon Jun 27 12:45:10 CEST 2005


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;
> 
> F="tst.erl",erl_prettypr:format(erl_recomment:recomment_forms(element(2,epp_dodger:parse_file(F)),erl_comment_scan:file(F))).
> 
> 
>   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:

  foo(Bla,
      X, %hello
      Bleh)->
      Bla.

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.

	/Richard



More information about the erlang-questions mailing list