diff --git a/CHANGES.md b/CHANGES.md index 3667d313..40d3e8f3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ - Removed `yojson-biniou` library - Removed deprecated `json` type aliasing type `t` which has been available since 1.6.0 (@Leonidas-from-XIV, #100). +- Removed `json_max` type (@Leonidas-from-XIV, #103) - Removed constraint that the "root" value being rendered (via either `pretty_print` or `to_string`) must be an object or array. (@cemerick, #121) diff --git a/lib/pretty.ml b/lib/pretty.ml index d3d4f405..3c4019fc 100644 --- a/lib/pretty.ml +++ b/lib/pretty.ml @@ -3,26 +3,39 @@ let pp_list sep ppx out l = let pp_sep out () = Format.fprintf out "%s@ " sep in Format.pp_print_list ~pp_sep ppx out l -let rec format std (out:Format.formatter) (x : t) : unit = +let rec format std (out:Format.formatter) (x:t) : unit = match x with | `Null -> Format.pp_print_string out "null" | `Bool x -> Format.pp_print_bool out x +#ifdef INT | `Int x -> Format.pp_print_string out (json_string_of_int x) +#endif +#ifdef FLOAT | `Float x -> let s = if std then std_json_string_of_float x else json_string_of_float x in Format.pp_print_string out s +#endif +#ifdef STRING | `String s -> Format.pp_print_string out (json_string_of_string s) - | `Intlit s - | `Floatlit s +#endif +#ifdef INTLIT + | `Intlit s -> Format.pp_print_string out s +#endif +#ifdef FLOATLIT + | `Floatlit s -> Format.pp_print_string out s +#endif +#ifdef STRINGLIT | `Stringlit s -> Format.pp_print_string out s +#endif | `List [] -> Format.pp_print_string out "[]" | `List l -> Format.fprintf out "[@;<1 0>@[%a@]@;<1 -2>]" (pp_list "," (format std)) l | `Assoc [] -> Format.pp_print_string out "{}" | `Assoc l -> Format.fprintf out "{@;<1 0>%a@;<1 -2>}" (pp_list "," (format_field std)) l +#ifdef TUPLE | `Tuple l -> if std then format std out (`List l) @@ -31,19 +44,31 @@ let rec format std (out:Format.formatter) (x : t) : unit = Format.pp_print_string out "()" else Format.fprintf out "(@,%a@;<0 -2>)" (pp_list "," (format std)) l - +#endif +#ifdef VARIANT | `Variant (s, None) -> if std then - format std out (`String s) +#ifdef STRING + let representation = `String s in +#elif defined STRINGLIT + let representation = `Stringlit s in +#endif + format std out representation else Format.fprintf out "<%s>" (json_string_of_string s) | `Variant (s, Some x) -> if std then - format std out (`List [ `String s; x ]) +#ifdef STRING + let representation = `String s in +#elif defined STRINGLIT + let representation = `Stringlit s in +#endif + format std out (`List [ representation; x ]) else let op = json_string_of_string s in Format.fprintf out "<@[%s: %a@]>" op (format std) x +#endif and format_field std out (name, x) = Format.fprintf out "@[%s: %a@]" (json_string_of_string name) (format std) x diff --git a/lib/write2.ml b/lib/write2.ml index 3fda5644..09062112 100644 --- a/lib/write2.ml +++ b/lib/write2.ml @@ -1,9 +1,9 @@ -let pretty_print ?std out (x : t) = - Pretty.pp ?std out (x :> json_max) +let pretty_print ?std out x = + Pretty.pp ?std out x -let pretty_to_string ?std (x : t) = - Pretty.to_string ?std (x :> json_max) +let pretty_to_string ?std x = + Pretty.to_string ?std x -let pretty_to_channel ?std oc (x : t) = - Pretty.to_channel ?std oc (x :> json_max) +let pretty_to_channel ?std oc x = + Pretty.to_channel ?std oc x diff --git a/lib/yojson.cppo.ml b/lib/yojson.cppo.ml index 218940b7..3805b3ba 100644 --- a/lib/yojson.cppo.ml +++ b/lib/yojson.cppo.ml @@ -9,7 +9,6 @@ #define TUPLE #define VARIANT #include "type.ml" -type json_max = t #include "write.ml" #include "monomorphic.ml" module Pretty = @@ -33,6 +32,10 @@ struct #define STRING #include "type.ml" #include "write.ml" +module Pretty = +struct +#include "pretty.ml" +end #include "monomorphic.ml" #include "write2.ml" #include "read.ml" @@ -56,6 +59,10 @@ struct #include "type.ml" #include "safe.ml" #include "write.ml" +module Pretty = +struct +#include "pretty.ml" +end #include "monomorphic.ml" #include "write2.ml" #include "read.ml" @@ -80,6 +87,10 @@ struct #define VARIANT #include "type.ml" #include "write.ml" +module Pretty = +struct +#include "pretty.ml" +end #include "monomorphic.ml" #include "write2.ml" #include "read.ml" diff --git a/lib/yojson.cppo.mli b/lib/yojson.cppo.mli index 2b5c44fa..f3452294 100644 --- a/lib/yojson.cppo.mli +++ b/lib/yojson.cppo.mli @@ -132,7 +132,6 @@ end #define VARIANT #include "type.ml" #include "monomorphic.mli" -type json_max = t #include "write.mli" #include "write2.mli" #undef INT