bison-patches
[Top][All Lists]
Advanced

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

FYI: scan-gram.l unclosed construct error messages


From: Joel E. Denny
Subject: FYI: scan-gram.l unclosed construct error messages
Date: Mon, 14 Aug 2006 16:51:32 -0400 (EDT)

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1547
diff -p -u -r1.1547 ChangeLog
--- ChangeLog   14 Aug 2006 00:34:17 -0000      1.1547
+++ ChangeLog   14 Aug 2006 20:43:11 -0000
@@ -1,3 +1,16 @@
+2006-08-14  Joel E. Denny  <address@hidden>
+
+       In the grammar scanner, STRING_FINISH unclosed constructs and return
+       them to the parser in order to improve error messages.
+       * src/scan-gram.l (SC_ESCAPED_STRING, SC_ESCAPED_CHARACTER,
+       SC_BRACED_CODE, SC_PROLOGUE): Implement.
+       * tests/input.at (Unclosed constructs): New test case.
+       * tests/regression.at (Invalid inputs): Update now that unclosed %{ is
+       seen.
+
+       src/scan-gram.h, src/scan-gram.l: Remove unused
+       gram_last_braced_code_loc.
+
 2006-08-13  Joel E. Denny  <address@hidden>
 
        Handle string aliases for character tokens correctly.
Index: src/scan-gram.h
===================================================================
RCS file: /sources/bison/bison/src/scan-gram.h,v
retrieving revision 1.2
diff -p -u -r1.2 scan-gram.h
--- src/scan-gram.h     9 Jul 2006 19:51:48 -0000       1.2
+++ src/scan-gram.h     14 Aug 2006 20:43:12 -0000
@@ -27,7 +27,6 @@
 extern FILE *gram_in;
 extern int gram__flex_debug;
 extern char *gram_last_string;
-extern location gram_last_braced_code_loc;
 void gram_scanner_initialize (void);
 void gram_scanner_free (void);
 void gram_scanner_last_string_free (void);
Index: src/scan-gram.l
===================================================================
RCS file: /sources/bison/bison/src/scan-gram.l,v
retrieving revision 1.98
diff -p -u -r1.98 scan-gram.l
--- src/scan-gram.l     10 Aug 2006 04:53:04 -0000      1.98
+++ src/scan-gram.l     14 Aug 2006 20:43:12 -0000
@@ -66,10 +66,6 @@ gram_scanner_last_string_free (void)
   STRING_FREE;
 }
 
-/* The location of the most recently saved token, if it was a
-   BRACED_CODE token; otherwise, this has an unspecified value.  */
-location gram_last_braced_code_loc;
-
 static void handle_syncline (char *, location);
 static unsigned long int scan_integer (char const *p, int base, location loc);
 static int convert_ucn_to_byte (char const *hex_text);
@@ -340,15 +336,23 @@ splice     (\\[ \f\t\v]*\n)*
 
 <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;
   }
-  \n           unexpected_newline (token_start, "\""); BEGIN INITIAL;
-  <<EOF>>      unexpected_eof (token_start, "\"");     BEGIN INITIAL;
 }
 
   /*----------------------------------------------------------.
@@ -358,7 +362,9 @@ splice       (\\[ \f\t\v]*\n)*
 
 <SC_ESCAPED_CHARACTER>
 {
-  "'" {
+  "'"|"\n" {
+    if (yytext[0] == '\n')
+      unexpected_newline (token_start, "'");
     STRING_GROW;
     STRING_FINISH;
     loc->start = token_start;
@@ -367,8 +373,18 @@ splice      (\\[ \f\t\v]*\n)*
     BEGIN INITIAL;
     return CHAR;
   }
-  \n           unexpected_newline (token_start, "'");  BEGIN INITIAL;
-  <<EOF>>      unexpected_eof (token_start, "'");      BEGIN INITIAL;
+  <<EOF>> {
+    unexpected_eof (token_start, "'");
+    STRING_FINISH;
+    loc->start = token_start;
+    if (strlen(last_string) > 1)
+      val->character = last_string[1];
+    else
+      val->character = last_string[0];
+    STRING_FREE;
+    BEGIN INITIAL;
+    return CHAR;
+  }
 }
 
 <SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING>
@@ -505,7 +521,6 @@ splice       (\\[ \f\t\v]*\n)*
        STRING_FINISH;
        loc->start = code_start;
        val->chars = last_string;
-       gram_last_braced_code_loc = *loc;
        BEGIN INITIAL;
        return BRACED_CODE;
       }
@@ -515,7 +530,14 @@ splice      (\\[ \f\t\v]*\n)*
      (as `<' `<%').  */
   "<"{splice}"<"  STRING_GROW;
 
