Skip to content

Commit

Permalink
perl.h, pp_ctl.c - switch to standard way of terminating compilation
Browse files Browse the repository at this point in the history
I did not fully understand the use of yyquit() when I implemented
the SYNTAX_ERROR related stuff. It is not needed, and switching to this
makes eval compile error messages more consistent.
  • Loading branch information
demerphq committed Feb 20, 2023
1 parent 8a84914 commit 21938ae
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 22 deletions.
4 changes: 1 addition & 3 deletions perl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9094,9 +9094,7 @@ END_EXTERN_C

#define PERL_STOP_PARSING_AFTER_N_ERRORS 10

#define PERL_PARSE_IS_SYNTAX_ERROR_FLAG 128
#define PERL_PARSE_IS_SYNTAX_ERROR(f) ((f) & PERL_PARSE_IS_SYNTAX_ERROR_FLAG)
#define PERL_PARSE_ERROR_COUNT(f) ((f) & (PERL_PARSE_IS_SYNTAX_ERROR_FLAG-1))
#define PERL_PARSE_ERROR_COUNT(f) (f)

/*
Expand Down
3 changes: 2 additions & 1 deletion perly.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ Perl_yyparse (pTHX_ int gramtype)
yyerrlab:
/* If not already recovering from an error, report this error. */
if (!parser->yyerrstatus) {
yyerror ("syntax error");
yyerror("syntax error");
yyquit();
}


Expand Down
6 changes: 0 additions & 6 deletions pp_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1671,13 +1671,7 @@ Perl_qerror(pTHX_ SV *err)
Perl_warn(aTHX_ "%" SVf, SVfARG(err));

if (PL_parser) {
STRLEN len;
char *err_pv = SvPV(err,len);
++PL_parser->error_count;
if (memBEGINs(err_pv,len,"syntax error"))
{
PL_parser->error_count |= PERL_PARSE_IS_SYNTAX_ERROR_FLAG;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion t/op/eval.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BEGIN {
set_up_inc('../lib');
}

plan(tests => 162);
plan(tests => 167);

eval 'pass();';

Expand Down Expand Up @@ -625,6 +625,7 @@ for("{;", "{") {
eval $_; is $@ =~ s/eval \d+/eval 1/rag, <<'EOE',
Missing right curly or square bracket at (eval 1) line 1, at end of line
syntax error at (eval 1) line 1, at EOF
Execution of (eval 1) aborted due to compilation errors.
EOE
qq'Right line number for eval "$_"';
}
Expand Down
9 changes: 7 additions & 2 deletions t/op/signatures.t
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,10 @@ like $@, _create_mismatch_regexp('main::t081', 4, 2);
is $a, 123;

eval "#line 8 foo\nsub t082 (, \$a) { }";
is $@, qq{syntax error at foo line 8, near "(,"\n};
is $@, qq{syntax error at foo line 8, near "(,"\nExecution of foo aborted due to compilation errors.\n};

eval "#line 8 foo\nsub t083 (,) { }";
is $@, qq{syntax error at foo line 8, near "(,"\n};
is $@, qq{syntax error at foo line 8, near "(,"\nExecution of foo aborted due to compilation errors.\n};

sub t084($a,$b){ $a.$b }
is prototype(\&t084), undef;
Expand Down Expand Up @@ -1132,30 +1132,35 @@ eval "#line 8 foo\nsub t095 (\$a, 123) { }";
is $@, <<EOF;
A signature parameter must start with '\$', '\@' or '%' at foo line 8, near ", 1"
syntax error at foo line 8, near ", 123"
Execution of foo aborted due to compilation errors.
EOF

eval "#line 8 foo\nno warnings; sub t096 (\$a 123) { }";
is $@, <<'EOF';
Illegal operator following parameter in a subroutine signature at foo line 8, near "($a 123"
syntax error at foo line 8, near "($a 123"
Execution of foo aborted due to compilation errors.
EOF

eval "#line 8 foo\nsub t097 (\$a { }) { }";
is $@, <<'EOF';
Illegal operator following parameter in a subroutine signature at foo line 8, near "($a { }"
syntax error at foo line 8, near "($a { }"
Execution of foo aborted due to compilation errors.
EOF

eval "#line 8 foo\nsub t098 (\$a; \$b) { }";
is $@, <<'EOF';
Illegal operator following parameter in a subroutine signature at foo line 8, near "($a; "
syntax error at foo line 8, near "($a; "
Execution of foo aborted due to compilation errors.
EOF

eval "#line 8 foo\nsub t099 (\$\$) { }";
is $@, <<EOF;
Illegal character following sigil in a subroutine signature at foo line 8, near "(\$"
syntax error at foo line 8, near "\$\$) "
Execution of foo aborted due to compilation errors.
EOF

eval "#line 8 foo\nsub t101 (\@_) { }";
Expand Down
1 change: 1 addition & 0 deletions t/uni/parser.t
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ eval "sort \x{100}%";
die $@;
EOS
syntax error at (eval 1) line 1, at EOF
Execution of (eval 1) aborted due to compilation errors.
EXPECT

# New tests go here ^^^^^
Expand Down
10 changes: 1 addition & 9 deletions toke.c
Original file line number Diff line number Diff line change
Expand Up @@ -6218,6 +6218,7 @@ yyl_leftcurly(pTHX_ char *s, const U8 formbrack)
/* This hack is to get the ${} in the message. */
PL_bufptr = s+1;
yyerror("syntax error");
yyquit();
break;
}
OPERATOR(HASHBRACK);
Expand Down Expand Up @@ -12951,15 +12952,6 @@ Perl_yyerror_pvn(pTHX_ const char *const s, STRLEN len, U32 flags)
Perl_croak(aTHX_ "%s has too many errors.\n", name);
}
}
else {
/* This is a syntax error, and we should stop compiling. */
assert(PERL_PARSE_IS_SYNTAX_ERROR(PL_error_count));
if (errsv) {
Perl_croak_sv(aTHX_ errsv);
} else {
abort_execution(errsv, name);
}
}
}
PL_in_my = 0;
PL_in_my_stash = NULL;
Expand Down

0 comments on commit 21938ae

Please sign in to comment.