Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
reb-ddm committed Dec 11, 2024
1 parent a112d32 commit b065762
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 28 deletions.
53 changes: 33 additions & 20 deletions core/grammar/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
6 changes: 4 additions & 2 deletions core/grammar/ast.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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} *)
Expand Down
5 changes: 4 additions & 1 deletion core/grammar/cst.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 1 addition & 2 deletions core/grammar/lKappa_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion core/grammar/lKappa_compiler.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions core/term/lKappa.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "@[<h>%t%t%t%a%t@]"
Expand Down

0 comments on commit b065762

Please sign in to comment.