Commit 27caa03b authored by Bruno Guillaume's avatar Bruno Guillaume

Check for duplicate node identifiers at building time

parent b9e5ea66
......@@ -161,6 +161,35 @@ module Ast = struct
pat_negs: basic list;
}
let check_duplicate_edge_identifier basic =
let ids = List_.opt_map
(function ({edge_id= Some e},loc) -> Some (e, loc) | _ -> None)
basic.pat_edges in
let rec loop = function
| [] -> ()
| (x,loc)::t when List.exists (fun (y,_) -> x=y) t ->
Error.build ~loc "The identifier '%s' is used twice" x
| _::t -> loop t in
loop ids
let normalize_pattern pattern =
check_duplicate_edge_identifier pattern.pat_pos;
{ pattern with pat_negs =
List.map
(fun pat_neg ->
{ pat_neg with pat_edges =
List.map
(fun (u_edge,loc) ->
match u_edge.edge_id with
| None -> (u_edge,loc)
| Some id ->
Log.fwarning "[%s] identifier \"%s\" is useless in without part" (Loc.to_string loc) id;
({u_edge with edge_id=None},loc)
) pat_neg.pat_edges
}
) pattern.pat_negs
}
let add_implicit_node loc aux name pat_nodes =
if (List.exists (fun ({node_id},_) -> node_id=name) pat_nodes)
|| (List.exists (fun ({node_id},_) -> node_id=name) aux)
......
......@@ -121,6 +121,10 @@ module Ast : sig
pat_negs: basic list;
}
(* [check for duplicate edge identifier in pos part and
remove edge identifier in neg part] *)
val normalize_pattern : pattern -> pattern
val complete_pattern : pattern -> pattern
type concat_item =
......
......@@ -395,8 +395,9 @@ module Rule = struct
| _ -> ()
);
let pattern = Ast.normalize_pattern rule_ast.Ast.pattern in
let (pos, pos_table) =
try build_pos_basic ?domain ~pat_vars rule_ast.Ast.pattern.Ast.pat_pos
try build_pos_basic ?domain ~pat_vars pattern.Ast.pat_pos
with P_fs.Fail_unif ->
Error.build ~loc:rule_ast.Ast.rule_loc
"[Rule.build] in rule \"%s\": feature structures declared in the \"match\" clause are inconsistent"
......@@ -409,7 +410,7 @@ module Rule = struct
Log.fwarning "In rule \"%s\" [%s], the wihtout number %d cannot be satisfied, it is skipped"
rule_ast.Ast.rule_id (Loc.to_string rule_ast.Ast.rule_loc) pos;
(acc, pos+1)
) ([],1) rule_ast.Ast.pattern.Ast.pat_negs in
) ([],1) pattern.Ast.pat_negs in
{
name = rule_ast.Ast.rule_id;
pattern = (pos, negs);
......@@ -420,14 +421,15 @@ module Rule = struct
}
let build_pattern ?domain pattern_ast =
let n_pattern = Ast.normalize_pattern pattern_ast in
let (pos, pos_table) =
try build_pos_basic ?domain pattern_ast.Ast.pat_pos
try build_pos_basic ?domain n_pattern.Ast.pat_pos
with P_fs.Fail_unif -> Error.build "feature structures declared in the \"match\" clause are inconsistent " in
let negs =
List_.try_map
P_fs.Fail_unif (* Skip the without parts that are incompatible with the match part *)
(fun basic_ast -> build_neg_basic ?domain pos_table basic_ast)
pattern_ast.Ast.pat_negs in
n_pattern.Ast.pat_negs in
(pos, negs)
(* ====================================================================== *)
......
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