]> git.saurik.com Git - bison.git/commitdiff
Propagate i18n changes into glr.c.
authorAkim Demaille <demaille@gostai.com>
Thu, 11 Dec 2008 08:37:40 +0000 (09:37 +0100)
committerAkim Demaille <demaille@gostai.com>
Thu, 11 Dec 2008 09:47:06 +0000 (10:47 +0100)
* TODO: Update.
* data/glr.c (yyreportSyntaxError): Use "switch" instead of
building the error message format dynamically.
* data/lalr1.java: Formatting changes.

ChangeLog
TODO
data/glr.c
data/lalr1.java

index dd650dfe0116187a0464446f605ad83033b8f2a6..6edfdab775d11e568f4be8c5da9937a3f002d1b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-12-11  Akim Demaille  <demaille@gostai.com>
+
+       Propagate i18n changes into glr.c.
+       * TODO: Update.
+       * data/glr.c (yyreportSyntaxError): Use "switch" instead of
+       building the error message format dynamically.
+       * data/lalr1.java: Formatting changes.
+
 2008-12-11  Akim Demaille  <demaille@gostai.com>
 
        Use testsuite -C.
 2008-12-11  Akim Demaille  <demaille@gostai.com>
 
        Use testsuite -C.
diff --git a/TODO b/TODO
index a9ec30838b565d201ad35ff8021a92f8e9c5a5ed..b12a039a3bc9eec33f49861fc7a209ca507bad4a 100644 (file)
--- a/TODO
+++ b/TODO
@@ -161,8 +161,8 @@ In lalr1.cc we invoke it with the translated lookahead (yytoken), and
 yacc.c uses yychar.  I don't see why.
 
 ** yysyntax_error
 yacc.c uses yychar.  I don't see why.
 
 ** yysyntax_error
-The use of switch to select yyfmt in lalr1.cc seems simpler than
-what's done in yacc.c.
+The code bw glr.c and yacc.c is really alike, we can certainly factor
+some parts.
 
 * Header guards
 
 
 * Header guards
 
index 9998612b23467a9c23362d14a62cef8ebd4afc0b..6fd561e47ace34b59c5e60d5124c4e7476370c71 100644 (file)
@@ -2043,18 +2043,10 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
          yybool yysize_overflow = yyfalse;
          char* yymsg = NULL;
          enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
          yybool yysize_overflow = yyfalse;
          char* yymsg = NULL;
          enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+          /* Internationalized format string. */
+          const char *yyformat = 0;
+          /* Arguments of yyformat. */
          char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
          char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
-         int yyx;
-         char *yyfmt;
-         char const *yyf;
-         static char const yyunexpected[] = "syntax error, unexpected %s";
-         static char const yyexpecting[] = ", expecting %s";
-         static char const yyor[] = " or %s";
-         char yyformat[sizeof yyunexpected
-                       + sizeof yyexpecting - 1
-                       + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
-                          * (sizeof yyor - 1))];
-         char const *yyprefix = yyexpecting;
 
          /* Start YYX at -YYN if negative to avoid negative indexes in
             YYCHECK.  */
 
          /* Start YYX at -YYN if negative to avoid negative indexes in
             YYCHECK.  */
@@ -2063,10 +2055,13 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
          /* Stay within bounds of both yycheck and yytname.  */
          int yychecklim = YYLAST - yyn + 1;
          int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
          /* Stay within bounds of both yycheck and yytname.  */
          int yychecklim = YYLAST - yyn + 1;
          int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
-         int yycount = 1;
 
 
-         yyarg[0] = yytokenName (yytoken);
-         yyfmt = yystpcpy (yyformat, yyunexpected);
+          /* Number of reported tokens (one for the "unexpected", one per
+             "expected"). */
+          int yycount = 0;
+          int yyx;
+
+         yyarg[yycount++] = yytokenName (yytoken);
 
          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
            if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
 
          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
            if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
@@ -2075,19 +2070,29 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
                  {
                    yycount = 1;
                    yysize = yysize0;
                  {
                    yycount = 1;
                    yysize = yysize0;
-                   yyformat[sizeof yyunexpected - 1] = '\0';
                    break;
                  }
                yyarg[yycount++] = yytokenName (yyx);
                yysize1 = yysize + yytnamerr (NULL, yytokenName (yyx));
                yysize_overflow |= yysize1 < yysize;
                yysize = yysize1;
                    break;
                  }
                yyarg[yycount++] = yytokenName (yyx);
                yysize1 = yysize + yytnamerr (NULL, yytokenName (yyx));
                yysize_overflow |= yysize1 < yysize;
                yysize = yysize1;
-               yyfmt = yystpcpy (yyfmt, yyprefix);
-               yyprefix = yyor;
              }
 
              }
 
-         yyf = YY_(yyformat);
-         yysize1 = yysize + strlen (yyf);
+          switch (yycount)
+            {
+#define YYCASE_(N, S)                           \
+              case N:                           \
+                yyformat = S;                   \
+              break
+              YYCASE_(1, YY_("syntax error, unexpected %s"));
+              YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
+              YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
+              YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
+              YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
+#undef YYCASE_
+            }
+
+         yysize1 = yysize + strlen (yyformat);
          yysize_overflow |= yysize1 < yysize;
          yysize = yysize1;
 
          yysize_overflow |= yysize1 < yysize;
          yysize = yysize1;
 
@@ -2098,17 +2103,17 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
            {
              char *yyp = yymsg;
              int yyi = 0;
            {
              char *yyp = yymsg;
              int yyi = 0;
-             while ((*yyp = *yyf))
+             while ((*yyp = *yyformat))
                {
                {
-                 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
+                 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
                    {
                      yyp += yytnamerr (yyp, yyarg[yyi++]);
                    {
                      yyp += yytnamerr (yyp, yyarg[yyi++]);
-                     yyf += 2;
+                     yyformat += 2;
                    }
                  else
                    {
                      yyp++;
                    }
                  else
                    {
                      yyp++;
-                     yyf++;
+                     yyformat++;
                    }
                }
              yyerror (]b4_lyyerror_args[yymsg);
                    }
                }
              yyerror (]b4_lyyerror_args[yymsg);
index af3cd12e97240a0f23e0d1e336e36374a29cf051..b89a4233521954eca62a7cbe2c930a736f7a3458 100644 (file)
@@ -757,7 +757,7 @@ m4_popdef([b4_at_dollar])])dnl
                       res.append (yytnamerr_ (yytname_[x]));
                     }
               }
                       res.append (yytnamerr_ (yytname_[x]));
                     }
               }
-        return res.toString ();
+            return res.toString ();
           }
       }
 ]])[
           }
       }
 ]])[