mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 16:53:02 +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>
|
<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;
|
STRING_FINISH;
|
||||||
loc->start = token_start;
|
loc->start = token_start;
|
||||||
val->chars = last_string;
|
val->chars = last_string;
|
||||||
BEGIN INITIAL;
|
BEGIN INITIAL;
|
||||||
return STRING;
|
return STRING;
|
||||||
}
|
}
|
||||||
|
<<EOF>> unexpected_eof (token_start, "\"");
|
||||||
|
"\n" unexpected_newline (token_start, "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------.
|
/*----------------------------------------------------------.
|
||||||
@@ -543,49 +535,27 @@ eqopt ([[:space:]]*=)?
|
|||||||
|
|
||||||
<SC_ESCAPED_CHARACTER>
|
<SC_ESCAPED_CHARACTER>
|
||||||
{
|
{
|
||||||
"'"|"\n" {
|
"'" {
|
||||||
STRING_FINISH;
|
STRING_FINISH;
|
||||||
loc->start = token_start;
|
loc->start = token_start;
|
||||||
val->character = last_string[0];
|
val->character = last_string[0];
|
||||||
|
|
||||||
|
/* FIXME: Eventually, make these errors. */
|
||||||
|
if (last_string[0] == '\0')
|
||||||
{
|
{
|
||||||
/* FIXME: Eventually, make these errors. */
|
complain (loc, Wother, _("empty character literal"));
|
||||||
if (last_string[0] == '\0')
|
/* '\0' seems dangerous even if we are about to complain. */
|
||||||
{
|
val->character = '\'';
|
||||||
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"));
|
|
||||||
}
|
}
|
||||||
if (yytext[0] == '\n')
|
else if (last_string[1] != '\0')
|
||||||
unexpected_newline (token_start, "'");
|
complain (loc, Wother,
|
||||||
STRING_FREE;
|
_("extra characters in character literal"));
|
||||||
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, "'");
|
|
||||||
STRING_FREE;
|
STRING_FREE;
|
||||||
BEGIN INITIAL;
|
BEGIN INITIAL;
|
||||||
return CHAR;
|
return CHAR;
|
||||||
}
|
}
|
||||||
|
"\n" unexpected_newline (token_start, "'");
|
||||||
|
<<EOF>> unexpected_eof (token_start, "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------.
|
/*-----------------------------------------------------------.
|
||||||
@@ -612,15 +582,7 @@ eqopt ([[:space:]]*=)?
|
|||||||
[^<>]+ STRING_GROW;
|
[^<>]+ STRING_GROW;
|
||||||
"<"+ STRING_GROW; nesting += yyleng;
|
"<"+ STRING_GROW; nesting += yyleng;
|
||||||
|
|
||||||
<<EOF>> {
|
<<EOF>> unexpected_eof (token_start, ">");
|
||||||
unexpected_eof (token_start, ">");
|
|
||||||
STRING_FINISH;
|
|
||||||
loc->start = token_start;
|
|
||||||
val->uniqstr = uniqstr_new (last_string);
|
|
||||||
STRING_FREE;
|
|
||||||
BEGIN INITIAL;
|
|
||||||
return TAG;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------.
|
/*----------------------------.
|
||||||
@@ -691,15 +653,15 @@ eqopt ([[:space:]]*=)?
|
|||||||
<SC_CHARACTER>
|
<SC_CHARACTER>
|
||||||
{
|
{
|
||||||
"'" STRING_GROW; BEGIN context_state;
|
"'" STRING_GROW; BEGIN context_state;
|
||||||
\n unexpected_newline (token_start, "'"); BEGIN context_state;
|
\n unexpected_newline (token_start, "'");
|
||||||
<<EOF>> unexpected_eof (token_start, "'"); BEGIN context_state;
|
<<EOF>> unexpected_eof (token_start, "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
<SC_STRING>
|
<SC_STRING>
|
||||||
{
|
{
|
||||||
"\"" STRING_GROW; BEGIN context_state;
|
"\"" STRING_GROW; BEGIN context_state;
|
||||||
\n unexpected_newline (token_start, "\""); BEGIN context_state;
|
\n unexpected_newline (token_start, "\"");
|
||||||
<<EOF>> unexpected_eof (token_start, "\""); BEGIN context_state;
|
<<EOF>> unexpected_eof (token_start, "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -750,15 +712,7 @@ eqopt ([[:space:]]*=)?
|
|||||||
(as '<' '<%'). */
|
(as '<' '<%'). */
|
||||||
"<"{splice}"<" STRING_GROW;
|
"<"{splice}"<" STRING_GROW;
|
||||||
|
|
||||||
<<EOF>> {
|
<<EOF>> unexpected_eof (code_start, "}");
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<SC_BRACED_CODE>
|
<SC_BRACED_CODE>
|
||||||
@@ -809,14 +763,7 @@ eqopt ([[:space:]]*=)?
|
|||||||
return PROLOGUE;
|
return PROLOGUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
<<EOF>> {
|
<<EOF>> unexpected_eof (code_start, "%}");
|
||||||
unexpected_eof (code_start, "%}");
|
|
||||||
STRING_FINISH;
|
|
||||||
loc->start = code_start;
|
|
||||||
val->chars = last_string;
|
|
||||||
BEGIN INITIAL;
|
|
||||||
return PROLOGUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -999,8 +946,8 @@ handle_syncline (char *args, location loc)
|
|||||||
|
|
||||||
/*----------------------------------------------------------------.
|
/*----------------------------------------------------------------.
|
||||||
| For a token or comment starting at START, report message MSGID, |
|
| For a token or comment starting at START, report message MSGID, |
|
||||||
| which should say that an end marker was found before |
|
| which should say that an end marker was found before the |
|
||||||
| the expected TOKEN_END. |
|
| expected TOKEN_END. Then, pretend that TOKEN_END was found. |
|
||||||
`----------------------------------------------------------------*/
|
`----------------------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1009,6 +956,15 @@ unexpected_end (boundary start, char const *msgid, char const *token_end)
|
|||||||
location loc;
|
location loc;
|
||||||
loc.start = start;
|
loc.start = start;
|
||||||
loc.end = scanner_cursor;
|
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);
|
token_end = quote (token_end);
|
||||||
/* Instead of '\'', display "'". */
|
/* Instead of '\'', display "'". */
|
||||||
if (STREQ (token_end, "'\\''"))
|
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. |
|
| 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. |
|
| 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
|
static void
|
||||||
|
|||||||
@@ -1469,12 +1469,22 @@ start: '
|
|||||||
]])
|
]])
|
||||||
AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]])
|
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: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: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
|
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],
|
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], [],
|
AT_BISON_CHECK([two.y], [1], [],
|
||||||
[[two.y:2.8-11: warning: extra characters in character literal [-Wother]
|
[[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: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: error: missing "'" at end of file
|
||||||
|
two.y:4.8-10: warning: extra characters in character literal [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_DATA([three.y],
|
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], [],
|
AT_BISON_CHECK([three.y], [1], [],
|
||||||
[[three.y:2.8-12: warning: extra characters in character literal [-Wother]
|
[[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: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: error: missing "'" at end of file
|
||||||
|
three.y:4.8-11: warning: extra characters in character literal [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|||||||
Reference in New Issue
Block a user