Commit 4683000f authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Better error message when a %type declaration concerns a nonexistent symbol

or a terminal symbol.
parent f7c982c8
......@@ -108,9 +108,6 @@
* bundle the Coq library with menhir, and add demos/calc-coq
to show how it is used
* BUG: la directive $type<...> nt donne lieu à un message d'erreur bizarre
si le non-terminal nt n'existe pas. (Jacques-Henri.)
* On pourrait rendre moins restrictif le critère qui garantit la terminaison
de l'expansion des non-terminaux paramétrés. Il suffirait de vérifier que
les paramètres effectifs sont toujours des atomes (symboles terminaux ou
......
......@@ -630,13 +630,13 @@ let check_parameterized_grammar_is_well_defined grammar =
let is_nonterminal = StringMap.mem head grammar.p_rules
and is_terminal = StringMap.mem head grammar.p_tokens || List.mem head reserved in
(* If [head] is not satisfactory, error. *)
if (must_be_nonterminal && not is_nonterminal) then
Error.error [Parameters.position p]
"this should be a nonterminal symbol.\n\
%s declarations are applicable only to nonterminal symbols." kind;
if not (is_terminal || is_nonterminal) then
Error.error [Parameters.position p]
"%s is undefined." head;
if (must_be_nonterminal && not is_nonterminal) then
Error.error [Parameters.position p]
"%s is a terminal symbol,\n\
but %s declarations are applicable only to nonterminal symbols." (Parameters.print p) kind;
(* Then, check the arguments. *)
List.iter (check kind false) ps
in
......
File "on-error-reduce-nonexistent.mly", line 3, characters 17-20:
Error: this should be a nonterminal symbol.
%on_error_reduce declarations are applicable only to nonterminal symbols.
Error: foo is undefined.
File "terminal-type.mly", line 2, characters 11-12:
Error: this should be a nonterminal symbol.
%type declarations are applicable only to nonterminal symbols.
Error: A is a terminal symbol,
but %type declarations are applicable only to nonterminal symbols.
File "type-of-nonexistent-symbol.mly", line 3, characters 11-14:
Error: foo is undefined.
%token A
%start<unit> main
%type<int> foo
%%
main: A {}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment