parser: improve the error message for symbol class redefinition

Currently our error messages include both "symbol redeclared" and
"symbol redefined", and they mean something different.  This is
obscure, let's make this clearer.

I think the idea between 'definition' vs. 'declaration' is that in the
case of the nonterminals, the actual definition is its set of rules,
so %nterm would be about declaration.  The case of %token is less
clear.

* src/symtab.c (complain_class_redefined): New.
(symbol_class_set): Use it.
Simplify the logic of this function to clearly skip its body when the
preconditions are not met.
* tests/input.at (Symbol class redefinition): New.
This commit is contained in:
Akim Demaille
2018-12-09 08:14:35 +01:00
parent afdefecab6
commit 20b0746793
3 changed files with 74 additions and 18 deletions

View File

@@ -483,6 +483,45 @@ AT_CHECK_UNUSED_VALUES([1], [1])
AT_CLEANUP
## --------------------------- ##
## Symbol class redefinition. ##
## --------------------------- ##
AT_SETUP([Symbol class redefinition])
AT_DATA([[input.y]],
[[%token FOO
%nterm FOO BAR
%token BAR
%%
FOO: BAR
BAR:
]])
AT_BISON_CHECK([-fcaret input.y], [1], [],
[[input.y:2.1-6: warning: deprecated directive, use '%type' [-Wdeprecated]
%nterm FOO BAR
^^^^^^
input.y:2.8-10: error: symbol FOO redeclared as a nonterminal
%nterm FOO BAR
^^^
input.y:1.8-10: previous definition
%token FOO
^^^
input.y:3.8-10: error: symbol BAR redeclared as a token
%token BAR
^^^
input.y:2.12-14: previous definition
%nterm FOO BAR
^^^
input.y:5.1-3: error: rule given for FOO, which is a token
FOO: BAR
^^^
]])
AT_CLEANUP
## --------------------------------------------- ##
## Default %printer and %destructor redeclared. ##
## --------------------------------------------- ##