Skip to content
Snippets Groups Projects
Commit 92dfcb65 authored by Loïc Correnson's avatar Loïc Correnson Committed by David Bühler
Browse files

[server] export more API

parent 7b77bdd2
No related branches found
No related tags found
No related merge requests found
......@@ -82,9 +82,11 @@ include $(FRAMAC_SHARE)/Makefile.dynamic
SERVER_API= \
package.mli \
jbuffer.mli \
data.mli \
request.mli \
states.mli \
main.mli \
kernel_main.mli \
kernel_ast.mli \
kernel_properties.mli
......
......@@ -243,6 +243,8 @@ struct
declare ~package ~name:"text" ~descr jdef
end
let jpretty = Jbuffer.to_json
(* -------------------------------------------------------------------------- *)
(* --- Functional API --- *)
(* -------------------------------------------------------------------------- *)
......
......@@ -87,6 +87,10 @@ module Jtext : S with type t = json
module Jmarkdown : S with type t = Markdown.text
(** All-in-one formatter. Return the JSON encoding of formatted text. *)
val jpretty : ?indent:int -> ?margin:int ->
(Format.formatter -> 'a -> unit) -> 'a -> Jtext.t
(* -------------------------------------------------------------------------- *)
(** {2 Constructors} *)
(* -------------------------------------------------------------------------- *)
......
......@@ -100,6 +100,7 @@ let bprintf buffer msg = Format.fprintf buffer.fmt msg
let formatter buffer = buffer.fmt
let contents buffer : json =
Format.pp_print_flush buffer.fmt () ;
flush buffer () ;
while buffer.stack <> [] do
pop_tag buffer ""
......@@ -112,15 +113,20 @@ let contents buffer : json =
let format ?indent ?margin msg =
let buffer = create ?indent ?margin () in
Format.kfprintf
(fun fmt -> Format.pp_print_flush fmt () ; contents buffer)
(fun _fmt -> contents buffer)
buffer.fmt msg
let to_json ?indent ?margin pp a =
let buffer = create ?indent ?margin () in
pp buffer.fmt a ;
Format.pp_print_flush buffer.fmt () ;
contents buffer
let rec is_empty (js : json) = match js with
| `Null -> true
| `List js -> List.for_all is_empty js
| `String "" -> true
| _ -> false
let rec fprintf fmt = function
| `Null -> ()
| `String text -> Format.pp_print_string fmt text
......
......@@ -55,6 +55,9 @@ val pop_tag : buffer -> Format.stag -> unit
tags. *)
val contents : buffer -> json
(** When [is_empty js] holds, the JSON is sure to be empty. *)
val is_empty : json -> bool
(** Prints back a JSON encoding into the provided formatter.
@raise Yojson.Basic.Util.Type_error in case of ill formatted buffer. *)
val fprintf : Format.formatter -> json -> unit
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment