From 018e269b2ebcdd05f8e9b3a685cd8aae561a8cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzanne=20Dup=C3=A9ron?= Date: Wed, 24 Jun 2020 02:04:59 +0100 Subject: [PATCH] Have separate ppf and Yojson modules for PP_json --- src/stages/5-ast_typed/PP_json.ml | 14 ++++++++++++-- src/stages/5-ast_typed/formatter.ml | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/stages/5-ast_typed/PP_json.ml b/src/stages/5-ast_typed/PP_json.ml index 745483ebc..d700c65b3 100644 --- a/src/stages/5-ast_typed/PP_json.ml +++ b/src/stages/5-ast_typed/PP_json.ml @@ -76,13 +76,23 @@ module M = struct `Assoc ["typeVariableMap", `List lst'] ); } - let print : ((no_state, json) fold_config -> no_state -> 'a -> json) -> 'a -> json = fun fold v -> + let to_json : ((no_state, json) fold_config -> no_state -> 'a -> json) -> 'a -> json = fun fold v -> fold to_json NoState v + + let print : ((no_state, json) fold_config -> no_state -> 'a -> json) -> formatter -> 'a -> unit = fun fold ppf v -> + fprintf ppf "%a" Yojson.Basic.pp (to_json fold v) end +module Yojson = Fold.Folds(struct + type in_state = M.no_state ;; + type out_state = json ;; + type 'a t = 'a -> json ;; + let f = M.to_json ;; +end) + include Fold.Folds(struct type in_state = M.no_state ;; type out_state = json ;; - type 'a t = 'a -> json ;; + type 'a t = formatter -> 'a -> unit ;; let f = M.print ;; end) diff --git a/src/stages/5-ast_typed/formatter.ml b/src/stages/5-ast_typed/formatter.ml index f6c331722..e42269786 100644 --- a/src/stages/5-ast_typed/formatter.ml +++ b/src/stages/5-ast_typed/formatter.ml @@ -4,7 +4,7 @@ let program_ppformat ~display_format f (typed,_) = match display_format with | Human_readable | Dev -> PP.program f typed -let program_jsonformat (typed,_) : json = PP_json.program typed +let program_jsonformat (typed,_) : json = PP_json.Yojson.program typed let program_format : 'a format = { pp = program_ppformat;