Simplify the i18n of the error messages.

* data/lalr1.cc: Comment changes.
	* data/yacc.c (yysyntax_error): Rewrite, using a switch as in
	lalr1.cc instead of building dynamically the format string.
This commit is contained in:
Akim Demaille
2008-12-11 00:59:13 +01:00
parent e5fa6147ef
commit eeb2942237
3 changed files with 43 additions and 43 deletions

View File

@@ -1,3 +1,10 @@
2008-12-11 Akim Demaille <demaille@gostai.com>
Simplify the i18n of the error messages.
* data/lalr1.cc: Comment changes.
* data/yacc.c (yysyntax_error): Rewrite, using a switch as in
lalr1.cc instead of building dynamically the format string.
2008-12-08 Akim Demaille <demaille@gostai.com> 2008-12-08 Akim Demaille <demaille@gostai.com>
Fix portability issue in the test suite. Fix portability issue in the test suite.

View File

@@ -1393,7 +1393,8 @@ b4_error_verbose_if([int yystate, int yytoken],
int yychecklim = yylast_ - yyn + 1; int yychecklim = yylast_ - yyn + 1;
int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
// Number of "expected" tokens. // Number of reported tokens (one for the "unexpected", one per
// "expected").
size_t yycount = 0; size_t yycount = 0;
// Its maximum. // Its maximum.
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };

View File

@@ -843,28 +843,10 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
YYSIZE_T yysize1; YYSIZE_T yysize1;
int yysize_overflow = 0; int yysize_overflow = 0;
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; 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;
# if 0
/* This is so xgettext sees the translatable formats that are
constructed on the fly. */
YY_("syntax error, unexpected %s");
YY_("syntax error, unexpected %s, expecting %s");
YY_("syntax error, unexpected %s, expecting %s or %s");
YY_("syntax error, unexpected %s, expecting %s or %s or %s");
YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
# endif
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 /* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. */ YYCHECK. */
@@ -873,10 +855,12 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
/* Stay within bounds of both yycheck and yytname. */ /* Stay within bounds of both yycheck and yytname. */
int yychecklim = YYLAST - yyn + 1; int yychecklim = YYLAST - yyn + 1;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yycount = 1; /* Number of reported tokens (one for the "unexpected", one per
"expected"). */
int yycount = 0;
int yyx;
yyarg[0] = yytname[yytype]; yyarg[yycount++] = yytname[yytype];
yyfmt = yystpcpy (yyformat, yyunexpected);
for (yyx = yyxbegin; yyx < yyxend; ++yyx) for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
@@ -885,19 +869,29 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
{ {
yycount = 1; yycount = 1;
yysize = yysize0; yysize = yysize0;
yyformat[sizeof yyunexpected - 1] = '\0';
break; break;
} }
yyarg[yycount++] = yytname[yyx]; yyarg[yycount++] = yytname[yyx];
yysize1 = yysize + yytnamerr (0, yytname[yyx]); yysize1 = yysize + yytnamerr (0, yytname[yyx]);
yysize_overflow |= (yysize1 < yysize); yysize_overflow |= (yysize1 < yysize);
yysize = yysize1; yysize = yysize1;
yyfmt = yystpcpy (yyfmt, yyprefix);
yyprefix = yyor;
} }
yyf = YY_(yyformat); switch (yycount)
yysize1 = yysize + yystrlen (yyf); {
#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 + yystrlen (yyformat);
yysize_overflow |= (yysize1 < yysize); yysize_overflow |= (yysize1 < yysize);
yysize = yysize1; yysize = yysize1;
@@ -911,19 +905,17 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
produced a string with the wrong number of "%s"s. */ produced a string with the wrong number of "%s"s. */
char *yyp = yyresult; char *yyp = yyresult;
int yyi = 0; int yyi = 0;
while ((*yyp = *yyf) != '\0') while ((*yyp = *yyformat) != '\0')
{ if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) {
{ yyp += yytnamerr (yyp, yyarg[yyi++]);
yyp += yytnamerr (yyp, yyarg[yyi++]); yyformat += 2;
yyf += 2; }
} else
else {
{ yyp++;
yyp++; yyformat++;
yyf++; }
}
}
} }
return yysize; return yysize;
} }