"Missing right curly or square bracket" warning could in fact say which
perl says
Unmatched right curly bracket at ... line 129, at end of line
That's clear. But other times it just says
Missing right curly or square bracket at ... line 190, at end of line
So where's the bug? The bug is sometimes perl uses Advanced Technology™ or whatever, to give precise answers, while other times it gives blurry answers.
Surely it has kept a count, e.g.,
e.g., 27 { and 27 } and 33 [, but only 32 ], so it could give
a more precise answer about which is missing.
perl says
Unmatched right curly bracket at ... line 129, at end of line
That's clear. But other times it just says
Missing right curly or square bracket at ... line 190, at end of line
So where's the bug? The bug is sometimes perl uses Advanced Technology™ or whatever, to give precise answers, while other times it gives blurry answers.
Surely it has kept a count, e.g., e.g., 27
{and 27}and 33[, but only 32], so it could give a more precise answer about which is missing.
Your Subject for this ticket claims that perl "could in fact" specify the exact type of missing right bracket (curly or square) in this error message. The use of "could in fact" rather than "should" suggests that we can make this distinction but for some reason have simply neglected to do so. Can you identify the place in the codebase that supports this claim?
AFAICT, this phrasing of the missing right bracket error message was introduced into toke.c by Gurusamy Sarathy in commit d98d5fffa33 in March 1999. Previously, the message simply read, Missing right bracket, and that message was introduced (probably by Larry Wall) somewhere in the alpha stage of Perl 5's development. My hunch is that if we could have made the requested distinction in an easy way, we would have done so long ago.
On Mon, Dec 04, 2023 at 06:31:27AM -0800, James E Keenan wrote:
Your Subject for this ticket claims that
perl"could in fact" specify the exact type of missing right bracket (curly or square) in this error message. The use of "could in fact" rather than "should" suggests that we can make this distinction but for some reason have simply neglected to do so. Can you identify the place in the codebase that supports this claim?AFAICT, this phrasing of the missing right bracket error message was introduced into
toke.cby Gurusamy Sarathy in commit d98d5fffa33 in March 1999. Previously, the message simply read,Missing right bracket, and that message was introduced (probably by Larry Wall) somewhere in the alpha stage of Perl 5's development. My hunch is that if we could have made the requested distinction in an easy way, we would have done so long ago.
I think the request is pointing out that when perl reaches the end of parsing and notices that that not all open brackets have been accounted for, it includes in the error the line at which perl noticed this - which is typically the last line in the source file.
It (presumably) would be useful if perl also indicated which line the unmatched opening bracket was located on. So for this code:
{
my $a;
{
my $b;
}
At the moment perl says:
Missing right curly or square bracket at foo line 6, at end of line
syntax error at foo line 6, at EOF
Presumably it would be nice if it could indicate that the most recent unmatched bracket was on line 1.
I don't think the parser records that information at the moment, but there's no reason in principle(*) why it couldn't be made to do so.
(*) Of course with the perl parser lots of things are easy in principle but turn out to be hard in practice.
-- Music lesson: a symbiotic relationship whereby a pupil's embellishments concerning the amount of practice performed since the last lesson are rewarded with embellishments from the teacher concerning the pupil's progress over the corresponding period.
The use of "could in fact" rather than "should" suggests that we can make this distinction but for some reason have simply neglected to do so. Can you identify the place in the codebase that supports this claim?
No, but consider:
$ perl -e '{'
Missing right curly or square bracket at -e line 1, at end of line
Here perl says "curly or square bracket" as if it isn't sure which it is looking for. But:
$ perl -e '{ ]'
syntax error at -e line 1, near "{ ]"
So the parser knows full well that ] is not syntactically valid at this point, and only a curly bracket is acceptable.
$ perl -e '{'
Missing right curly or square bracket at -e line 1, at end of line
is a great example. "Even a three-year-old could distinguish which one was missing and give a clearer answer."