error: rename the error token from YYERRCODE to YYerror

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.
This commit is contained in:
Akim Demaille
2020-04-28 07:28:52 +02:00
parent 7346163840
commit cd4e799da4
16 changed files with 48 additions and 60 deletions

6
NEWS
View File

@@ -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"

20
TODO
View File

@@ -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

View File

@@ -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]],

View File

@@ -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]])

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
(+_)

View File

@@ -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;
}
}

View File

@@ -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)

View File

@@ -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" */

View File

@@ -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
{

View File

@@ -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++;
{

View File

@@ -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],

View File

@@ -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

View File

@@ -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, ,