X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=inline;f=helm%2Focaml%2Fcic_transformations%2Fbox.ml;h=386fabd0bfb65a9b4e721b8e33fe1215bfd7af15;hb=aca103d3c3d740efcc0bcc2932922cff77facb49;hp=41b7fb7259098fdc95ba031be77bda699b1514c9;hpb=ac0a12080b434bf0daafc08e9da240eb57f47280;p=helm.git diff --git a/helm/ocaml/cic_transformations/box.ml b/helm/ocaml/cic_transformations/box.ml index 41b7fb725..386fabd0b 100644 --- a/helm/ocaml/cic_transformations/box.ml +++ b/helm/ocaml/cic_transformations/box.ml @@ -36,6 +36,7 @@ type 'expr box = Text of attr * string | Space of attr + | Ink of attr | H of attr * ('expr box) list | V of attr * ('expr box) list | Object of attr * 'expr @@ -43,8 +44,66 @@ type and attr = (string option * string * string) list -let smallskip = Text([]," ");; -let skip = Text([]," ");; +let smallskip = Space([None,"width","0.5em"]);; +let skip = Space([None,"width","1em"]);; let indent t = H([],[skip;t]);; +(* BoxML prefix *) +let prefix = "b";; + +let box2xml ~obj2xml box = + let rec aux = + let module X = Xml in + function + Text (attr,s) -> X.xml_nempty ~prefix "text" attr (X.xml_cdata s) + | Space attr -> X.xml_empty ~prefix "space" attr + | Ink attr -> X.xml_empty ~prefix "ink" attr + | H (attr,l) -> + X.xml_nempty ~prefix "h" attr + [< (List.fold_right (fun x i -> [< (aux x) ; i >]) l [<>]) + >] + | V (attr,l) -> + X.xml_nempty ~prefix "v" attr + [< (List.fold_right (fun x i -> [< (aux x) ; i >]) l [<>]) + >] + | Object (attr,m) -> + X.xml_nempty ~prefix "obj" attr [< obj2xml m >] + | Action (attr,l) -> + X.xml_nempty ~prefix "action" attr + [< (List.fold_right (fun x i -> [< (aux x) ; i >]) l [<>]) >] + in + aux box +;; + +let rec map f = function + | (Text _) as box -> box + | (Space _) as box -> box + | (Ink _) as box -> box + | H (attr, l) -> H (attr, List.map (map f) l) + | V (attr, l) -> V (attr, List.map (map f) l) + | Action (attr, l) -> Action (attr, List.map (map f) l) + | Object (attr, obj) -> Object (attr, f obj) +;; + +(* +let document_of_box ~obj2xml pres = + [< Xml.xml_cdata "\n" ; + Xml.xml_cdata "\n"; + Xml.xml_nempty ~prefix "box" + [Some "xmlns","m","http://www.w3.org/1998/Math/MathML" ; + Some "xmlns","b","http://helm.cs.unibo.it/2003/BoxML" ; + Some "xmlns","helm","http://www.cs.unibo.it/helm" ; + Some "xmlns","xlink","http://www.w3.org/1999/xlink" + ] (print_box pres) + >] +*) + +let b_h a b = H(a,b) +let b_v a b = V(a,b) +let b_text a b = Text(a,b) +let b_object b = Object ([],b) +let b_indent = indent +let b_space = Space [None, "width", "0.5em"] +let b_kw = b_text [None, "color", "red"] +