mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 17:23:02 +00:00
Simplify the i18n of the error messages.
* data/yacc.c (yysyntax_error): Rewrite, using a switch instead
of building dynamically the format string.
(cherry picked from commit eeb2942237)
Conflicts:
data/lalr1.cc
This commit is contained in:
committed by
Joel E. Denny
parent
4c6b13f37e
commit
d3d3628bde
@@ -1,3 +1,9 @@
|
|||||||
|
2008-12-11 Akim Demaille <demaille@gostai.com>
|
||||||
|
|
||||||
|
Simplify the i18n of the error messages.
|
||||||
|
* data/yacc.c (yysyntax_error): Rewrite, using a switch instead
|
||||||
|
of building dynamically the format string.
|
||||||
|
|
||||||
2009-10-03 Joel E. Denny <jdenny@clemson.edu>
|
2009-10-03 Joel E. Denny <jdenny@clemson.edu>
|
||||||
|
|
||||||
Remove dead code.
|
Remove dead code.
|
||||||
|
|||||||
76
data/yacc.c
76
data/yacc.c
@@ -977,28 +977,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. In other words, skip the first -YYN actions for this
|
YYCHECK. In other words, skip the first -YYN actions for this
|
||||||
@@ -1008,10 +990,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
|
||||||
@@ -1021,19 +1005,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;
|
||||||
|
|
||||||
@@ -1047,19 +1041,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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user