bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/4] error: rename the error token from YYERRCODE to YYerror


From: Akim Demaille
Subject: [PATCH 1/4] error: rename the error token from YYERRCODE to YYerror
Date: Tue, 28 Apr 2020 08:49:19 +0200

See https://lists.gnu.org/r/bison-patches/2020-04/msg00162.html.

* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/glr.cc,
* data/skeletons/lalr1.java, doc/bison.texi,
* examples/c/bistromathic/parse.y, src/scan-gram.l, src/symtab.c
(YYERRCODE): Rename as...
(YYerror): this.
Adjust dependencies.
---
 NEWS                                      |  6 +++---
 TODO                                      | 20 ++++----------------
 data/skeletons/bison.m4                   |  2 +-
 data/skeletons/c.m4                       |  2 +-
 data/skeletons/glr.cc                     |  8 ++++----
 data/skeletons/lalr1.java                 |  2 +-
 doc/bison.texi                            |  8 ++++----
 examples/c/bistromathic/bistromathic.test |  2 +-
 examples/c/bistromathic/parse.y           |  2 +-
 src/parse-gram.c                          | 12 ++++++------
 src/parse-gram.h                          |  2 +-
 src/scan-gram.l                           | 18 +++++++++---------
 src/symtab.c                              |  4 ++--
 tests/calc.at                             | 12 ++++++------
 tests/headers.at                          |  2 +-
 tests/input.at                            |  6 +++---
 16 files changed, 48 insertions(+), 60 deletions(-)

diff --git a/NEWS b/NEWS
index 528d0f22..26342ab7 100644
--- a/NEWS
+++ b/NEWS
@@ -12,7 +12,7 @@ GNU Bison NEWS
   errors generate an error message, and then ignore the invalid input
   without entering the error-recovery.
 
-  The scanners may now return YYERRCODE, the error token, to enter the
+  The scanners may now return YYerror, the error token, to enter the
   error-recovery mode without triggering an additional error message.  See
   the bistromathic for an example.
 
@@ -139,7 +139,7 @@ GNU Bison NEWS
   "yytoken_kind_t".
 
   This type now also includes tokens that were previously hidden: YYEOF (end
-  of input), YYUNDEF (undefined token), and YYERRCODE (error token).  They
+  of input), YYUNDEF (undefined token), and YYerror (error token).  They
   now have string aliases, internationalized when internationalization is
   enabled.  Therefore, by default, error messages now refer to "end of file"
   (internationalized) rather than the cryptic "$end", or to "invalid token"
@@ -4136,7 +4136,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
  LocalWords:  yysymbol yytnamerr yyreport ctx ARGMAX yysyntax stderr LPAREN
  LocalWords:  symrec yypcontext TOKENMAX yyexpected YYEMPTY yypstate YYEOF
  LocalWords:  autocompletion bistromathic submessages Cayuela lexcalc hoc
- LocalWords:  yytoken YYUNDEF YYERRCODE
+ LocalWords:  yytoken YYUNDEF YYerror
 
 Local Variables:
 ispell-dictionary: "american"
diff --git a/TODO b/TODO
index a4fb47b9..5407311e 100644
--- a/TODO
+++ b/TODO
@@ -23,8 +23,8 @@ basic_symbol.
   reflection to support both output types?
 
 ** Documentation
-- YYERRCODE, YYUNDEF, YYEOF
-- YYERRCODE and translation
+- YYerror, YYUNDEF, YYEOF
+- YYerror and translation
 
 ** yypcontext_expected_tokens
 Beware that returning 0 is unclear: does it mean there are no possible
@@ -33,20 +33,8 @@ lookahead, or that there are too many?
 ** bistromathic
 Beware of portability of __attribute__.
 
-** YYERRCODE
-Give it another name, it's ugly and conflicts with the way some people have
-used it so far.
-
-Possible names:
-
-- YYERROR_TOKEN, but it's too different from the other tokens, included the
-  special ones (YYEOF, YYUNDEF).
-
-- YYerror.  It looks weird, but at least it is correct: that's the name
-  under which the error token appears in the grammar: "error".  Without the
-  'YY' prefix though, granted.
-
-yacc.c should `#define YYERRCODE` to that new name in the *.c for sake of the
+** YYerror
+yacc.c should `#define YYERRCODE YYerror` in the *.c for sake of the
 projects that used it.  In particular
 
 
