bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] scan-gram.l: for flex-2.5.31: move unput call into body


From: Paul Eggert
Subject: Re: [PATCH] scan-gram.l: for flex-2.5.31: move unput call into body
Date: 18 Apr 2003 00:56:53 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Peter Muir <address@hidden> writes:

> the debian maintainer for flex says the behaviour of flex is correct
> (and suggested to move the function inside %{...%}).

That doesn't work, for reasons discussed in my email of a few minutes ago.
Thanks for the bug report, though.  I installed the following patch.

2003-04-17  Paul Eggert  <address@hidden>

        * src/scan-gram.l: Add %option nounput, since we no longer use unput.
        (unexpected_eof): Renamed from unexpected_end_of_file, for brevity.
        Do not insert the expected token via unput, as this runs afoul
        of a POSIX-compatibility bug in flex 2.5.31.
        All uses changed to BEGIN the parent state,
        since we no longer insert the expected token via unput.
        * tests/regression.at (Invalid inputs): Remove cascaded diagnostic
        that is no longer emitted after the above change.

--- src/scan-gram.l     13 Mar 2003 07:07:17 -0000      1.58
+++ src/scan-gram.l     18 Apr 2003 07:26:19 -0000      1.59
@@ -20,7 +20,7 @@
    02111-1307  USA
 */
 
-%option debug nodefault noyywrap never-interactive
+%option debug nodefault nounput noyywrap never-interactive
 %option prefix="gram_" outfile="lex.yy.c"
 
 %{
@@ -102,7 +102,7 @@ static void handle_dollar (int token_typ
 static void handle_at (int token_type, char *cp, location loc);
 static void handle_syncline (char *args);
 static int convert_ucn_to_byte (char const *hex_text);
-static void unexpected_end_of_file (boundary, char const *);
+static void unexpected_eof (boundary, char const *);
 
 %}
 %x SC_COMMENT SC_LINE_COMMENT SC_YACC_COMMENT
@@ -323,7 +323,7 @@ splice       (\\[ \f\t\v]*\n)*
 {
   "*/"     BEGIN context_state;
   .|\n    ;
-  <<EOF>>  unexpected_end_of_file (token_start, "*/");
+  <<EOF>>  unexpected_eof (token_start, "*/"); BEGIN context_state;
 }
 
 
@@ -334,7 +334,7 @@ splice       (\\[ \f\t\v]*\n)*
 <SC_COMMENT>
 {
   "*"{splice}"/"  STRING_GROW; BEGIN context_state;
-  <<EOF>>        unexpected_end_of_file (token_start, "*/");
+  <<EOF>>        unexpected_eof (token_start, "*/"); BEGIN context_state;
 }
 
 
@@ -368,7 +368,7 @@ splice       (\\[ \f\t\v]*\n)*
   }
 
   .|\n     STRING_GROW;
-  <<EOF>>   unexpected_end_of_file (token_start, "\"");
+  <<EOF>>   unexpected_eof (token_start, "\""); BEGIN INITIAL;
 }
 
   /*---------------------------------------------------------------.
@@ -394,7 +394,7 @@ splice       (\\[ \f\t\v]*\n)*
   }
 
   .|\n     STRING_GROW;
-  <<EOF>>   unexpected_end_of_file (token_start, "'");
+  <<EOF>>   unexpected_eof (token_start, "'"); BEGIN INITIAL;
 }
 
 
@@ -456,7 +456,7 @@ splice       (\\[ \f\t\v]*\n)*
 {
   "'"                  STRING_GROW; BEGIN context_state;
   address@hidden       STRING_GROW;
-  <<EOF>>              unexpected_end_of_file (token_start, "'");
+  <<EOF>>              unexpected_eof (token_start, "'"); BEGIN context_state;
 }
 
 
@@ -469,7 +469,10 @@ splice      (\\[ \f\t\v]*\n)*
 {
   "\""                 STRING_GROW; BEGIN context_state;
   address@hidden       STRING_GROW;
-  <<EOF>>              unexpected_end_of_file (token_start, "\"");
+  <<EOF>> {
+    unexpected_eof (token_start, "\"");
+    BEGIN context_state;
+  }
 }
 
 
@@ -536,7 +539,7 @@ splice       (\\[ \f\t\v]*\n)*
       }
   }
 
-  <<EOF>>  unexpected_end_of_file (scanner_cursor, "{}");
+  <<EOF>>  unexpected_eof (scanner_cursor, "{}"); BEGIN INITIAL;
 }
 
 
@@ -589,7 +592,7 @@ splice       (\\[ \f\t\v]*\n)*
   "$"("<"{tag}">")?(-?[0-9]+|"$")  handle_dollar (token_type, yytext, *loc);
   "@"(-?[0-9]+|"$")               handle_at (token_type, yytext, *loc);
 
-  <<EOF>>  unexpected_end_of_file (code_start, "}");
+  <<EOF>>  unexpected_eof (code_start, "}"); BEGIN INITIAL;
 }
 
 
@@ -607,7 +610,7 @@ splice       (\\[ \f\t\v]*\n)*
     return PROLOGUE;
   }
 
-  <<EOF>>  unexpected_end_of_file (code_start, "%}");
+  <<EOF>>  unexpected_eof (code_start, "%}"); BEGIN INITIAL;
 }
 
 
@@ -971,25 +974,15 @@ handle_syncline (char *args)
 /*------------------------------------------------------------------------.
 | 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
-unexpected_end_of_file (boundary start, char const *token_end)
+unexpected_eof (boundary start, char const *token_end)
 {
-  size_t i = strlen (token_end);
-
   location loc;
   loc.start = start;
   loc.end = scanner_cursor;
   complain_at (loc, _("missing `%s' at end of file"), 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]);
 }
 
 
--- tests/regression.at 2 Mar 2003 13:36:55 -0000       1.79
+++ tests/regression.at 18 Apr 2003 07:26:46 -0000      1.80
@@ -298,7 +298,6 @@ input.y:5.1-17: invalid directive: `%a-d
 input.y:6.1: invalid character: `%'
 input.y:6.2: invalid character: `-'
 input.y:7.1-8.0: missing `%}' at end of file
-input.y:7.1-8.0: syntax error, unexpected "%{...%}"
 ]])
 
 AT_CLEANUP




reply via email to

[Prev in Thread] Current Thread [Next in Thread]