[m-rev.] for review: better diagnostics for unbalanced parentheses
Peter Wang
novalazy at gmail.com
Wed Jul 30 12:13:37 AEST 2025
On Tue, 29 Jul 2025 16:48:25 +0200 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
>
>
> 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.
Every text editor worth using can highlight unbalanced brackets
automatically, and when you place the cursor on a bracket character,
can highlight or jump to its corresponding bracket pair. I don't feel
like more verbose output from the compiler is helpful in this case,
but YMMV.
> 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?
It's okay.
I'll make another suggestion. For this:
unbalanced.m:038: Syntax error at token `)': expected comma, `|', `]', or an
unbalanced.m:038: operator.
unbalanced.m:038: There is an open `[' on line 37 between the open `(' on
unbalanced.m:038: line 36 and the `)' here.
I think this could be better:
There is an unclosed `[' on line 37 between the `(' on line 36
and the `)' here.
- Saying "unclosed `['" instead of "open `['" in the first part
suggests both the problem and the solution.
- The word "open" is redundant in the second part, and the sentence
seems more readable once it is removed.
Peter
More information about the reviews
mailing list