diff --git a/core/grammar/ast.ml b/core/grammar/ast.ml index 4be17ef22..51f9f5f00 100644 --- a/core/grammar/ast.ml +++ b/core/grammar/ast.ml @@ -190,7 +190,8 @@ type ('agent, 'agent_sig, 'pattern, 'mixture, 'id, 'rule) compil = { configurations: configuration list; tokens: string Loc.annoted list; volumes: (string * float * string) list; - guard_param_values: (string Loc.annoted * bool) list; (** The guard parameters that have a defined value (true or false).*) + guard_param_values: (string Loc.annoted * bool) list; + (** The guard parameters that have a defined value (true or false).*) } type parsing_compil = (agent, agent_sig, mixture, mixture, string, rule) compil @@ -1149,7 +1150,8 @@ let print_parsing_compil_kappa f c = c.perturbations (Pp.list Pp.space print_init) c.init - (Pp.list Pp.space (fun f ((s, _), b) -> Format.fprintf f "%%guard_param: %s -> %b" s b)) + (Pp.list Pp.space (fun f ((s, _), b) -> + Format.fprintf f "%%guard_param: %s -> %b" s b)) c.guard_param_values let arrow_notation_to_yojson filenames f_mix f_var r = @@ -1583,21 +1585,21 @@ let merge_guards g1 g2 = List.sort_uniq String.compare guards let rec guard_params_from_guard = function -| LKappa.True | LKappa.False -> [] -| Param id -> [id] -| Not guard -> guard_params_from_guard guard -| And (g1, g2) | Or (g1, g2) -> - let gp1 = guard_params_from_guard g1 in - let gp2 = guard_params_from_guard g2 in - merge_guards gp1 gp2 + | LKappa.True | LKappa.False -> [] + | Param id -> [ id ] + | Not guard -> guard_params_from_guard guard + | And (g1, g2) | Or (g1, g2) -> + let gp1 = guard_params_from_guard g1 in + let gp2 = guard_params_from_guard g2 in + merge_guards gp1 gp2 let get_list_of_guard_parameters r = - List.fold_left (fun guard_params (_, guard, (_, _)) -> - match guard with - | None -> guard_params - | Some g -> - merge_guards guard_params (guard_params_from_guard g) - ) [] r + List.fold_left + (fun guard_params (_, guard, (_, _)) -> + match guard with + | None -> guard_params + | Some g -> merge_guards guard_params (guard_params_from_guard g)) + [] r let split_mixture m = List.fold_right @@ -1731,8 +1733,11 @@ let compil_to_json c = (JsonUtil.of_list (Loc.string_annoted_to_json ~filenames))) c.configurations ); ( "guard_param_values", - JsonUtil.of_list ( JsonUtil.of_pair (Loc.string_annoted_to_json ~filenames) JsonUtil.of_bool) c.guard_param_values - ); + JsonUtil.of_list + (JsonUtil.of_pair + (Loc.string_annoted_to_json ~filenames) + JsonUtil.of_bool) + c.guard_param_values ); ] let compil_of_json = function @@ -1826,9 +1831,17 @@ let compil_of_json = function guard_param_values = JsonUtil.to_list ~error_msg: - (JsonUtil.exn_msg_cant_import_from_json "AST guard_param_values sig") - (JsonUtil.to_pair ~error_msg:(JsonUtil.exn_msg_cant_import_from_json "AST guard_param_values sig") - (Loc.string_annoted_of_json ~filenames) (JsonUtil.to_bool ~error_msg:(JsonUtil.exn_msg_cant_import_from_json "AST guard_param_values boolean value"))) + (JsonUtil.exn_msg_cant_import_from_json + "AST guard_param_values sig") + (JsonUtil.to_pair + ~error_msg: + (JsonUtil.exn_msg_cant_import_from_json + "AST guard_param_values sig") + (Loc.string_annoted_of_json ~filenames) + (JsonUtil.to_bool + ~error_msg: + (JsonUtil.exn_msg_cant_import_from_json + "AST guard_param_values boolean value"))) (List.assoc "guard_param_values" l); } with Not_found -> diff --git a/core/grammar/ast.mli b/core/grammar/ast.mli index 8e83cfe04..cfa18d37d 100644 --- a/core/grammar/ast.mli +++ b/core/grammar/ast.mli @@ -185,8 +185,10 @@ val split_mixture : mixture -> mixture * mixture val infer_agent_signatures : parsing_compil -> parsing_compil (** Used when agent signatures is implicit: infer agent signatures and tokens from init, rules and perturbations *) -val get_list_of_guard_parameters : (string Loc.annoted option * string LKappa.guard option * 'rule Loc.annoted) -list -> string list +val get_list_of_guard_parameters : + (string Loc.annoted option * string LKappa.guard option * 'rule Loc.annoted) + list -> + string list (** Returns a list of all the parameters used in the guards of the rule list. *) (** {6 Printers} *) diff --git a/core/grammar/cst.ml b/core/grammar/cst.ml index 8345166ba..4f9d931c3 100644 --- a/core/grammar/cst.ml +++ b/core/grammar/cst.ml @@ -37,5 +37,8 @@ let append_to_ast_compil rev_instr compil = Ast.configurations = (param_name, value_list) :: r.Ast.configurations; } | Ast.GUARD_PARAM (params_sig, b) -> - { r with Ast.guard_param_values = (params_sig, b) :: r.Ast.guard_param_values }) + { + r with + Ast.guard_param_values = (params_sig, b) :: r.Ast.guard_param_values; + }) compil (List.rev rev_instr) diff --git a/core/grammar/lKappa_compiler.ml b/core/grammar/lKappa_compiler.ml index da4f0aeaf..92063cbd1 100644 --- a/core/grammar/lKappa_compiler.ml +++ b/core/grammar/lKappa_compiler.ml @@ -2729,8 +2729,7 @@ let compil_of_ast ~warning ~debug_mode ~syntax_version ~var_overwrite ast_compil tokens_finder alg_vars_finder ast_compil.init in - let guard_params = Ast.get_list_of_guard_parameters ast_compil.rules -in + let guard_params = Ast.get_list_of_guard_parameters ast_compil.rules in { agents_sig; diff --git a/core/grammar/lKappa_compiler.mli b/core/grammar/lKappa_compiler.mli index 93005cfa4..a26d0f803 100644 --- a/core/grammar/lKappa_compiler.mli +++ b/core/grammar/lKappa_compiler.mli @@ -48,7 +48,9 @@ type ast_compiled_data = { token_names: unit NamedDecls.t; alg_vars_finder: int Mods.StringMap.t; updated_alg_vars: int list; (** alg vars with forbidden constant prop *) - guard_params: string list; (** all guard parameters that are present in any guard in the code *) (*rTODO make it an int list*) + guard_params: string list; + (** all guard parameters that are present in any guard in the code *) + (*rTODO make it an int list*) result: ( Ast.agent, Ast.agent_sig, diff --git a/core/term/lKappa.ml b/core/term/lKappa.ml index 718f6df90..d639e2115 100644 --- a/core/term/lKappa.ml +++ b/core/term/lKappa.ml @@ -518,8 +518,7 @@ let rec print_guard f g = | 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_guard f g = - Format.fprintf f "/*if*/ %a /*then*/@ " print_guard g +let print_guard f g = Format.fprintf f "/*if*/ %a /*then*/@ " print_guard g let print_rule ~noCounters ~full sigs counters_info pr_tok pr_var f r = Format.fprintf f "@[%t%t%t%a%t@]"