diff --git a/core/grammar/eval.ml b/core/grammar/eval.ml index bac2295e5..9561405bb 100644 --- a/core/grammar/eval.ml +++ b/core/grammar/eval.ml @@ -513,6 +513,7 @@ let compile_inits ~debug_mode ~warning ?rescale ~compile_mode_on contact_map env LKappa.r_rate = Alg_expr.const Nbr.zero; LKappa.r_un_rate = None; LKappa.r_edit_style = true; + LKappa.r_guard = None; } in let preenv'', state' = @@ -544,6 +545,7 @@ let compile_inits ~debug_mode ~warning ?rescale ~compile_mode_on contact_map env LKappa.r_rate = Alg_expr.const Nbr.zero; LKappa.r_un_rate = None; LKappa.r_edit_style = false; + LKappa.r_guard = None; } in (match diff --git a/core/grammar/lKappa_compiler.ml b/core/grammar/lKappa_compiler.ml index dd88fa55a..bdb78b93d 100644 --- a/core/grammar/lKappa_compiler.ml +++ b/core/grammar/lKappa_compiler.ml @@ -1345,6 +1345,7 @@ let assemble_rule ~warning ~syntax_version (rule : rule_inter_rep) r_delta_tokens; r_rate; r_un_rate; + r_guard = rule.guard; } let modif_expr_of_ast ~warning ~syntax_version sigs counters_info tok algs diff --git a/core/symmetries/patterns_extra.ml b/core/symmetries/patterns_extra.ml index dd35b4989..b24abd3ff 100644 --- a/core/symmetries/patterns_extra.ml +++ b/core/symmetries/patterns_extra.ml @@ -573,6 +573,7 @@ let lkappa_init = LKappa.r_rate = Alg_expr.int 0; LKappa.r_un_rate = None; LKappa.r_edit_style = true; + LKappa.r_guard = None; } let raw_mixture_to_lkappa_rule raw_mixture = @@ -583,6 +584,7 @@ let raw_mixture_to_lkappa_rule raw_mixture = LKappa.r_rate = Alg_expr.int 0; LKappa.r_un_rate = None; LKappa.r_edit_style = true; + LKappa.r_guard = None; } let rule_mixture_to_lkappa_rule rule_mixture = @@ -593,6 +595,7 @@ let rule_mixture_to_lkappa_rule rule_mixture = LKappa.r_rate = Alg_expr.int 0; LKappa.r_un_rate = None; LKappa.r_edit_style = true; + LKappa.r_guard = None; } (*convert a species into lkappa rule signature*) diff --git a/core/term/lKappa.ml b/core/term/lKappa.ml index 19fe64518..37119d709 100644 --- a/core/term/lKappa.ml +++ b/core/term/lKappa.ml @@ -36,6 +36,14 @@ type rule_agent = { type rule_mixture = rule_agent list +type 'id guard = + | True + | False + | Param of 'id + | Not of 'id guard + | And of 'id guard * 'id guard + | Or of 'id guard * 'id guard + type rule = { r_mix: rule_mixture; r_created: Raw_mixture.t; @@ -46,16 +54,9 @@ type rule = { * (rule_mixture, int) Alg_expr.e Loc.annoted option) option; r_edit_style: bool; + r_guard: string guard option; } -type 'id guard = - | True - | False - | Param of 'id - | Not of 'id guard - | And of 'id guard * 'id guard - | Or of 'id guard * 'id guard - let print_link pr_port pr_type pr_annot f = function | ANY_FREE -> Format.pp_print_string f "#" | LNK_TYPE (p, a) -> Format.fprintf f "%a.%a" (pr_port a) p pr_type a @@ -508,8 +509,22 @@ let print_rates ~noCounters sigs counters_info pr_tok pr_var f r = md)) max_dist) +let rec print_guard f g = + (*rTODO test*) + match g with + | True -> Format.fprintf f "TRUE" + | False -> Format.fprintf f "FALSE" + | Param i -> Format.fprintf f "%s" i + | And (a, b) -> Format.fprintf f "@[%a && %a@]" print_guard a print_guard b + | Or (a, b) -> Format.fprintf f "@[(%a || %a)@]" print_guard a print_guard b + | Not a -> Format.fprintf f "@[[not] %a@]" print_guard a + let print_rule ~noCounters ~full sigs counters_info pr_tok pr_var f r = - Format.fprintf f "@[%t%t%a%t@]" + Format.fprintf f "@[%t%t%t%a%t@]" + (fun f -> + match r.r_guard with + | None -> () + | Some g -> print_guard f g) (fun f -> if full || r.r_edit_style then Format.fprintf f "%a%a" @@ -679,6 +694,7 @@ let rule_of_json ~filenames = function (List.assoc "unary_rate" l) with Not_found -> None); r_edit_style = Yojson.Basic.Util.to_bool (List.assoc "edit_style" l); + r_guard = None (*TODO List.assoc_opt "guard" l;*); } with Not_found -> raise (Yojson.Basic.Util.Type_error ("Incorrect rule", x))) diff --git a/core/term/lKappa.mli b/core/term/lKappa.mli index 112a44417..aea61f6f6 100644 --- a/core/term/lKappa.mli +++ b/core/term/lKappa.mli @@ -51,6 +51,14 @@ Array.copy ra_ints)]. *) type rule_mixture = rule_agent list (** [rule_mixture] is the mixture description from the initial state of a rule *) +type 'id guard = + | True + | False + | Param of 'id + | Not of 'id guard + | And of 'id guard * 'id guard + | Or of 'id guard * 'id guard + type rule = { r_mix: rule_mixture; (** Initial mixture state *) r_created: Raw_mixture.t; (** Mixture state after rule is applied *) @@ -62,16 +70,10 @@ type rule = { option; r_edit_style: bool; (** If rule was written in edit style, else it's rewrite style *) + r_guard: string guard option; + (** There could be a guard that defines if this rule is active or not. *) } -type 'id guard = - | True - | False - | Param of 'id - | Not of 'id guard - | And of 'id guard * 'id guard - | Or of 'id guard * 'id guard - val agent_to_erased : Signature.s -> rule_agent -> rule_agent val to_erased : Signature.s -> rule_mixture -> rule_mixture val to_maintained : rule_mixture -> rule_mixture @@ -132,6 +134,8 @@ val print_rates : rule -> unit +val print_guard : Format.formatter -> string guard -> unit + val print_rule : noCounters:bool -> full:bool ->