Have separate ppf and Yojson modules for PP_json

This commit is contained in:
Suzanne Dupéron 2020-06-24 02:04:59 +01:00
parent 65161148d3
commit 018e269b2e
2 changed files with 13 additions and 3 deletions

View File

@ -76,13 +76,23 @@ module M = struct
`Assoc ["typeVariableMap", `List lst'] ); `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 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 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 include Fold.Folds(struct
type in_state = M.no_state ;; type in_state = M.no_state ;;
type out_state = json ;; type out_state = json ;;
type 'a t = 'a -> json ;; type 'a t = formatter -> 'a -> unit ;;
let f = M.print ;; let f = M.print ;;
end) end)

View File

@ -4,7 +4,7 @@ let program_ppformat ~display_format f (typed,_) =
match display_format with match display_format with
| Human_readable | Dev -> PP.program f typed | 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 = { let program_format : 'a format = {
pp = program_ppformat; pp = program_ppformat;