glr.cc: don't issue two error messages when syntax_error is thrown

Reported by Askar Safin.
https://lists.gnu.org/archive/html/bison-patches/2019-01/msg00000.html

* data/skeletons/glr.c (yygetToken): Return YYEMPTY when an exception
is thrown.
* data/skeletons/lalr1.cc: Log when an exception is caught.
* tests/c++.at (Syntax error as exception): Be sure to recover from
error before triggering another error.
This commit is contained in:
Akim Demaille
2019-01-02 11:43:08 +01:00
parent 5be47a73e8
commit 80ef7e7639
3 changed files with 19 additions and 7 deletions

View File

@@ -778,11 +778,12 @@ yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* yystackp])[]b4_user_formals
#if YY_EXCEPTIONS
}
catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc)
{]b4_locations_if([
{
YYDPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([
yylloc = yyexc.location;])[
yyerror (]b4_lyyerror_args[yyexc.what ());
// Map to the undef token.
*yycharp = YYMAXUTOK + 1;
// Leave yytoken/yychar to YYEMPTY.
return YYEMPTY;
}
#endif // YY_EXCEPTIONS]], [[
*yycharp = ]b4_lex[;]])[
@@ -871,7 +872,8 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
#if YY_EXCEPTIONS
}
catch (const syntax_error& yyexc)
{]b4_locations_if([
{
YYDPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([
*yylocp = yyexc.location;])[
yyerror (]b4_yyerror_args[yyexc.what ());
YYERROR;
@@ -2353,7 +2355,10 @@ b4_dollar_popdef])[]dnl
else if (yyisErrorAction (yyaction))
{]b4_locations_if([[
yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
yyreportSyntaxError (&yystack]b4_user_args[);
/* If yylex returned no token (YYEMPTY), it already
issued an error message. */
if (yytoken != YYEMPTY)
yyreportSyntaxError (&yystack]b4_user_args[);
goto yyuser_error;
}
else

View File

@@ -827,6 +827,7 @@ b4_dollar_popdef])[]dnl
#if YY_EXCEPTIONS
catch (const syntax_error& yyexc)
{
YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';
error (yyexc);
goto yyerrlab1;
}
@@ -916,6 +917,7 @@ b4_dollar_popdef])[]dnl
#if YY_EXCEPTIONS
catch (const syntax_error& yyexc)
{
YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';
error (yyexc);
YYERROR;
}