dogfooding: use YYERRCODE in our scanner

* src/scan-gram.l: Use it.
* tests/input.at: Adjust.
This commit is contained in:
Akim Demaille
2020-04-27 07:14:05 +02:00
parent 89c4e1becf
commit 7346163840
3 changed files with 43 additions and 13 deletions

13
NEWS
View File

@@ -2,6 +2,19 @@ GNU Bison NEWS
* Noteworthy changes in release ?.? (????-??-??) [?]
** New features
*** Returning the error token
When the scanner returns an invalid token or the undefined token
(YYUNDEF), the parser generates an error message and enters error
recovery. Because of that error message, most scanners that find lexical
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
error-recovery mode without triggering an additional error message. See
the bistromathic for an example.
* Noteworthy changes in release 3.5.90 (2020-04-18) [beta]

View File

@@ -307,6 +307,7 @@ eqopt ({sp}=)?
"%"{id} {
complain (loc, complaint, _("invalid directive: %s"), quote (yytext));
return GRAM_ERRCODE;
}
":" return COLON;
@@ -328,6 +329,7 @@ eqopt ({sp}=)?
accept "1FOO" as "1 FOO". */
{int}{id} {
complain (loc, complaint, _("invalid identifier: %s"), quote (yytext));
return GRAM_ERRCODE;
}
/* Characters. */
@@ -382,6 +384,7 @@ eqopt ({sp}=)?
complain (loc, complaint, "%s: %s",
ngettext ("invalid character", "invalid characters", yyleng),
quote_mem (yytext, yyleng));
return GRAM_ERRCODE;
}
<<EOF>> {
@@ -398,7 +401,11 @@ eqopt ({sp}=)?
<SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_TSTRING,SC_TAG>
{
\0 complain (loc, complaint, _("invalid null character"));
\0 {
complain (loc, complaint, _("invalid null character"));
STRING_FREE;
return GRAM_ERRCODE;
}
}
@@ -454,6 +461,7 @@ eqopt ({sp}=)?
complain (loc, complaint,
_("unexpected identifier in bracketed name: %s"),
quote (yytext));
return GRAM_ERRCODE;
}
else
{
@@ -474,7 +482,10 @@ eqopt ({sp}=)?
}
}
else
complain (loc, complaint, _("an identifier expected"));
{
complain (loc, complaint, _("an identifier expected"));
return GRAM_ERRCODE;
}
}
[^\].A-Za-z0-9_/ \f\r\n\t\v]+|. {
@@ -482,6 +493,7 @@ eqopt ({sp}=)?
ngettext ("invalid character in bracketed name",
"invalid characters in bracketed name", yyleng),
quote_mem (yytext, yyleng));
return GRAM_ERRCODE;
}
<<EOF>> {
@@ -580,21 +592,27 @@ eqopt ({sp}=)?
{
"'" {
STRING_FINISH;
BEGIN INITIAL;
loc->start = token_start;
val->CHAR = last_string[0];
if (last_string[0] == '\0')
{
complain (loc, complaint, _("empty character literal"));
/* '\0' seems dangerous even if we are about to complain. */
val->CHAR = '\'';
}
{
complain (loc, complaint, _("empty character literal"));
STRING_FREE;
return GRAM_ERRCODE;
}
else if (last_string[1] != '\0')
complain (loc, complaint,
_("extra characters in character literal"));
STRING_FREE;
BEGIN INITIAL;
return CHAR;
{
complain (loc, complaint, _("extra characters in character literal"));
STRING_FREE;
return GRAM_ERRCODE;
}
else
{
STRING_FREE;
return CHAR;
}
}
{eol} unexpected_newline (token_start, "'");
<<EOF>> unexpected_eof (token_start, "'");

View File

@@ -102,7 +102,6 @@ input.y:6.1-17: error: invalid directive: '%a-does-not-exist'
input.y:7.1: error: invalid character: '%'
input.y:7.2: error: invalid character: '-'
input.y:8.1-9.0: error: missing '%}' at end of file
input.y:8.1-9.0: error: unexpected %{...%}
]])
AT_CLEANUP