multistart: check duplicates

* src/symlist.h, src/symlist.c (symbol_list_find_symbol)
(symbol_list_last): New.
(symbol_list_append): Use symbol_list_last.
* src/reader.c (grammar_start_symbols_add): Check and discard duplicates.
* tests/input.at (Duplicate %start symbol): New.
* tests/reduce.at (Bad start symbols): Add the multistart keyword.
This commit is contained in:
Akim Demaille
2020-11-22 11:19:48 +01:00
parent 7fe9205b9f
commit 5b19f91ccf
6 changed files with 137 additions and 15 deletions

View File

@@ -1814,6 +1814,75 @@ AT_BISON_CHECK([-o input.c input.y])
AT_CLEANUP
## ------------------------- ##
## Duplicate %start symbol. ##
## ------------------------- ##
AT_SETUP([Duplicate %start symbol])
AT_KEYWORDS([multistart])
AT_DATA([input.y],
[[%start exp exp exp
%%
exp: %empty;
]])
AT_BISON_CHECK([-fcaret input.y], [0], [],
[[input.y:1.12-14: warning: duplicate directive [-Wother]
1 | %start exp exp exp
| ^~~
input.y:1.8-10: note: previous declaration
1 | %start exp exp exp
| ^~~
input.y:1.16-18: warning: duplicate directive [-Wother]
1 | %start exp exp exp
| ^~~
input.y:1.8-10: note: previous declaration
1 | %start exp exp exp
| ^~~
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
AT_DATA([input.y],
[[%start exp foo exp
%%
exp: foo;
foo: %empty;
]])
AT_BISON_CHECK([-fcaret input.y], [0], [],
[[input.y:1.16-18: warning: duplicate directive [-Wother]
1 | %start exp foo exp
| ^~~
input.y:1.8-10: note: previous declaration
1 | %start exp foo exp
| ^~~
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
AT_DATA([input.y],
[[%start exp foo
%start exp
%%
exp: foo;
foo: %empty;
]])
AT_BISON_CHECK([-fcaret input.y], [0], [],
[[input.y:2.8-10: warning: duplicate directive [-Wother]
2 | %start exp
| ^~~
input.y:1.8-10: note: previous declaration
1 | %start exp foo
| ^~~
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
AT_CLEANUP
## --------------------- ##
## %prec takes a token. ##
## --------------------- ##

View File

@@ -452,7 +452,7 @@ AT_CLEANUP
AT_SETUP([Bad start symbols])
m4_pushdef([AT_TEST],
[
[AT_BISON_OPTION_PUSHDEFS([$1])
AT_DATA([[input.y]],
[%%
$1
@@ -461,6 +461,7 @@ $1
AT_BISON_CHECK([[input.y]], 1, [],
[$2
])
AT_BISON_OPTION_POPDEFS([$1])
])
AT_TEST(