mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
scanner: reintroduce unput for missing end tokens
Unput was no longer used since a POSIX-compatiblity issue with Flex 2.5.31,
which has been adressed in newer versions of Flex. See this discussion:
<http://lists.gnu.org/archive/html/bug-bison/2003-04/msg00029.html>
This partially reverts commit aa4180418f.
* src/scan-gram.l (unexpected_end): Here.
* tests/input.at: Adjust for new order of error reports.
This commit is contained in:
111
src/scan-gram.l
111
src/scan-gram.l
@@ -517,23 +517,15 @@ eqopt ([[:space:]]*=)?
|
||||
|
||||
<SC_ESCAPED_STRING>
|
||||
{
|
||||
"\""|"\n" {
|
||||
if (yytext[0] == '\n')
|
||||
unexpected_newline (token_start, "\"");
|
||||
STRING_FINISH;
|
||||
loc->start = token_start;
|
||||
val->chars = last_string;
|
||||
BEGIN INITIAL;
|
||||
return STRING;
|
||||
}
|
||||
<<EOF>> {
|
||||
unexpected_eof (token_start, "\"");
|
||||
"\"" {
|
||||
STRING_FINISH;
|
||||
loc->start = token_start;
|
||||
val->chars = last_string;
|
||||
BEGIN INITIAL;
|
||||
return STRING;
|
||||
}
|
||||
<<EOF>> unexpected_eof (token_start, "\"");
|
||||
"\n" unexpected_newline (token_start, "\"");
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------.
|
||||
@@ -543,49 +535,27 @@ eqopt ([[:space:]]*=)?
|
||||
|
||||
<SC_ESCAPED_CHARACTER>
|
||||
{
|
||||
"'"|"\n" {
|
||||
"'" {
|
||||
STRING_FINISH;
|
||||
loc->start = token_start;
|
||||
val->character = last_string[0];
|
||||
|
||||
/* FIXME: Eventually, make these errors. */
|
||||
if (last_string[0] == '\0')
|
||||
{
|
||||
/* FIXME: Eventually, make these errors. */
|
||||
if (last_string[0] == '\0')
|
||||
{
|
||||
complain (loc, Wother, _("empty character literal"));
|
||||
/* '\0' seems dangerous even if we are about to complain. */
|
||||
val->character = '\'';
|
||||
}
|
||||
else if (last_string[1] != '\0')
|
||||
complain (loc, Wother,
|
||||
_("extra characters in character literal"));
|
||||
complain (loc, Wother, _("empty character literal"));
|
||||
/* '\0' seems dangerous even if we are about to complain. */
|
||||
val->character = '\'';
|
||||
}
|
||||
if (yytext[0] == '\n')
|
||||
unexpected_newline (token_start, "'");
|
||||
STRING_FREE;
|
||||
BEGIN INITIAL;
|
||||
return CHAR;
|
||||
}
|
||||
<<EOF>> {
|
||||
STRING_FINISH;
|
||||
loc->start = token_start;
|
||||
val->character = last_string[0];
|
||||
{
|
||||
/* FIXME: Eventually, make these errors. */
|
||||
if (last_string[0] == '\0')
|
||||
{
|
||||
complain (loc, Wother, _("empty character literal"));
|
||||
/* '\0' seems dangerous even if we are about to complain. */
|
||||
val->character = '\'';
|
||||
}
|
||||
else if (last_string[1] != '\0')
|
||||
complain (loc, Wother,
|
||||
_("extra characters in character literal"));
|
||||
}
|
||||
unexpected_eof (token_start, "'");
|
||||
else if (last_string[1] != '\0')
|
||||
complain (loc, Wother,
|
||||
_("extra characters in character literal"));
|
||||
STRING_FREE;
|
||||
BEGIN INITIAL;
|
||||
return CHAR;
|
||||
}
|
||||
"\n" unexpected_newline (token_start, "'");
|
||||
<<EOF>> unexpected_eof (token_start, "'");
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------.
|
||||
@@ -612,15 +582,7 @@ eqopt ([[:space:]]*=)?
|
||||
[^<>]+ STRING_GROW;
|
||||
"<"+ STRING_GROW; nesting += yyleng;
|
||||
|
||||
<<EOF>> {
|
||||
unexpected_eof (token_start, ">");
|
||||
STRING_FINISH;
|
||||
loc->start = token_start;
|
||||
val->uniqstr = uniqstr_new (last_string);
|
||||
STRING_FREE;
|
||||
BEGIN INITIAL;
|
||||
return TAG;
|
||||
}
|
||||
<<EOF>> unexpected_eof (token_start, ">");
|
||||
}
|
||||
|
||||
/*----------------------------.
|
||||
@@ -691,15 +653,15 @@ eqopt ([[:space:]]*=)?
|
||||
<SC_CHARACTER>
|
||||
{
|
||||
"'" STRING_GROW; BEGIN context_state;
|
||||
\n unexpected_newline (token_start, "'"); BEGIN context_state;
|
||||
<<EOF>> unexpected_eof (token_start, "'"); BEGIN context_state;
|
||||
\n unexpected_newline (token_start, "'");
|
||||
<<EOF>> unexpected_eof (token_start, "'");
|
||||
}
|
||||
|
||||
<SC_STRING>
|
||||
{
|
||||
"\"" STRING_GROW; BEGIN context_state;
|
||||
\n unexpected_newline (token_start, "\""); BEGIN context_state;
|
||||
<<EOF>> unexpected_eof (token_start, "\""); BEGIN context_state;
|
||||
\n unexpected_newline (token_start, "\"");
|
||||
<<EOF>> unexpected_eof (token_start, "\"");
|
||||
}
|
||||
|
||||
|
||||
@@ -750,15 +712,7 @@ eqopt ([[:space:]]*=)?
|
||||
(as '<' '<%'). */
|
||||
"<"{splice}"<" STRING_GROW;
|
||||
|
||||
<<EOF>> {
|
||||
int token = (YY_START == SC_BRACED_CODE) ? BRACED_CODE : BRACED_PREDICATE;
|
||||
unexpected_eof (code_start, "}");
|
||||
STRING_FINISH;
|
||||
loc->start = code_start;
|
||||
val->code = last_string;
|
||||
BEGIN INITIAL;
|
||||
return token;
|
||||
}
|
||||
<<EOF>> unexpected_eof (code_start, "}");
|
||||
}
|
||||
|
||||
<SC_BRACED_CODE>
|
||||
@@ -809,14 +763,7 @@ eqopt ([[:space:]]*=)?
|
||||
return PROLOGUE;
|
||||
}
|
||||
|
||||
<<EOF>> {
|
||||
unexpected_eof (code_start, "%}");
|
||||
STRING_FINISH;
|
||||
loc->start = code_start;
|
||||
val->chars = last_string;
|
||||
BEGIN INITIAL;
|
||||
return PROLOGUE;
|
||||
}
|
||||
<<EOF>> unexpected_eof (code_start, "%}");
|
||||
}
|
||||
|
||||
|
||||
@@ -999,8 +946,8 @@ handle_syncline (char *args, location loc)
|
||||
|
||||
/*----------------------------------------------------------------.
|
||||
| For a token or comment starting at START, report message MSGID, |
|
||||
| which should say that an end marker was found before |
|
||||
| the expected TOKEN_END. |
|
||||
| which should say that an end marker was found before the |
|
||||
| expected TOKEN_END. Then, pretend that TOKEN_END was found. |
|
||||
`----------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
@@ -1009,6 +956,15 @@ unexpected_end (boundary start, char const *msgid, char const *token_end)
|
||||
location loc;
|
||||
loc.start = start;
|
||||
loc.end = scanner_cursor;
|
||||
size_t i = strlen (token_end);
|
||||
|
||||
/* Adjust scanner cursor so that any later message does not count
|
||||
the characters about to be inserted. */
|
||||
scanner_cursor.column -= i;
|
||||
|
||||
while (i != 0)
|
||||
unput (token_end[--i]);
|
||||
|
||||
token_end = quote (token_end);
|
||||
/* Instead of '\'', display "'". */
|
||||
if (STREQ (token_end, "'\\''"))
|
||||
@@ -1020,6 +976,7 @@ unexpected_end (boundary start, char const *msgid, char const *token_end)
|
||||
/*------------------------------------------------------------------------.
|
||||
| Report an unexpected EOF in a token or comment starting at START. |
|
||||
| An end of file was encountered and the expected TOKEN_END was missing. |
|
||||
| After reporting the problem, pretend that TOKEN_END was found. |
|
||||
`------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
|
||||
@@ -1469,12 +1469,22 @@ start: '
|
||||
]])
|
||||
AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]])
|
||||
|
||||
AT_BISON_CHECK([empty.y], [1], [],
|
||||
AT_BISON_CHECK([-fcaret empty.y], [1], [],
|
||||
[[empty.y:2.8-9: warning: empty character literal [-Wother]
|
||||
empty.y:3.8-4.0: warning: empty character literal [-Wother]
|
||||
start: '';
|
||||
^^
|
||||
empty.y:3.8-4.0: error: missing "'" at end of line
|
||||
empty.y:4.8: warning: empty character literal [-Wother]
|
||||
start: '
|
||||
^
|
||||
empty.y:3.8-4.0: warning: empty character literal [-Wother]
|
||||
start: '
|
||||
^
|
||||
empty.y:4.8: error: missing "'" at end of file
|
||||
start: '
|
||||
^
|
||||
empty.y:4.8: warning: empty character literal [-Wother]
|
||||
start: '
|
||||
^
|
||||
]])
|
||||
|
||||
AT_DATA([two.y],
|
||||
@@ -1486,10 +1496,10 @@ AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]])
|
||||
|
||||
AT_BISON_CHECK([two.y], [1], [],
|
||||
[[two.y:2.8-11: warning: extra characters in character literal [-Wother]
|
||||
two.y:3.8-4.0: warning: extra characters in character literal [-Wother]
|
||||
two.y:3.8-4.0: error: missing "'" at end of line
|
||||
two.y:4.8-10: warning: extra characters in character literal [-Wother]
|
||||
two.y:3.8-4.0: warning: extra characters in character literal [-Wother]
|
||||
two.y:4.8-10: error: missing "'" at end of file
|
||||
two.y:4.8-10: warning: extra characters in character literal [-Wother]
|
||||
]])
|
||||
|
||||
AT_DATA([three.y],
|
||||
@@ -1501,10 +1511,10 @@ AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]])
|
||||
|
||||
AT_BISON_CHECK([three.y], [1], [],
|
||||
[[three.y:2.8-12: warning: extra characters in character literal [-Wother]
|
||||
three.y:3.8-4.0: warning: extra characters in character literal [-Wother]
|
||||
three.y:3.8-4.0: error: missing "'" at end of line
|
||||
three.y:4.8-11: warning: extra characters in character literal [-Wother]
|
||||
three.y:3.8-4.0: warning: extra characters in character literal [-Wother]
|
||||
three.y:4.8-11: error: missing "'" at end of file
|
||||
three.y:4.8-11: warning: extra characters in character literal [-Wother]
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
Reference in New Issue
Block a user