[m-rev.] For revew: a new, improved pretty printer

Zoltan Somogyi zs at csse.unimelb.edu.au
Wed Aug 1 17:34:16 AEST 2007


On 01-Aug-2007, Ralph Becket <rafe at csse.unimelb.edu.au> wrote:
> +:- type doc
> +    --->    s(string)                   % Output a literal string.  Strings
> +                                        %   containing newlines, hard
> +                                        %   tabs, etc. will lead to strange
> +                                        %   output.
> +    ;       nl                          % Output a newline if the enclosing
> +                                        %   group does not fit on the current
> +                                        %   line.

I think the documentation would be much easier to read (and to write)
in this style:

       ;        nl
       		% Output a newline if the enclosing group does not fit
		% on the current line.

I would consider renaming the constructor s/1 to something else, both to make
it more readable and to avoid the ambiguity with the constructor used in
string.format.

> +    ;       open_group                  % Open a new group (groups control
> +                                        %   how nls are handled).
> +    ;       close_group                 % Close a group.

Document how unmatched open_groups and close_groups are handled.

> +    ;       indent(string)              % Append a string to indentation.
> +    ;       outdent                     % Remove the last indentation string.

Likewise

> +    ;       pp_list(list(univ), doc)    % Pretty print a list of items
> +                                        %  using the given doc as a
> +                                        %  separator between items.  Each
> +                                        %  item - separator pair is placed
> +                                        %  inside a group, preceded by nl
> +                                        %  and set_arg_priority.

What is set_arg_priority? You have set_OP_priority below.

Also, items and separators are not pairs, since N items have N-1 separators.

Are there limits on what docs are permissible or sensible separators?

> +    ;       pp_term(string, list(univ)) % Pretty print a term with zero or
> +                                        %  more arguments.  If the term
> +                                        %  corresponds to a Mercury operator
> +                                        %  it will be printed with appropriate
> +                                        %  fixity and, if necessary, in
> +                                        %  parentheses.  The term name will be
> +                                        %  quoted and escaped if necessary.

> +    ;       set_op_priority(ops.priority)
> +                                        % Set the current priority for printing
> +                                        %  operator terms with the correct
> +                                        %  parenthesisation.

What is the scope of this effect? Why isn't the scope a doc supplied as an
argument?

> +    ;       set_limit(pp_limit).        % Set the truncation limit.  This
> +                                        %  should not be necessary for user
> +                                        %  defined pretty printers!

I don't know which of several possible meanings of "truncation limit" you
mean here (e.g. is the limit hard or soft?). However, regardless of the
meaning, which is this part of a doc instead of an argument to the predicate
that prints docs or converts them to strings? If it has to be a part of
the doc for some reason, what is the scope of its effect?

Zoltan.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list