From 651d12df5d6e9a5ae3a0ea5b490ac5b82d2da00c Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 5 Apr 2018 23:02:57 +0800 Subject: [PATCH] Implement manual printers for Meta type --- src/meta.ml | 29 +++++++++++++++++++++++++++++ src/meta.mli | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/meta.ml b/src/meta.ml index d23bd4ae..c1553e03 100644 --- a/src/meta.ml +++ b/src/meta.ml @@ -102,12 +102,34 @@ module Parse = struct error lb "'package' or variable name expected" end +let pp_action fmt = function + | Set -> Format.pp_print_string fmt "Set" + | Add -> Format.pp_print_string fmt "Add" + +let pp_predicate fmt = function + | Pos s -> Format.fprintf fmt "%S" ("+" ^ s) + | Neg s -> Format.fprintf fmt "%S" ("-" ^ s) + +let pp_rule fmt (t : rule) = + Fmt.record fmt + [ "var", (Fmt.const Fmt.quoted t.var) + ; "predicates", (Fmt.const (Fmt.ocaml_list pp_predicate) t.predicates) + ; "action", (Fmt.const pp_action t.action) + ; "value", (Fmt.const Fmt.quoted t.value) + ] + module Simplified = struct module Rules = struct type t = { set_rules : rule list ; add_rules : rule list } + + let pp fmt t = + Fmt.record fmt + [ "set_rules", Fmt.const (Fmt.ocaml_list pp_rule) t.set_rules + ; "add_rules", Fmt.const (Fmt.ocaml_list pp_rule) t.add_rules + ] end type t = @@ -115,6 +137,13 @@ module Simplified = struct ; vars : Rules.t String_map.t ; subs : t list } + + let rec pp fmt t = + Fmt.record fmt + [ "name", Fmt.const Fmt.quoted t.name + ; "vars", Fmt.const (String_map.pp Rules.pp) t.vars + ; "subs", Fmt.const (Fmt.ocaml_list pp) t.subs + ] end let rec simplify t = diff --git a/src/meta.mli b/src/meta.mli index fe5eda8a..b609ebcb 100644 --- a/src/meta.mli +++ b/src/meta.mli @@ -38,6 +38,8 @@ module Simplified : sig ; vars : Rules.t String_map.t ; subs : t list } + + val pp : Format.formatter -> t -> unit end val load : fn:string -> name:string -> Simplified.t