X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fcic_transformations%2Fbox.ml;h=96c55b18ae4c01c7ec991e85ec47bdb035833d3c;hb=7b78ae643999aa95b95b376fab54adb33dbed206;hp=764a491eb0d8eb2a876ae1dedcaf841f9d0aae6a;hpb=9ab5ca8acba80b19a939eea2cd87761507e7128b;p=helm.git diff --git a/helm/ocaml/cic_transformations/box.ml b/helm/ocaml/cic_transformations/box.ml index 764a491eb..96c55b18a 100644 --- a/helm/ocaml/cic_transformations/box.ml +++ b/helm/ocaml/cic_transformations/box.ml @@ -39,6 +39,8 @@ type | Ink of attr | H of attr * ('expr box) list | V of attr * ('expr box) list + | HV of attr * ('expr box) list + | HOV of attr * ('expr box) list | Object of attr * 'expr | Action of attr * ('expr box) list @@ -49,32 +51,53 @@ let skip = Space([None,"width","1em"]);; let indent t = H([],[skip;t]);; -(* MathML prefix *) +(* BoxML prefix *) let prefix = "b";; + +let tag_of_box = function + | H _ -> "h" + | V _ -> "v" + | HV _ -> "hv" + | HOV _ -> "hov" + | _ -> assert false -let rec print_box = - 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 -> [< (print_box x) ; i >]) l [<>]) - >] - | V (attr,l) -> - X.xml_nempty ~prefix "v" attr - [< (List.fold_right (fun x i -> [< (print_box x) ; i >]) l [<>]) - >] - | Object (attr,m) -> - X.xml_nempty ~prefix "obj" attr [< Mpresentation.print_mpres m >] - | Action (attr,l) -> - X.xml_nempty ~prefix "action" attr - [< (List.fold_right (fun x i -> [< (print_box x) ; i >]) l [<>]) - >] +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) + | V (attr,l) + | HV (attr,l) + | HOV (attr,l) as box -> + X.xml_nempty ~prefix (tag_of_box box) 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) + | HV (attr, l) -> HV (attr, List.map (map f) l) + | HOV (attr, l) -> HOV (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 pres = +(* +let document_of_box ~obj2xml pres = [< Xml.xml_cdata "\n" ; Xml.xml_cdata "\n"; Xml.xml_nempty ~prefix "box" @@ -84,6 +107,7 @@ let document_of_box pres = 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)