https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-runtime/intl/plural.y;h=a712255af4f2f739c93336d4ff6556d932a426a5;hb=HEAD
diff --git a/data/skeletons/bison.m4 b/data/skeletons/bison.m4
index a7f45bf0..10bdfcb2 100644
--- a/data/skeletons/bison.m4
+++ b/data/skeletons/bison.m4
@@ -427,7 +427,7 @@ m4_define([b4_symbol_kind],
 m4_case([$1],
   [-2],                             [[YYEMPTY]],
   [0],                              [[YYEOF]],
-  [1],                              [[YYERRCODE]],
+  [1],                              [[YYerror]],
   [2],                              [[YYUNDEF]],
   [m4_case(b4_symbol([$1], [tag]),
       [$accept],                    [[YYACCEPT]],
diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4
index 1a1e3afd..e4e461ae 100644
--- a/data/skeletons/c.m4
+++ b/data/skeletons/c.m4
@@ -439,7 +439,7 @@ m4_define([b4_symbol(-2, tag)], [[No symbol.]])
 
 m4_if(b4_symbol(0, id), [YYEOF],
      [m4_define([b4_symbol(0, id)],  [b4_api_PREFIX[][EOF]])])
-m4_define([b4_symbol(1, id)],  [b4_api_PREFIX[][ERRCODE]])
+m4_define([b4_symbol(1, id)],  [b4_api_PREFIX[][error]])
 m4_define([b4_symbol(2, id)],  [b4_api_PREFIX[][UNDEF]])
 
 
diff --git a/data/skeletons/glr.cc b/data/skeletons/glr.cc
index af15a9a6..95053a2f 100644
--- a/data/skeletons/glr.cc
+++ b/data/skeletons/glr.cc
@@ -356,10 +356,10 @@ b4_percent_define_flag_if([[global_tokens_and_yystype]],
 
 ]m4_define([b4_declare_symbol_enum],
 [[typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type 
yysymbol_kind_t;
-#define ]b4_symbol_prefix[YYEMPTY   
]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEMPTY
-#define ]b4_symbol_prefix[YYERRCODE 
]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYERRCODE
-#define ]b4_symbol_prefix[YYEOF     
]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEOF
-#define ]b4_symbol_prefix[YYUNDEF   
]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYUNDEF
+#define ]b4_symbol_prefix[YYEMPTY  
]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEMPTY
+#define ]b4_symbol_prefix[YYerror  
]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYerror
+#define ]b4_symbol_prefix[YYEOF    
]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEOF
+#define ]b4_symbol_prefix[YYUNDEF  
]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYUNDEF
 ]])[
 ]b4_percent_code_get([[provides]])[
 ]m4_popdef([b4_parse_param])dnl