-  <<EOF>>  unexpected_eof (code_start, "}"); BEGIN INITIAL;
+  <<EOF>> {
+    unexpected_eof (code_start, "}");
+    STRING_FINISH;
+    loc->start = code_start;
+    val->chars = last_string;
+    BEGIN INITIAL;
+    return BRACED_CODE;
+  }
 }
 
 
@@ -533,7 +555,14 @@ splice      (\\[ \f\t\v]*\n)*
     return PROLOGUE;
   }
 
-  <<EOF>>  unexpected_eof (code_start, "%}"); BEGIN INITIAL;
+  <<EOF>> {
+    unexpected_eof (code_start, "%}");
+    STRING_FINISH;
+    loc->start = code_start;
+    val->chars = last_string;
+    BEGIN INITIAL;
+    return PROLOGUE;
+  }
 }
 
 
Index: tests/input.at
===================================================================
RCS file: /sources/bison/bison/tests/input.at,v
retrieving revision 1.52
diff -p -u -r1.52 input.at
--- tests/input.at      14 Aug 2006 00:34:17 -0000      1.52
+++ tests/input.at      14 Aug 2006 20:43:12 -0000
@@ -492,3 +492,48 @@ start: 'a';
 AT_CHECK([bison -o input.c input.y])
 
 AT_CLEANUP
+
+
+## --------------------- ##
+## Unclosed constructs.  ##
+## --------------------- ##
+
+AT_SETUP([Unclosed constructs])
+
+# Bison's scan-gram.l once forgot to STRING_FINISH some unclosed constructs, so
+# they were prepended to whatever it STRING_GROW'ed next.  It also threw them
+# away rather than returning them to the parser.  The effect was confusing
+# subsequent error messages.
+
+AT_DATA([input.y],
+[[%token A "a
+%token B "b"
+%token AB "ab" // Used to complain that "ab" was already used.
+%token C '1
+%token TWO "2"
+%token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
+
+%%
+
+start: ;
+
+// Used to report a syntax error because it didn't see any kind of symbol
+// identifier.
+%type <f> 'a
+;
+%type <f> "a
+;
+// Used to report a syntax error because it didn't see braced code.
+%destructor { free ($$)
+]])
+
+AT_CHECK([bison -o input.c input.y], 1, [],
+[[input.y:1.10-2.0: missing `"' at end of line
+input.y:4.10-5.0: missing `'' at end of line
+input.y:14.11-15.0: missing `'' at end of line
+input.y:16.11-17.0: missing `"' at end of line
+input.y:19.13-20.0: missing `}' at end of file
+input.y:20.1: syntax error, unexpected end of file, expecting ;
+]])
+
+AT_CLEANUP
Index: tests/regression.at
===================================================================
RCS file: /sources/bison/bison/tests/regression.at,v
retrieving revision 1.104
diff -p -u -r1.104 regression.at
--- tests/regression.at 9 Jul 2006 20:36:33 -0000       1.104
+++ tests/regression.at 14 Aug 2006 20:43:12 -0000
@@ -398,6 +398,7 @@ 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]