]> git.saurik.com Git - bison.git/commitdiff
scanner: reintroduce unput for missing end tokens
authorTheophile Ranquet <ranquet@lrde.epita.fr>
Thu, 15 Nov 2012 17:10:35 +0000 (17:10 +0000)
committerTheophile Ranquet <ranquet@lrde.epita.fr>
Thu, 27 Dec 2012 16:57:03 +0000 (17:57 +0100)
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 aa4180418fff518198e1b0f2c43fec6432210dc7.

* src/scan-gram.l (unexpected_end): Here.
* tests/input.at: Adjust for new order of error reports.

src/scan-gram.l
tests/input.at

index 4b7591bb1f9a74c0fe5799ccd160899d0ee8596f..0ea06c3fffda6714293a5c6201d281ede2d95367 100644 (file)
@@ -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')
-        {
-          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')
-      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')
     {
-      /* 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 = '\'';
     }
-    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
index f60eaec7237daa4fcfa2010073c9595ffe54a829..385d0f3a9c1953a9d1949be63cee0d86e0c6d278 100644 (file)
@@ -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