[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/12] yacc.c: let custom error messages see the location
From: |
Akim Demaille |
Subject: |
[PATCH 08/12] yacc.c: let custom error messages see the location |
Date: |
Thu, 16 Jan 2020 07:58:19 +0100 |
* 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.
---
data/skeletons/yacc.c | 19 ++++++++++++++-----
tests/calc.at | 1 +
tests/local.at | 4 +++-
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index 5c7a938d..b6485258 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)
{
--
2.24.1
- Re: RFC: custom error messages, (continued)
- [PATCH 02/12] yacc.c: store token numbers, not token strings, Akim Demaille, 2020/01/16
- [PATCH 03/12] yacc.c: style: avoid macros, Akim Demaille, 2020/01/16
- [PATCH 01/12] yacc.c: extract yyerror_message_arguments, Akim Demaille, 2020/01/16
- [PATCH 04/12] yacc.c: add custom error message generation, Akim Demaille, 2020/01/16
- [PATCH 06/12] tests: compute verbose error messages from the custom ones, Akim Demaille, 2020/01/16
- [PATCH 05/12] yacc.c: check custom error messages, Akim Demaille, 2020/01/16
- [PATCH 07/12] yacc.c: isolate yyexpected_tokens, Akim Demaille, 2020/01/16
- [PATCH 08/12] yacc.c: let custom error messages see the location,
Akim Demaille <=
- [PATCH 09/12] yacc.c: check custom error messages with parse-params, Akim Demaille, 2020/01/16
- [PATCH 10/12] tests: a clearer test for parse-params, Akim Demaille, 2020/01/16
- [PATCH 12/12] yacc.c: portability to G++ 4.8, Akim Demaille, 2020/01/16
- [PATCH 11/12] yacc.c: pass the parse-params to yyreport_syntax_error, Akim Demaille, 2020/01/16
- Re: RFC: custom error messages, Christian Schoenebeck, 2020/01/16
- Re: RFC: custom error messages, Akim Demaille, 2020/01/17
- Re: RFC: custom error messages, Christian Schoenebeck, 2020/01/18
Re: RFC: custom error messages, Rici Lake, 2020/01/06
Re: RFC: custom error messages, Adrian Vogelsgesang, 2020/01/08