diff --git a/data/skeletons/lalr1.java b/data/skeletons/lalr1.java
index 8cb000d4..844461e0 100644
--- a/data/skeletons/lalr1.java
+++ b/data/skeletons/lalr1.java
@@ -615,7 +615,7 @@ b4_dollar_popdef[]dnl
         yySymbolPrint ("Next token is", yytoken,
                        yylval]b4_locations_if([, yylloc])[);]])[
 
-        if (yytoken == SymbolKind.]b4_symbol_prefix[YYERRCODE)
+        if (yytoken == SymbolKind.]b4_symbol_prefix[YYerror)
           {
             // The scanner already issued an error message, process directly
             // to error recovery.  But do not keep the error token as
diff --git a/doc/bison.texi b/doc/bison.texi
index 84186b72..f7a70b73 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -7471,7 +7471,7 @@ enum yysymbol_kind_t
 @{
   YYSYMBOL_YYEMPTY = -2,      /* No symbol.  */
   YYSYMBOL_YYEOF = 0,         /* "end of file"  */
-  YYSYMBOL_YYERRCODE = 1,     /* error  */
+  YYSYMBOL_YYerror = 1,       /* error  */
   YYSYMBOL_YYUNDEF = 2,       /* "invalid token"  */
   YYSYMBOL_PLUS = 3,          /* "+"  */
   YYSYMBOL_MINUS = 4,         /* "-"  */
@@ -7497,7 +7497,7 @@ The location of the syntax error (that of the unexpected 
token).
 
 @deftypefun int yypcontext_expected_tokens (@code{const yypcontext_t *}ctx, 
@code{yysymbol_kind_t} @var{argv}@code{[]}, @code{int} @var{argc})
 Fill @var{argv} with the expected tokens, which never includes
-@code{YYSYMBOL_YYEMPTY}, @code{YYSYMBOL_YYERRCODE}, or
+@code{YYSYMBOL_YYEMPTY}, @code{YYSYMBOL_YYerror}, or
 @code{YYSYMBOL_YYUNDEF}.
 
 Never put more than @var{argc} elements into @var{argv}, and on success
@@ -11549,7 +11549,7 @@ struct token
   @{
     YYEMPTY = -2,              // No token.
     YYEOF = 0,                 // "end of file"
-    YYERRCODE = 256,           // error
+    YYerror = 256,             // error
     YYUNDEF = 257,             // "invalid token"
     PLUS = 258,                // "+"
     MINUS = 259,               // "-"
@@ -15126,7 +15126,7 @@ London, Department of Computer Science, TR-00-12 
(December 2000).
 @c LocalWords: redeclare automata Dparse localedir datadir XSLT midrule Wno
 @c LocalWords: multitable headitem hh basename Doxygen fno filename gdef de
 @c LocalWords: doxygen ival sval deftypemethod deallocate pos deftypemethodx
-@c LocalWords: Ctor defcv defcvx arg accessors CPP ifndef CALCXX YYERRCODE
+@c LocalWords: Ctor defcv defcvx arg accessors CPP ifndef CALCXX YYerror
 @c LocalWords: lexer's calcxx bool LPAREN RPAREN deallocation cerrno climits
 @c LocalWords: cstdlib Debian undef yywrap unput noyywrap nounput zA yyleng
 @c LocalWords: errno strtol ERANGE str strerror iostream argc argv Javadoc PSLR
diff --git a/examples/c/bistromathic/bistromathic.test 
b/examples/c/bistromathic/bistromathic.test
index 9a5b6d11..1e5bd0e1 100755
--- a/examples/c/bistromathic/bistromathic.test
+++ b/examples/c/bistromathic/bistromathic.test
@@ -118,7 +118,7 @@ run 0 '> 100% + 10
 err: 1.4: syntax error: invalid character: %'
 
 # Traces.  This allows to check the location of the error.  If we
-# forget to map YYERRCODE to YYUNDEF, error recovery enters an endless
+# forget to map YYerror to YYUNDEF, error recovery enters an endless
 # loop with this input.
 cat >input <<EOF
 (+_)
diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y
index 042c5616..925e06f5 100644
--- a/examples/c/bistromathic/parse.y
+++ b/examples/c/bistromathic/parse.y
@@ -300,7 +300,7 @@ yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc)
       // Stray characters.
     default:
       yyerror (yylloc, "syntax error: invalid character: %c", c);
-      return TOK_YYERRCODE;
+      return TOK_YYerror;
     }
 }
 
diff --git a/src/parse-gram.c b/src/parse-gram.c
index 610f2004..21c201cc 100644
--- a/src/parse-gram.c
+++ b/src/parse-gram.c
@@ -106,7 +106,7 @@ enum yysymbol_kind_t
 {
   YYSYMBOL_YYEMPTY = -2,
   YYSYMBOL_YYEOF = 0,                      /* "end of file"  */
-  YYSYMBOL_YYERRCODE = 1,                  /* error  */
+  YYSYMBOL_YYerror = 1,                    /* error  */
   YYSYMBOL_YYUNDEF = 2,                    /* "invalid token"  */
   YYSYMBOL_STRING = 3,                     /* "string"  */
   YYSYMBOL_TSTRING = 4,                    /* "translatable string"  */
@@ -1612,7 +1612,7 @@ yypcontext_expected_tokens (const yypcontext_t *yyctx,
   for (yyx = 0; yyx < YYNTOKENS; ++yyx)
     {
       yysymbol_kind_t yysym = YY_CAST (yysymbol_kind_t, yyx);
-      if (yysym != YYSYMBOL_YYERRCODE && yysym != YYSYMBOL_YYUNDEF)
+      if (yysym != YYSYMBOL_YYerror && yysym != YYSYMBOL_YYUNDEF)
         switch (yy_lac (yyctx->yyesa, yyctx->yyes, yyctx->yyes_capacity, 
yyctx->yyssp, yysym))
           {
           case YYENOMEM:
@@ -1960,14 +1960,14 @@ yybackup:
       yytoken = YYSYMBOL_YYEOF;
       YYDPRINTF ((stderr, "Now at end of input.\n"));
     }
-  else if (yychar == GRAM_ERRCODE)
+  else if (yychar == GRAM_error)
     {
       /* The scanner already issued an error message, process directly
          to error recovery.  But do not keep the error token as
          lookahead, it is too special and may lead us to an endless
          loop in error recovery. */
       yychar = GRAM_UNDEF;
-      yytoken = YYSYMBOL_YYERRCODE;
+      yytoken = YYSYMBOL_YYerror;
       yyerror_range[1] = yylloc;
       goto yyerrlab1;
     }
@@ -2705,8 +2705,8 @@ yyerrlab1:
       yyn = yypact[yystate];
       if (!yypact_value_is_default (yyn))
         {
-          yyn += YYSYMBOL_YYERRCODE;
-          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYERRCODE)
+          yyn += YYSYMBOL_YYerror;
+          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
             {
               yyn = yytable[yyn];
               if (0 < yyn)
diff --git a/src/parse-gram.h b/src/parse-gram.h
index 50dca5bf..ecda432d 100644
--- a/src/parse-gram.h
+++ b/src/parse-gram.h
@@ -80,7 +80,7 @@ extern int gram_debug;
   {
     GRAM_EMPTY = -2,
     GRAM_EOF = 0,                  /* "end of file"  */
-    GRAM_ERRCODE = 1,              /* error  */
+    GRAM_error = 1,                /* error  */
     GRAM_UNDEF = 2,                /* "invalid token"  */
     STRING = 3,                    /* "string"  */
     TSTRING = 4,                   /* "translatable string"  */
diff --git a/src/scan-gram.l b/src/scan-gram.l
index 601cc7a7..b6ddd3fa 100644
--- a/src/scan-gram.l
+++ b/src/scan-gram.l
@@ -307,7 +307,7 @@ eqopt    ({sp}=)?
 
   "%"{id} {
     complain (loc, complaint, _("invalid directive: %s"), quote (yytext));
-    return GRAM_ERRCODE;
+    return GRAM_error;
   }
 
   ":"                     return COLON;
@@ -329,7 +329,7 @@ eqopt    ({sp}=)?
      accept "1FOO" as "1 FOO".  */
   {int}{id} {
     complain (loc, complaint, _("invalid identifier: %s"), quote (yytext));
-    return GRAM_ERRCODE;
+    return GRAM_error;
   }
 
   /* Characters.  */
@@ -384,7 +384,7 @@ eqopt    ({sp}=)?
     complain (loc, complaint, "%s: %s",
               ngettext ("invalid character", "invalid characters", yyleng),
               quote_mem (yytext, yyleng));
-    return GRAM_ERRCODE;
+    return GRAM_error;
   }
 
   <<EOF>> {
@@ -404,7 +404,7 @@ eqopt    ({sp}=)?
   \0         {
     complain (loc, complaint, _("invalid null character"));
     STRING_FREE;
-    return GRAM_ERRCODE;
+    return GRAM_error;
   }
 }
 
@@ -461,7 +461,7 @@ eqopt    ({sp}=)?
         complain (loc, complaint,
                   _("unexpected identifier in bracketed name: %s"),
                   quote (yytext));
-        return GRAM_ERRCODE;
+        return GRAM_error;
       }
     else
       {
@@ -484,7 +484,7 @@ eqopt    ({sp}=)?
     else
       {
         complain (loc, complaint, _("an identifier expected"));
-        return GRAM_ERRCODE;
+        return GRAM_error;
       }
   }
 
@@ -493,7 +493,7 @@ eqopt    ({sp}=)?
               ngettext ("invalid character in bracketed name",
                         "invalid characters in bracketed name", yyleng),
               quote_mem (yytext, yyleng));
-    return GRAM_ERRCODE;
+    return GRAM_error;
   }
 
   <<EOF>> {
@@ -600,13 +600,13 @@ eqopt    ({sp}=)?
       {
         complain (loc, complaint, _("empty character literal"));
         STRING_FREE;
-        return GRAM_ERRCODE;
+        return GRAM_error;
       }
     else if (last_string[1] != '\0')
       {
         complain (loc, complaint, _("extra characters in character literal"));
         STRING_FREE;
-        return GRAM_ERRCODE;
+        return GRAM_error;
       }
     else
       {
diff --git a/src/symtab.c b/src/symtab.c
index 34ae2bc8..c9ac27f4 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -847,8 +847,8 @@ symbols_new (void)
   accept->content->class = nterm_sym;
   accept->content->number = nvars++;
 
-  /* Construct the YYERRCODE/"error" token */
-  errtoken = symbol_get ("YYERRCODE", empty_loc);
+  /* Construct the YYerror/"error" token */
+  errtoken = symbol_get ("YYerror", empty_loc);
   errtoken->content->class = token_sym;
   errtoken->content->number = ntokens++;
   {
diff --git a/tests/calc.at b/tests/calc.at
index 67fb21aa..4a9eaa73 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -226,7 +226,7 @@ read_integer (]AT_YYLEX_FORMALS[)
       fprintf (stderr, "%d.%d: ",
                AT_LOC_FIRST_LINE, AT_LOC_FIRST_COLUMN);])[
       fputs ("syntax error: invalid character: '#'\n", stderr);
-      return ]AT_TOKEN_PREFIX[]AT_API_PREFIX[ERRCODE;
+      return ]AT_TOKEN_PREFIX[]AT_API_PREFIX[error;
     }
 
   /* Return single chars. */
@@ -339,7 +339,7 @@ class CalcLexer(R) : Lexer
     if (c == '#')
       {
         stderr.writeln (]AT_LOCATION_IF([location, ": ", ])["syntax error: 
invalid character: '#'");
-        return TokenKind.YYERRCODE;
+        return TokenKind.YYerror;
       }
 
     return c;
@@ -405,7 +405,7 @@ m4_define([AT_CALC_YYLEX(java)],
         return yylex ();
       case '#':
         System.err.println(]AT_LOCATION_IF([[start + ": " + ]])["syntax error: 
invalid character: '#'");
-        return YYERRCODE;
+        return YYerror;
       default:
         return tkind;
       }
@@ -1025,9 +1025,9 @@ _AT_CHECK_CALC_ERROR([$1], [0], [(* *) + (*) + (*)],
 ]AT_JAVA_IF([1.16-1.17], [1.16])[: syntax error on token ['*'] (expected: 
[number] ['-'] ['('] ['!'])]])
 
 
-# YYERRCODE.
-# ---------
-# Check that returning YYERRCODE from the scanner properly enters
+# YYerror.
+# --------
+# Check that returning YYerror from the scanner properly enters
 # error-recovery without issuing a second error message.
 
 _AT_CHECK_CALC_ERROR([$1], [0], [(#) + (#) = 2222],
diff --git a/tests/headers.at b/tests/headers.at
index fa13819e..bf48120b 100644
--- a/tests/headers.at
+++ b/tests/headers.at
@@ -323,7 +323,7 @@ AT_PERL_CHECK([[-n -0777 -e '
       |YYChar
       |YYNTOKENS  # This is actual scoped in a C++ class.
       |YYPUSH_MORE(?:_DEFINED)?
-      |S_(YY(ACCEPT|EMPTY|EOF|ERRCODE|UNDEF))  # These guys are scoped.
+      |S_(YY(ACCEPT|EMPTY|EOF|error|UNDEF))  # These guys are scoped.
       |YYUSE
       |YY_ATTRIBUTE(?:_PURE|_UNUSED)
       |YY(?:_REINTERPRET)?_CAST
diff --git a/tests/input.at b/tests/input.at
index c459ecd5..77fa3e59 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -342,9 +342,9 @@ exp:
 %%
 int main (void)
 {
-  assert (YYERRCODE == 123);
+  assert (YYerror == 123);
   assert (YYTRANSLATE (YYEOF) == YYSYMBOL_YYEOF);
-  assert (YYTRANSLATE (YYERRCODE) == YYSYMBOL_YYERRCODE);
+  assert (YYTRANSLATE (YYerror) == YYSYMBOL_YYerror);
   assert (YYTRANSLATE (YYUNDEF) == YYSYMBOL_YYUNDEF);
   return 0;
 }
@@ -431,7 +431,7 @@ AT_BISON_CHECK([-Wno-other -S./dump-symbols.m4 input.y])
 AT_CHECK([cat symbols.csv], [],
 [[number, class, tag, id, user_number, type,
 0, Token, "end of file", YYEOF, 0, ,
-1, Token, error, YYERRCODE, 256, ,
+1, Token, error, YYerror, 256, ,
 2, Token, "invalid token", YYUNDEF, 257, ,
 3, Token, 'a', , 97, ,
 4, Token, "A1", A1, 1, ,
-- 
2.26.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]