]> git.saurik.com Git - bison.git/commitdiff
Improve error messages for `$' or `@' followed by `.' or `-'.
authorJoel E. Denny <joeldenny@joeldenny.org>
Sun, 9 Jan 2011 23:06:19 +0000 (18:06 -0500)
committerJoel E. Denny <joeldenny@joeldenny.org>
Sun, 9 Jan 2011 23:08:56 +0000 (18:08 -0500)
Previously, for this special case of an invalid reference, the
usual "symbol not found in production:" was printed.  However,
because the symbol name was parsed as the empty string, that
message was followed immediately by a newline instead of a symbol
name.  In reality, this is a syntax error, so the reference is
invalid regardless of the symbols actually appearing in the
production.  Discussed at
<http://lists.gnu.org/archive/html/bison-patches/2011-01/msg00012.html>.
* src/scan-code.l (parse_ref): Report the above case as a syntax
error.  Other than that, continue to handle this case like any
other invalid reference that Bison manages to parse because
"possibly meant" messages can still be helpful to the user.
* tests/named-refs.at ($ or @ followed by . or -): New test group.

ChangeLog
src/scan-code.l
tests/named-refs.at

index ac74891f8a568c01d56aefe0f72902b6b8aa9e27..1f500fdf65b942822143f62aab40c6166d2aea19 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2011-01-09  Joel E. Denny  <joeldenny@joeldenny.org>
+
+       Improve error messages for `$' or `@' followed by `.' or `-'.
+       Previously, for this special case of an invalid reference, the
+       usual "symbol not found in production:" was printed.  However,
+       because the symbol name was parsed as the empty string, that
+       message was followed immediately by a newline instead of a symbol
+       name.  In reality, this is a syntax error, so the reference is
+       invalid regardless of the symbols actually appearing in the
+       production.  Discussed at
+       <http://lists.gnu.org/archive/html/bison-patches/2011-01/msg00012.html>.
+       * src/scan-code.l (parse_ref): Report the above case as a syntax
+       error.  Other than that, continue to handle this case like any
+       other invalid reference that Bison manages to parse because
+       "possibly meant" messages can still be helpful to the user.
+       * tests/named-refs.at ($ or @ followed by . or -): New test group.
+
 2011-01-08  Joel E. Denny  <joeldenny@joeldenny.org>
 
        doc: don't use @acronym.
index ffc8b5d4173d394c3fa7fd5861da6e20a83831ac..3dd10443fa40338d6a6e8d3a708a4f71702c7b88 100644 (file)
@@ -621,7 +621,17 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
         complain_at_indent (text_loc, &indent, _("invalid reference: %s"),
                             quote (text));
         indent += SUB_INDENT;
-        if (midrule_rhs_index)
+        if (len == 0)
+          {
+            location sym_loc = text_loc;
+            sym_loc.start.column += 1;
+            sym_loc.end = sym_loc.start;
+            const char *format =
+              _("syntax error after `%c', expecting integer, letter,"
+                " `_', `[', or `$'");
+            complain_at_indent (sym_loc, &indent, format, dollar_or_at);
+          }
+        else if (midrule_rhs_index)
           {
             const char *format =
               _("symbol not found in production before $%d: %.*s");
index 7824c9bf1c335f97b4452611d540b789a5350a56..74549c6e78cc8652ce86db5e1b8e17b5df71b49f 100644 (file)
@@ -561,3 +561,32 @@ test.y:57.8-17: invalid reference: `$<aa>[sym]'
 test.y:54.1-57.21:  symbol not found in production: sym
 ]])
 AT_CLEANUP
+
+#######################################################################
+
+AT_SETUP([[$ or @ followed by . or -]])
+AT_DATA([[test.y]],
+[[
+%%
+start:
+  .field { $.field; }
+| -field { @-field; }
+| 'a'    { @.field; }
+| 'a'    { $-field; }
+;
+.field: ;
+-field: ;
+]])
+AT_BISON_CHECK([[test.y]], [[1]], [],
+[[test.y:4.12-18: invalid reference: `$.field'
+test.y:4.13:        syntax error after `$', expecting integer, letter, `_', `@<:@', or `$'
+test.y:4.3-8:       possibly meant: $[.field] at $1
+test.y:5.12-18: invalid reference: `@-field'
+test.y:5.13:        syntax error after `@', expecting integer, letter, `_', `@<:@', or `$'
+test.y:5.3-8:       possibly meant: @[-field] at $1
+test.y:6.12-18: invalid reference: `@.field'
+test.y:6.13:        syntax error after `@', expecting integer, letter, `_', `@<:@', or `$'
+test.y:7.12-18: invalid reference: `$-field'
+test.y:7.13:        syntax error after `$', expecting integer, letter, `_', `@<:@', or `$'
+]])
+AT_CLEANUP