mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-12 05:43:03 +00:00
Simplify handling of '.' and '-' after unbracketed named references.
* doc/bison.texinfo (Mid-Rule Actions): Mention that periods and dashes make symbol names less convenient for named references. * src/scan-code.l: (handle_action_dollar): New arg textlen. All callers changed. (handle_action_at): Likewise. Also, args are pointers to const. (ref_tail_fields): Remove; no longer used. (letter): Now includes '-' and '.', since this is for Bison identifiers. (id): Now the simpler traditional defn, since letters now include '-' and '.'. (c_letter, c_id): New defns. (ref): Use c_id for unbracketed IDs. (<SC_RULE_ACTION>): Simplify, now that the distinction between Bison and unbracketed IDs are now in the regular expressions. (VARIANT_BAD_BRACKETING): Remove. (VARIANT_NOT_VISIBLE_FROM_MIDRULE): Renumber. (find_prefix_end): Remove, replacing with .... (identifier_matches): New function. (variant_add): Use it. Omit EXPLICIT_BRACKETING arg; no longer needed. CP arg is pointer to constant. All callers changed. (show_sub_messages): Remove args CP, EXPLICIT_BRACKETING, DOLLAR_OR_AT. New arg TEXT. All callers changed. Do not worry about showing trailing context. (parse_ref): Args CP, RULE, TEXT are now pointers to const. New arg TEXTLEN. Remove arg DOLLAR_OR_AT. All callers changed. Simplify code now that the regular expressions capture the restrictions. * src/scan-gram.l (letter, id): Adjust to match scan-code.l. * src/symlist.c (symbol_list_null): Arg is now pointer to const. * src/symlist.h: Likewise. * tests/named-refs.at (Misleading references): These are now caught by the C compiler, not by Bison; that's good enough. Adjust test to reflect this. (Many kinds of errors, Unresolved references): Adjust expected diagnostics to match new behavior. The same errors are caught, though the diagnostics are not quite as fancy. ($ or @ followed by . or -): Likewise. Also, Make the grammar unambiguous, so that diagnostics are not complicated by ambiguity warnings.
This commit is contained in:
@@ -279,11 +279,9 @@ start: foo foo.bar { $foo.bar; }
|
||||
foo: '1'
|
||||
foo.bar: '2'
|
||||
]])
|
||||
AT_BISON_CHECK([-o test.c test.y], 0, [],
|
||||
[[test.y:11.22-29: warning: misleading reference: `$foo.bar'
|
||||
test.y:11.8-10: warning: refers to: $foo at $1
|
||||
test.y:11.12-18: warning: possibly meant: $[foo.bar] at $2
|
||||
]])
|
||||
AT_BISON_CHECK([-o test.c test.y])
|
||||
AT_CHECK([if $CC $CFLAGS $CPPFLAGS test.c; then false; else true; fi],
|
||||
[0], [ignore], [ignore])
|
||||
AT_CLEANUP
|
||||
|
||||
#######################################################################
|
||||
@@ -358,43 +356,33 @@ factor: '(' expr ')' { $$ = $2; }
|
||||
AT_BISON_CHECK([-o test.c test.y], 1, [],
|
||||
[[test.y:24.36-41: invalid reference: `$cond1'
|
||||
test.y:23.11-24.62: symbol not found in production: cond1
|
||||
test.y:26.43-53: invalid reference: `$stmt.field'
|
||||
test.y:26.43-47: invalid reference: `$stmt'
|
||||
test.y:25.11-26.60: symbol not found in production: stmt
|
||||
test.y:25.35-38: possibly meant: $then.field, hiding $stmt.field at $4
|
||||
test.y:28.43-52: invalid reference: `$stmt.list'
|
||||
test.y:25.35-38: possibly meant: $then, hiding $stmt at $4
|
||||
test.y:28.43-47: invalid reference: `$stmt'
|
||||
test.y:27.11-28.59: symbol not found in production: stmt
|
||||
test.y:27.30-38: possibly meant: $[stmt.list] at $4
|
||||
test.y:30.43-46: ambiguous reference: `$xyz'
|
||||
test.y:29.35-37: refers to: $xyz at $4
|
||||
test.y:29.50-52: refers to: $xyz at $6
|
||||
test.y:32.43-52: invalid reference: `$stmt.list'
|
||||
test.y:32.43-47: invalid reference: `$stmt'
|
||||
test.y:31.11-32.63: symbol not found in production: stmt
|
||||
test.y:31.40-43: possibly meant: $then, hiding $[stmt.list] at $4
|
||||
test.y:31.61-64: possibly meant: $else, hiding $[stmt.list] at $6
|
||||
test.y:34.43-58: invalid reference: `$stmt.list.field'
|
||||
test.y:34.43-47: invalid reference: `$stmt'
|
||||
test.y:33.11-34.69: symbol not found in production: stmt
|
||||
test.y:33.40-43: possibly meant: $then.field, hiding $[stmt.list].field at $4
|
||||
test.y:33.61-64: possibly meant: $else.field, hiding $[stmt.list].field at $6
|
||||
test.y:36.43-54: invalid reference: `$[stmt.list]'
|
||||
test.y:35.11-36.71: symbol not found in production: stmt.list
|
||||
test.y:35.40-43: possibly meant: $then, hiding $[stmt.list] at $4
|
||||
test.y:35.61-64: possibly meant: $else, hiding $[stmt.list] at $6
|
||||
test.y:38.43-49: invalid reference: `$then.1'
|
||||
test.y:38.43-47: invalid reference: `$then'
|
||||
test.y:37.11-38.60: symbol not found in production: then
|
||||
test.y:37.40-45: possibly meant: $[then.1] at $4
|
||||
test.y:40.43-55: invalid reference: `$then.1.field'
|
||||
test.y:40.43-47: invalid reference: `$then'
|
||||
test.y:39.11-40.66: symbol not found in production: then
|
||||
test.y:39.40-45: possibly meant: $[then.1].field at $4
|
||||
test.y:42.44-50: invalid reference: `$stmt.x'
|
||||
test.y:42.44-48: invalid reference: `$stmt'
|
||||
test.y:41.12-42.57: symbol not found in production: stmt
|
||||
test.y:41.36-41: possibly meant: $[stmt.x].x, hiding $stmt.x at $4
|
||||
test.y:41.36-41: possibly meant: $[stmt.x] at $4
|
||||
test.y:44.13-22: invalid reference: `$if-stmt-a'
|
||||
test.y:41.36-41: possibly meant: $[stmt.x], hiding $stmt at $4
|
||||
test.y:44.13-15: invalid reference: `$if'
|
||||
test.y:43.12-44.59: symbol not found in production: if
|
||||
test.y:43.1-9: possibly meant: $[if-stmt-a] at $$
|
||||
test.y:46.46-54: invalid reference: `$then-a.f'
|
||||
test.y:46.46-50: invalid reference: `$then'
|
||||
test.y:45.12-46.65: symbol not found in production: then
|
||||
test.y:45.41-46: possibly meant: $[then-a].f at $4
|
||||
]])
|
||||
AT_CLEANUP
|
||||
|
||||
@@ -527,9 +515,9 @@ sym_a : 'a';
|
||||
sym_b : 'b';
|
||||
]])
|
||||
AT_BISON_CHECK([-o test.c test.y], 1, [],
|
||||
[[test.y:13.8-17: invalid reference: `$sym.field'
|
||||
[[test.y:13.8-11: invalid reference: `$sym'
|
||||
test.y:12.1-13.21: symbol not found in production: sym
|
||||
test.y:16.8-21: invalid reference: `$<aa>sym.field'
|
||||
test.y:16.8-15: invalid reference: `$<aa>sym'
|
||||
test.y:15.1-16.25: symbol not found in production: sym
|
||||
test.y:19.8-19: invalid reference: `$[sym.field]'
|
||||
test.y:18.1-19.23: symbol not found in production: sym.field
|
||||
@@ -543,9 +531,9 @@ test.y:31.8-13: invalid reference: `$[sym]'
|
||||
test.y:30.1-33.21: symbol not found in production before $3: sym
|
||||
test.y:33.8-17: invalid reference: `$<aa>[sym]'
|
||||
test.y:30.1-33.21: symbol not found in production: sym
|
||||
test.y:37.8-17: invalid reference: `$sym-field'
|
||||
test.y:37.8-11: invalid reference: `$sym'
|
||||
test.y:36.1-37.21: symbol not found in production: sym
|
||||
test.y:40.8-21: invalid reference: `$<aa>sym-field'
|
||||
test.y:40.8-15: invalid reference: `$<aa>sym'
|
||||
test.y:39.1-40.25: symbol not found in production: sym
|
||||
test.y:43.8-19: invalid reference: `$[sym-field]'
|
||||
test.y:42.1-43.23: symbol not found in production: sym-field
|
||||
@@ -572,21 +560,15 @@ start:
|
||||
.field { $.field; }
|
||||
| -field { @-field; }
|
||||
| 'a' { @.field; }
|
||||
| 'a' { $-field; }
|
||||
| 'b' { $-field; }
|
||||
;
|
||||
.field: ;
|
||||
-field: ;
|
||||
.field: 'c' ;
|
||||
-field: 'd' ;
|
||||
]])
|
||||
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_BISON_CHECK([[test.y]], [], [],
|
||||
[[test.y:4.12: warning: stray `$'
|
||||
test.y:5.12: warning: stray `@'
|
||||
test.y:6.12: warning: stray `@'
|
||||
test.y:7.12: warning: stray `$'
|
||||
]])
|
||||
AT_CLEANUP
|
||||
|
||||
Reference in New Issue
Block a user