[m-rev.] for review: better diagnostics for unbalanced parentheses

Zoltan Somogyi zoltan.somogyi at runbox.com
Wed Jul 30 00:48:25 AEST 2025



On Tue, 29 Jul 2025 16:55:25 +1000, Peter Wang <novalazy at gmail.com> wrote:
> > +unbalanced.m:031: Error: predicate `q'/2 has no clauses.
> > +unbalanced.m:038: Syntax error: expected comma, `|', `]', or operator, got
> > +unbalanced.m:038:   token `)' (there is an open '[' on line 37 between the open
> > +unbalanced.m:038:   '(' on line 36 and the ')' here).
> 
> I find all the punctuation and symbols and line numbers hard to follow
> and distracting.
> 
> Here is my suggestion:
> 
>     Syntax error at token ')': expected comma, `|', `]', or operator.
>     There is an unclosed `[' on line 37.
> 
> I think it is enough to point out the location and identity of
> the last unclosed bracket.

I am following all your other suggestions, but I want to push back on this one.
Most of the time, it does not matter whether you print all unclosed brackets
or just the last one, because you rarely have more than one. But when you do,
you don't really want to have do a recompile to get the locations of the earlier ones.
I *could* make the compiler print the location of just the last one and then add
"and there are other unclosed brackets earlier as well", but to me, that would
sound like the compiler going "nya-nya, those locations are for me to know
and for you to find out", like on a kindergarten playground.

To make things easier to read, I intend to generate output like this,
with an nl piece between the sentences to make things line up:

    Syntax error at token ')': expected comma, `|', `]', or operator.
    There is an unclosed `[' on line 37.
    There is an unclosed `(' on line 42.

Would that satisfy you?

Thanks for the review.

Zoltan.





More information about the reviews mailing list