[erlang-questions] erl_syntax:comment with erl_prettypr error

Richard Carlsson carlsson.richard@REDACTED
Fri Dec 23 20:48:45 CET 2011


On 12/23/2011 07:34 PM, Adrian Campos wrote:
> Hello,
>
> I have been trying to create an abstract syntax tree with a comment, but
> once the tree is correctly formed and I try to print it with
> erl_prettypr:format(Tree) I get this error:
>
> /5> C = erl_syntax:comment("comm")./
> /{tree,comment,{attr,0,[],none},{comment,none,"comm"}}/
> /6> erl_prettypr:format(C)./
> /** exception error: no function clause matching prettypr:strwidth(99,1)/
> /in function prettypr:string/1/
> /in call from prettypr:text/1/
> /in call from erl_prettypr:stack_comment_lines/1/
> /in call from erl_prettypr:lay_2/2/
> /in call from erl_prettypr:format/2/
>
> My question is: is this error a prettypr bug? or am I doing something
> wrong using erl_prettypr:format withot any options besides the Tree?

When you construct the comment, you have to give it a list of lines of 
text, not just a single string. For example:

   C1 = erl_syntax:comment(["comm"]).

   C2 = erl_syntax:comment(["comm line 1", "comm line 2"]).

    /Richard



More information about the erlang-questions mailing list