yacc.c: let custom error messages see the location

* data/skeletons/yacc.c (yyparse_context_t): Add yylloc when
applicable.
(yyparse_context_location): New.
* tests/local.at (AT_YYERROR_DEFINE(c)): Handle the location.
* tests/calc.at: Check it.
This commit is contained in:
Akim Demaille
2020-01-12 11:08:06 +01:00
parent 8637438cee
commit fd33cc9c8b
3 changed files with 18 additions and 6 deletions

View File

@@ -619,7 +619,9 @@ yyreport_syntax_error (const yyparse_context_t *ctx)
if (n == -2)
return 2;
if (n)
{
{]AT_LOCATION_IF([[
LOCATION_PRINT (stderr, *yyparse_context_location (ctx));
fprintf (stderr, ": ");]])[
fprintf (stderr, "syntax error on token [%s]", yysymbol_name (arg[0]));
if (1 < n)
{