Commit 50c97c6d authored by POTTIER Francois's avatar POTTIER Francois

Check that the formal parameters of each rule have distinct names.

parent 7272355a
......@@ -193,4 +193,5 @@
* Ideally, [PartialGrammar] should avoid renaming the parameters of
a rule, when there is no need to do so. The renamed parameter is
visible in sort unification error messages.
visible in sort unification error messages and in messages about
duplicate formal parameters (test/bad/duplicate-formal.mly).
......@@ -151,7 +151,6 @@ let check_branch env (branch : parameterized_branch) =
let enter_rule env (nt : symbol) (rule : parameterized_rule) : env =
(* For each formal parameter, allocate a fresh variable. *)
(* TEMPORARY should we check that the formals have distinct names? *)
let formals, domain = allocate rule.pr_parameters in
(* Connect these variables with the sort of the symbol [nt]. *)
......
......@@ -669,10 +669,19 @@ let check_parameterized_grammar_is_well_defined grammar =
Error.error [ p ] "%s is undefined." s
in
StringMap.iter
(fun k prule -> List.iter
(fun k prule ->
(* The formal parameters of each rule must have distinct names. *)
prule.pr_parameters
|> List.sort compare
|> Misc.dup compare
|> Option.iter (fun x ->
Error.error prule.pr_positions
"several parameters of this rule are named \"%s\"." x
);
(* Check each branch. *)
(fun { pr_producers = producers;
List.iter (fun { pr_producers = producers;
pr_branch_prec_annotation;
} -> ignore (List.fold_left
......
File "duplicate-formal.mly", line 6, characters 0-3:
Error: several parameters of this rule are named "X25".
%token A
%start<unit> main
%%
foo(X,X): (* the two formal parameters have the same name *)
X A {}
main:
foo(A,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