[PATCH 01/10] glr.c: fix line numbers in logs

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <[email protected]>
* data/skeletons/glr.c (yyglrReduce): Fix line numbers.
* tests/glr-regression.at: Fix expectations.
---
 TODO                    | 6 ++++++
 data/skeletons/glr.c    | 4 ++--
 tests/glr-regression.at | 2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/TODO b/TODO
index 875de655..a7dc19c2 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,10 @@
 * Soon
+** glr
+There is no test with "Parse on stack %ld rejected by rule %d" in it.
+
+** yyrline etc.
+Clarify that rule numbers in the skeletons are 1-based.
+
 ** Macros in C++
 There are many macros that should obey api.prefix: YY_CPLUSPLUS, YY_MOVE,
 etc.
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index f54d25c7..8bbb784b 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -1483,7 +1483,7 @@ yyglrReduce (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule,
       if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULLPTR)
         YY_DPRINTF ((stderr,
                      "Parse on stack %ld rejected by rule %d (line %d).\n",
-                     YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule - 1]));
+                     YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule]));
       if (yyflag != yyok)
         return yyflag;
       YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), &yysval, &yyloc);
@@ -1510,7 +1510,7 @@ yyglrReduce (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule,
       YY_DPRINTF ((stderr,
                    "Reduced stack %ld by rule %d (line %d); action deferred.  "
                    "Now in state %d.\n",
-                   YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule - 1],
+                   YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule],
                    yynewLRState));
       for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
         if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR)
diff --git a/tests/glr-regression.at b/tests/glr-regression.at
index 2fe6c7af..36093048 100644
--- a/tests/glr-regression.at
+++ b/tests/glr-regression.at
@@ -1899,7 +1899,7 @@ Now at end of input.
 Stack 0 Entering state 7
 Now at end of input.
 Splitting off stack 1 from 0.
-Reduced stack 1 by rule 2 (line 26); action deferred.  Now in state 2.
+Reduced stack 1 by rule 2 (line 27); action deferred.  Now in state 2.
 Stack 1 Entering state 2
 Now at end of input.
 Reduced stack 0 by rule 1 (line 26); action deferred.  Now in state 2.
-- 
2.29.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.