Commits

camlspotter committed e144d3e

hide the printer implementation

Comments (0)

Files changed (4)

 
 type ppr = token t
 
-let box : int -> token t -> token t = 
+let box : int -> ppr -> ppr = 
   fun offset t a l -> Box (offset, t a l)
 
-let vbox : int -> token t -> token t = 
+let vbox : int -> ppr -> ppr = 
   fun offset t a l -> VBox (offset, t a l)
 
-let (++) : token t -> token t -> token t = 
+let (++) : ppr -> ppr -> ppr = 
   fun p1 p2 a l -> Seq [p1 a l; p2 a l]
 
-let cut : token t = 
+let cut : ppr = 
   fun _out_ops _out_lev -> Cut
 
-let space : token t = 
-  fun _out_pos _out_lev -> String " "
+let space : ppr = 
+  fun _out_pos _out_lev -> Space
 
-let seq : token t list -> token t
+let flush : ppr =
+  fun _out_pos _out_lev -> Flush
+
+let seq : ppr list -> ppr
   = fun ps a l -> Seq (List.map (fun p -> p a l) ps)
 
-let string : string -> token t
+let string : string -> ppr
   = fun s _out_pos _out_lev -> String s
 
-let nop : token t = fun _out_pos _out_lev -> NOP
+let nop : ppr = fun _out_pos _out_lev -> NOP
 
 let left    : 'a t -> 'a t          = fun p _a l -> p Left    l
 let right   : 'a t -> 'a t          = fun p _a l -> p Right   l
   | _ -> assert false
 
 
-let parenbox : assoc -> level -> token t -> token t = fun assoc lev t ->
+let parenbox : assoc -> level -> ppr -> ppr = fun assoc lev t ->
   need_paren assoc lev >>= function
     | true  -> string "(" ++ box 0 (reset t) ++ string ")" 
     | false -> t
 
 (** Common utilities *)
 
-let binop : assoc -> level -> op:token t -> token t -> token t -> token t =
+let binop : assoc -> level -> op:ppr -> ppr -> ppr -> ppr =
   fun assoc lev ~op:sep l r ->
     parenbox assoc lev (level lev (left l++ sep ++ right r))
 
-let list : level -> token t -> token t list -> token t = 
+let list : level -> ppr -> ppr list -> ppr = 
   fun lev sep f_elems ->
     parenbox Noassoc lev (level lev (seq (List.intersperse sep f_elems)))
 
-let prefix : level -> op:token t -> token t -> token t =
+let prefix : level -> op:ppr -> ppr -> ppr =
   fun lev ~op:pref t -> 
     let t = parenbox Right lev (pref ++ level lev (right t)) in
     (* [uminus (uminus 1)] should not be printed out neither "- - 1" or "--1",
       | `Same -> space ++ t 
       | `Weaker | `Stronger -> t
 
-let postfix : level -> op:token t -> token t -> token t =
+let postfix : level -> op:ppr -> ppr -> ppr =
   fun lev ~op:postf t -> 
     let t = parenbox Left lev (level lev (left t) ++ postf) in
     (* [uminus (uminus 1)] should not be printed out neither "- - 1" or "--1",
 (** Display machine with Format like capability *)
 
 module Token : sig
-  type t =
-    | String of string
-    | Box of int * t
-    | VBox of int * t
-    | Cut
-    | Space
-    | Flush
-    | Seq of t list
-    | NOP
-
+  type t
   val format : Format.t -> t -> unit
   val buffer : Buffer.t -> t -> unit
   val show : t -> string
 val ( ++ ) : ppr -> ppr -> ppr
 val cut : ppr
 val space : ppr
+val flush : ppr
 val seq : ppr list -> ppr
 val string : string -> ppr
 val nop : ppr

opam/treeprint.1.0.0/descr

 Small tree structure printer with operator associations and precedences.
+Treeprint is a small printer combinator library for ASTs with infix,
+prefix and postfix operators with associativity and precedence. 
+It provides abstract printing with minimum parentheses insertion.

opam/treeprint.1.0.0/opam

 remove: [
   ["ocamlfind" "remove" "treeprint"]
 ]
-depends: [ "ocamlfind" "spotlib" {>="2.0.0"} ]
+depends: [ "ocamlfind" "spotlib" {>="2.0.0"} "omake"]