Commit a9265343 authored by Bruno Guillaume's avatar Bruno Guillaume

Remove old Try, Plus and Bang

parent c91fbd08
......@@ -349,21 +349,15 @@ module Ast = struct
type strat_def = (* /!\ The list must not be empty in the Seq or Plus constructor *)
| Ref of string (* reference to a module name or to another strategy *)
| Seq of strat_def list (* a sequence of strategies to apply one after the other *)
| Plus of strat_def list (* a set of strategies to apply in parallel *)
| Star of strat_def (* a strategy to apply iteratively *)
| Bang of strat_def (* a strategy to apply iteratively and deterministically *)
| Pick of strat_def (* pick one normal form a the given strategy; return 0 if nf *)
| Try of strat_def (* pick one normal form a the given strategy; return input if nf *)
| Sequence of string list (* compatibility mode with old code *)
let rec strat_def_to_string = function
| Ref m -> m
| Seq l -> "(" ^ (String.concat "; " (List.map strat_def_to_string l)) ^ ")"
| Plus l -> "(" ^ (String.concat "+" (List.map strat_def_to_string l)) ^ ")"
| Star s -> "(" ^ (strat_def_to_string s) ^")" ^ "*"
| Bang s -> "(" ^ (strat_def_to_string s) ^")" ^ "!"
| Pick s -> "pick" ^ "(" ^(strat_def_to_string s)^")"
| Try s -> "try" ^ "(" ^(strat_def_to_string s)^")"
| Sequence names -> "{" ^ (String.concat ";" names) ^ "}"
(* invariant: Seq list and Plus list are not empty in the input and so not empty in the output *)
......@@ -371,9 +365,7 @@ module Ast = struct
| Sequence l -> Sequence l
| Ref m -> Ref m
| Star s -> Star (strat_def_flatten s)
| Bang s -> Bang (strat_def_flatten s)
| Pick s -> Pick (strat_def_flatten s)
| Try s -> Try (strat_def_flatten s)
| Seq l ->
let fl = List.map strat_def_flatten l in
let rec loop = function
......@@ -381,13 +373,6 @@ module Ast = struct
| (Seq l) :: tail -> l @ (loop tail)
| x :: tail -> x :: (loop tail)
in Seq (loop fl)
| Plus l ->
let fl = List.map strat_def_flatten l in
let rec loop = function
| [] -> []
| (Plus l) :: tail -> l @ (loop tail)
| x :: tail -> x :: (loop tail)
in Plus (loop fl)
type strategy = {
strat_name: string;
......
......@@ -197,11 +197,8 @@ module Ast : sig
type strat_def = (* /!\ The list must not be empty in the Seq or Plus constructor *)
| Ref of string (* reference to a module name or to another strategy *)
| Seq of strat_def list (* a sequence of strategies to apply one after the other *)
| Plus of strat_def list (* a set of strategies to apply in parallel *)
| Star of strat_def (* a strategy to apply iteratively *)
| Bang of strat_def (* a strategy to apply iteratively and deterministically *)
| Pick of strat_def (* pick one normal form a the given strategy; return 0 if nf *)
| Try of strat_def (* pick one normal form a the given strategy; return input if nf *)
| Sequence of string list (* compatibility mode with old code *)
val strat_def_to_string: strat_def -> string
......
......@@ -195,11 +195,8 @@ module Grs = struct
(if not (List.exists (fun m -> name = m.Modul.name) t.modules)
then Error.build ~loc:strat.Ast.strat_loc "In sequence '%s' definition, module '%s' undefined" strat.Ast.strat_name name)
| Ast.Seq sd_list -> List.iter loop sd_list
| Ast.Plus sd_list -> List.iter loop sd_list
| Ast.Star sd -> loop sd
| Ast.Bang sd -> loop sd
| Ast.Pick sd -> loop sd
| Ast.Try sd -> loop sd
| Ast.Sequence name_list ->
List.iter (fun name ->
if not (List.exists (fun m -> name = m.Modul.name) t.modules)
......@@ -311,14 +308,6 @@ module Grs = struct
with Not_found -> Error.build "No module or strategy named '%s'" name in
Rule.conf_one_step ?domain: grs.domain inst modul.Modul.rules
end
(* Union of strategies *)
| Ast.Plus [] -> None (* the list can be empty in a recursive call! *)
| Ast.Plus (head::tail) ->
begin
match loop inst head with
| Some new_inst -> Some new_inst
| None -> loop inst (Ast.Plus tail)
end
(* Sequence of strategies *)
| Ast.Seq [] -> Log.fcritical "Empty sequence in strategy definition"
| Ast.Seq [one] -> loop inst one
......@@ -337,15 +326,6 @@ module Grs = struct
end
(* Pick *)
| Ast.Pick sub_strat -> loop inst sub_strat
(* Bang *)
| Ast.Bang sub_strat -> loop inst (Ast.Star sub_strat)
(* Try *)
| Ast.Try sub_strat ->
begin
match loop inst sub_strat with
| None -> Some inst
| Some new_inst -> Some new_inst
end
(* Old style seq definition *)
| Ast.Sequence module_list -> loop inst (new_style grs module_list) in
loop inst strat
......@@ -472,37 +452,6 @@ module Grs = struct
apply_leaf (Ast.Seq tail_strat) one_step
| Ast.Pick strat -> pick (loop instance strat)
| Ast.Try strat -> try_ (loop instance strat)
| Ast.Bang strat -> loop instance (Ast.Pick (Ast.Star strat))
(* ========> Strat defined as a sequence of sub-strategies <========= *)
| Ast.Plus [] -> Log.bug "[Grs.build_rew_display] Empty union!"; exit 2
| Ast.Plus strat_list ->
let rd_list = List.map (fun strat -> loop instance strat) strat_list in
let (opt_lnf, opt_node_info) =
List.fold_left (fun (acc_lnf, acc_node) rd ->
match (rd, acc_lnf, acc_node) with
| (Libgrew_types.Empty, acc_lnf, acc_node) -> (acc_lnf, acc_node)
| (Libgrew_types.Leaf graph, None ,_) -> (Some (graph,"0"), acc_node)
| (Libgrew_types.Leaf _,Some (graph,names) ,_) -> (Some (graph,"0+"^names), acc_node)
| (Libgrew_types.Local_normal_form (graph,name,_), None, _) -> (Some (graph,name), acc_node)
| (Libgrew_types.Local_normal_form (_,name,_), Some (graph,names), _) -> (Some (graph,name^"+"^names), acc_node)
| (Libgrew_types.Node (graph,name,bs_rd_list), _, None) -> (acc_lnf, Some (graph,name,bs_rd_list))
| (Libgrew_types.Node (_,name,bs_rd_list), _, Some (graph,acc_names,acc_bs_rd_list)) ->
(acc_lnf, Some (graph, name^"+"^acc_names,bs_rd_list @ acc_bs_rd_list))
) (None,None) rd_list in
begin
match (opt_lnf, opt_node_info) with
| (None, None) -> Libgrew_types.Empty
| (Some (graph,lnf_name), None) -> Libgrew_types.Local_normal_form (graph, lnf_name, Libgrew_types.Leaf graph)
| (None, Some (a,b,c)) -> Libgrew_types.Node (a,b,c)
| (Some (_,lnf_name), Some (graph,acc_name,acc_bs_rd_list)) ->
let bs = {Libgrew_types.first={Libgrew_types.rule_name="dummy";up=G_deco.empty;down=G_deco.empty}; small_step=[]} in
Libgrew_types.Node (graph,acc_name,(bs, Libgrew_types.Leaf graph) :: acc_bs_rd_list)
end
| Ast.Star strat ->
begin
......
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