bison-patches
[Top][All Lists]
Advanced

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

Re: Public / protected access to parser's symbol_name() in C++


From: Akim Demaille
Subject: Re: Public / protected access to parser's symbol_name() in C++
Date: Sun, 10 May 2020 10:10:28 +0200


> Le 10 mai 2020 à 10:06, Akim Demaille <address@hidden> a écrit :
> 
> I'm also installing this in maint.  I don't like to add new features
> in bug fix releases, but now having this was really a bug in the API.

I don't like style changes in bug fix releases, but in this case, it
cannot do harm for the end users, while doing this just in master could
make maintenance between both branches really troublesome.

So I'll install this in maint too.

commit 091943f265b83b22e2cf353c511a22eb446b528a
Author: Akim Demaille <address@hidden>
Date:   Sun May 10 10:06:11 2020 +0200

    c++: style: reorder generated code
    
    The implementation of yy::parser::symbol_name is emitted even before
    the implementation of yy::parser::parser.  This makes little sense.
    
    * data/skeletons/lalr1.cc (symbol_name): Move its implementation in
    the same place as in the class definition: after "error" and before
    "context".

diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc
index 2c4b17c0..204b82d9 100644
--- a/data/skeletons/lalr1.cc
+++ b/data/skeletons/lalr1.cc
@@ -613,83 +613,6 @@ m4_if(b4_prefix, [yy], [],
 #define YYRECOVERING()  (!!yyerrstatus_)
 
 ]b4_namespace_open[
-]b4_parse_error_bmatch([custom\|detailed],
-[[  const char *
-  ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
-  {
-    static const char *const yy_sname[] =
-    {
-    ]b4_symbol_names[
-    };]b4_has_translations_if([[
-    /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
-       internationalizable.  */
-    static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
-    {
-    ]b4_translatable[
-    };
-    return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
-            ? _(yy_sname[yysymbol])
-            : yy_sname[yysymbol]);]], [[
-    return yy_sname[yysymbol];]])[
-  }
-]],
-[simple],
-[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
-  const char *
-  ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
-  {
-    return yytname_[yysymbol];
-  }
-#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
-]],
-[verbose],
-[[  /* Return YYSTR after stripping away unnecessary quotes and
-     backslashes, so that it's suitable for yyerror.  The heuristic is
-     that double-quoting is unnecessary unless the string contains an
-     apostrophe, a comma, or backslash (other than backslash-backslash).
-     YYSTR is taken from yytname.  */
-  std::string
-  ]b4_parser_class[::yytnamerr_ (const char *yystr)
-  {
-    if (*yystr == '"')
-      {
-        std::string yyr;
-        char const *yyp = yystr;
-
-        for (;;)
-          switch (*++yyp)
-            {
-            case '\'':
-            case ',':
-              goto do_not_strip_quotes;
-
-            case '\\':
-              if (*++yyp != '\\')
-                goto do_not_strip_quotes;
-              else
-                goto append;
-
-            append:
-            default:
-              yyr += *yyp;
-              break;
-
-            case '"':
-              return yyr;
-            }
-      do_not_strip_quotes: ;
-      }
-
-    return yystr;
-  }
-
-  std::string
-  ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
-  {
-    return yytnamerr_ (yytname_[yysymbol]);
-  }
-]])[
-
   /// Build a parser object.
   ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)
 #if ]b4_api_PREFIX[DEBUG
@@ -1273,8 +1196,86 @@ b4_dollar_popdef])[]dnl
   {
     error (]b4_join(b4_locations_if([yyexc.location]),
                     [[yyexc.what ()]])[);
-  }]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
+  }
 
+]b4_parse_error_bmatch([custom\|detailed],
+[[  const char *
+  ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
+  {
+    static const char *const yy_sname[] =
+    {
+    ]b4_symbol_names[
+    };]b4_has_translations_if([[
+    /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
+       internationalizable.  */
+    static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
+    {
+    ]b4_translatable[
+    };
+    return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
+            ? _(yy_sname[yysymbol])
+            : yy_sname[yysymbol]);]], [[
+    return yy_sname[yysymbol];]])[
+  }
+]],
+[simple],
+[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
+  const char *
+  ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
+  {
+    return yytname_[yysymbol];
+  }
+#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
+]],
+[verbose],
+[[  /* Return YYSTR after stripping away unnecessary quotes and
+     backslashes, so that it's suitable for yyerror.  The heuristic is
+     that double-quoting is unnecessary unless the string contains an
+     apostrophe, a comma, or backslash (other than backslash-backslash).
+     YYSTR is taken from yytname.  */
+  std::string
+  ]b4_parser_class[::yytnamerr_ (const char *yystr)
+  {
+    if (*yystr == '"')
+      {
+        std::string yyr;
+        char const *yyp = yystr;
+
+        for (;;)
+          switch (*++yyp)
+            {
+            case '\'':
+            case ',':
+              goto do_not_strip_quotes;
+
+            case '\\':
+              if (*++yyp != '\\')
+                goto do_not_strip_quotes;
+              else
+                goto append;
+
+            append:
+            default:
+              yyr += *yyp;
+              break;
+
+            case '"':
+              return yyr;
+            }
+      do_not_strip_quotes: ;
+      }
+
+    return yystr;
+  }
+
+  std::string
+  ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
+  {
+    return yytnamerr_ (yytname_[yysymbol]);
+  }
+]])[
+
+]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
   // ]b4_parser_class[::context.
   ]b4_parser_class[::context::context (const ]b4_parser_class[& yyparser, 
const symbol_type& yyla)
     : yyparser_ (yyparser)




reply via email to

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