diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c index aa1a4eb9..f26d9b8e 100644 --- a/data/skeletons/yacc.c +++ b/data/skeletons/yacc.c @@ -1050,7 +1050,8 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes, [[typedef struct { yy_state_t *yyssp; - int yytoken;]b4_lac_if([[ + int yytoken;]b4_locations_if([[ + YYLTYPE *yylloc;]])[]b4_lac_if([[ yy_state_t *yyesa; yy_state_t **yyes_p; YYPTRDIFF_T *yyes_capacity_p;]])[ @@ -1165,7 +1166,15 @@ yysyntax_error_arguments (const yyparse_context_t *yyctx, ]m4_case(b4_percent_define_get([[parse.error]]), [custom], -[[static int +[b4_locations_if([[/* The location of this context. */ +static YYLTYPE * +yyparse_context_location (const yyparse_context_t *yyctx) +{ + return yyctx->yylloc; +}]])[ + +/* User defined funtion to report a syntax error. */ +static int yyreport_syntax_error (const yyparse_context_t *yyctx);]], [verbose], [[# ifndef yystrlen @@ -1820,10 +1829,10 @@ yyerrlab: [custom], [[ { yyparse_context_t yyctx - = {yyssp, yytoken]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])[};]b4_lac_if([[ + = {yyssp, yytoken]b4_locations_if([[, &yylloc]])[]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])[};]b4_lac_if([[ if (yychar != YYEMPTY) YY_LAC_ESTABLISH;]])[ - if (yyreport_syntax_error (]b4_yyerror_args[&yyctx) == 2) + if (yyreport_syntax_error (&yyctx) == 2) goto yyexhaustedlab; }]], [simple], @@ -1832,7 +1841,7 @@ yyerrlab: [[ { char const *yymsgp = YY_("syntax error"); yyparse_context_t yyctx - = {yyssp, yytoken]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])[}; + = {yyssp, yytoken]b4_locations_if([[, &yylloc]])[]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])[}; int yysyntax_error_status;]b4_lac_if([[ if (yychar != YYEMPTY) YY_LAC_ESTABLISH;]])[ diff --git a/tests/calc.at b/tests/calc.at index 6b36c521..0ed9709c 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -788,6 +788,7 @@ AT_CHECK_CALC_LALR([%no-lines %define api.pure %define parse.error verbose %debu AT_CHECK_CALC_LALR([%define parse.error custom]) +AT_CHECK_CALC_LALR([%define parse.error custom %locations]) # ----------------------- # # Simple GLR Calculator. # diff --git a/tests/local.at b/tests/local.at index 05b2ed9c..e314b8bf 100644 --- a/tests/local.at +++ b/tests/local.at @@ -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) {