]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_notation/cicNotationPres.ml
snapshot
[helm.git] / helm / ocaml / cic_notation / cicNotationPres.ml
index 97659b763271be9e936a8d3240c4030a70f5fca5..790bb3785088a8b67c7dc905fcefa66919d8b4bd 100644 (file)
@@ -168,9 +168,17 @@ let render ids_to_uris =
     | None -> None
     | Some id -> (try Some (Hashtbl.find ids_to_uris id) with Not_found -> None)
   in
-  let make_href xref =
-    let uri = lookup_uri xref in
-    make_attributes [Some "helm","xref"; Some "xlink","href"] [xref;uri]
+  let make_href xref uris =
+    let xref_uri = lookup_uri xref in
+    let raw_uris = List.map UriManager.string_of_uri uris in
+    let uri =
+      match xref_uri, raw_uris with
+      | None, [] -> None
+      | Some uri, [] -> Some uri
+      | None, raw_uris -> Some (String.concat " " raw_uris)
+      | Some uri, raw_uris -> Some (String.concat " " (uri :: raw_uris))
+    in
+    make_attributes [Some "helm", "xref"; Some "xlink", "href"] [xref; uri]
   in
   let make_xref xref = make_attributes [Some "helm","xref"] [xref] in
   let make_box = function
@@ -179,38 +187,40 @@ let render ids_to_uris =
         box
     | m -> Box.Object ([], m)
   in
-  let make_hv xref children =
-    let attrs = indent_attributes @ make_href xref in
-    P.Mobject ([], Box.HV (indent_attributes, List.map make_box children))
-  in
   (* when mathonly is true no boxes should be generated, only mrows *)
-  let rec aux mathonly xref pos prec t =
+  let rec aux mathonly xref pos prec uris t =
     match t with
-    | A.AttributedTerm (`Loc _, t) -> aux mathonly xref pos prec t
-    | A.AttributedTerm (`Level (child_prec, child_assoc), t) ->
-       let t' = aux mathonly xref pos child_prec t in
-          add_parens child_prec child_assoc pos prec t'
-    | A.AttributedTerm (`IdRef xref, t) -> aux mathonly (Some xref) pos prec t
-    | A.Ident (literal, _) -> P.Mi (make_href xref, to_unicode literal)
-    | A.Num (literal, _) -> P.Mn (make_href xref, to_unicode literal)
-    | A.Symbol (literal, _) -> P.Mo (make_href xref,to_unicode literal)
-    | A.Uri (literal, _) -> P.Mi (make_href xref, to_unicode literal)
-    | A.Literal l -> aux_literal xref prec l
-    | A.Layout l -> aux_layout mathonly xref pos prec l
+    | A.AttributedTerm (attr, t) ->
+        aux_attribute mathonly xref pos prec uris t attr
+    | A.Ident (literal, _) -> P.Mi (make_href xref [], to_unicode literal)
+    | A.Num (literal, _) -> P.Mn (make_href xref [], to_unicode literal)
+    | A.Symbol (literal, _) -> P.Mo (make_href xref uris, to_unicode literal)
+    | A.Uri (literal, _) -> P.Mi (make_href xref [], to_unicode literal)
+    | A.Literal l -> aux_literal xref prec uris l
+    | A.Layout l -> aux_layout mathonly xref pos prec uris l
     | A.Magic _
     | A.Variable _ -> assert false  (* should have been instantiated *)
     | t ->
         prerr_endline (CicNotationPp.pp_term t);
         assert false
-  and aux_literal xref prec l =
-    let attrs = make_href xref in
+  and aux_attribute mathonly xref pos prec uris t =
+    function
+    | `Loc _ -> aux mathonly xref pos prec uris t
+    | `Level (child_prec, child_assoc) ->
+        let t' = aux mathonly xref pos child_prec uris t in
+        add_parens child_prec child_assoc pos prec t'
+    | `IdRef xref -> aux mathonly (Some xref) pos prec uris t
+    | `Href uris' -> aux mathonly xref pos prec uris' t
+    | _ -> assert false
+  and aux_literal xref prec uris l =
+    let attrs = make_href xref uris in
       match l with
        | `Symbol s
        | `Keyword s -> P.Mo (attrs, to_unicode s)
        | `Number s  -> P.Mn (attrs, to_unicode s)
-  and aux_layout mathonly xref pos prec l =
+  and aux_layout mathonly xref pos prec uris l =
     let attrs = make_xref xref in
-    let invoke' t = aux true None pos prec t in
+    let invoke' t = aux true None pos prec uris t in
     match l with
     | A.Sub (t1, t2) -> P.Msub (attrs, invoke' t1, invoke' t2)
     | A.Sup (t1, t2) -> P.Msup (attrs, invoke' t1, invoke' t2)
@@ -223,9 +233,9 @@ let render ids_to_uris =
     | A.Sqrt t -> P.Msqrt (attrs, invoke' t)
     | A.Root (t1, t2) -> P.Mroot (attrs, invoke' t1, invoke' t2)
     | A.Box (kind, terms) ->
-        let children = aux_children mathonly xref pos prec terms in
+        let children = aux_children mathonly xref pos prec uris terms in
           box_of mathonly kind attrs children
-  and aux_children mathonly xref pos prec terms =
+  and aux_children mathonly xref pos prec uris terms =
     let rec aux_list first =
       function
         [] -> []
@@ -238,7 +248,7 @@ let render ids_to_uris =
              | `Right -> `Right
              | `Left -> `Inner
          in
-          [aux mathonly xref pos' prec t]
+          [aux mathonly xref pos' prec uris t]
       | t :: tl ->
          let pos' =
            match pos, first with
@@ -249,13 +259,13 @@ let render ids_to_uris =
              | `Right, _ -> `Inner
              | `Inner, _ -> `Inner
          in
-            (aux mathonly xref pos' prec t) :: aux_list false tl
+            (aux mathonly xref pos' prec uris t) :: aux_list false tl
     in
       match terms with
-        [t] -> [aux mathonly xref pos prec t]
+        [t] -> [aux mathonly xref pos prec uris t]
       | tl -> aux_list true tl
   in
-    aux false None `None 0
+  aux false None `None 0 []
 
 let render_to_boxml id_to_uri t =
   let rec print_box (t: CicNotationPres.boxml_markup) =