X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Flambda-delta%2Fcommon%2Flibrary.ml;h=91272c6f839c10bffef60ad44d47ed1334e93ec5;hb=5dcae34c6e44a40e236db641f59ddb096d1a16ec;hp=1238c273986b760d9af759a564902d6e5b18b7f7;hpb=a9f15ca61aac8089fb4b599af72533c4a432ba7b;p=helm.git diff --git a/helm/software/lambda-delta/common/library.ml b/helm/software/lambda-delta/common/library.ml index 1238c2739..91272c6f8 100644 --- a/helm/software/lambda-delta/common/library.ml +++ b/helm/software/lambda-delta/common/library.ml @@ -11,9 +11,9 @@ module F = Filename module U = NUri +module C = Cps module H = Hierarchy - -type 'a out = (unit -> 'a) -> string -> 'a +module Y = Entity (* internal functions *******************************************************) @@ -21,55 +21,106 @@ let base = "xml" let obj_ext = ".xml" +let root = "ENTITY" + let system = "http://helm.cs.unibo.it/lambda-delta/" ^ base ^ "/ld.dtd" -let path_of_uri uri = +let path_of_uri xdir uri = + let base = F.concat xdir base in F.concat base (Str.string_after (U.string_of_uri uri) 3) -let pp_head frm = - Format.fprintf frm "@,@," "1.0" "UTF-8" +(* interface functions ******************************************************) -let pp_doctype frm = - Format.fprintf frm "@,@," system +type och = string -> unit -let open_entry si g frm = - let opts = if si then "si" else "" in - let f shp = - Format.fprintf frm "" shp opts - in - H.string_of_graph f g +type attr = string * string -let close_entry frm = - Format.fprintf frm "" +type pp = och -> int -> unit -(* interface functions ******************************************************) +let attribute out (name, contents) = + if contents <> "" then begin + out " "; out name; out "=\""; out contents; out "\"" + end -let old_export_entity export_entry si g = function - | Some entry -> - let _, uri, bind = entry in - let path = path_of_uri uri in - let _ = Sys.command (Printf.sprintf "mkdir -p %s" (F.dirname path)) in - let och = open_out (path ^ obj_ext) in - let frm = Format.formatter_of_out_channel och in - Format.pp_set_margin frm max_int; - Format.fprintf frm "@[%t%t%t%a%t@]@." - pp_head pp_doctype (open_entry si g) export_entry entry close_entry; - close_out och - | None -> () - -(****************************************************************************) -(* -let export_entity export_entry si g = function - | Some entry -> - let _, uri, bind = entry in - let path = path_of_uri root uri in - let _ = Sys.command (Printf.sprintf "mkdir -p %s" (F.dirname path)) in - let och = open_out (path ^ obj_ext) in - let out f s = output_string och s; f () in - let f () = close_out och in - - Format.fprintf frm "@[%t%t%t%a%t@]@." - pp_head pp_doctype (open_entry si g) export_entry entry close_entry; - close_out och - | None -> () -*) +let xml out version encoding = + out "\n\n" + +let doctype out root system = + out "\n\n" + +let tag tag attrs ?contents out indent = + let spc = String.make indent ' ' in + out spc; out "<"; out tag; List.iter (attribute out) attrs; + match contents with + | None -> out "/>\n" + | Some cont -> + out ">\n"; cont out (indent + 3); out spc; + out "\n" + +let sort = "Sort" + +let lref = "LRef" + +let gref = "GRef" + +let cast = "Cast" + +let appl = "Appl" + +let proj = "Proj" + +let abst = "Abst" + +let abbr = "Abbr" + +let void = "Void" + +let position i = + "position", string_of_int i + +let offset j = + let contents = if j > 0 then string_of_int j else "" in + "offset", contents + +let uri u = + "uri", U.string_of_uri u + +let arity n = + let contents = if n > 1 then string_of_int n else "" in + "arity", contents + +let name a = + let map f i n r s = + let n = if r then n else "^" ^ n in + let spc = if i then "" else " " in + f (s ^ n ^ spc) + in + let f s = "name", s in + Y.names f map a "" + +let mark a = + let err () = "mark", "" in + let f i = "mark", string_of_int i in + Y.mark err f a + +let export_entity pp_term si xdir (a, u, b) = + let path = path_of_uri xdir u in + let _ = Sys.command (Printf.sprintf "mkdir -p %s" (F.dirname path)) in + let och = open_out (path ^ obj_ext) in + let out = output_string och in + xml out "1.0" "UTF-8"; doctype out root system; + let a = Y.Name (U.name_of_uri u, true) :: a in + let attrs = [uri u; name a; mark a] in + let contents = match b with + | Y.Abst w -> tag "ABST" attrs ~contents:(pp_term w) + | Y.Abbr v -> tag "ABBR" attrs ~contents:(pp_term v) + | Y.Void -> assert false + in + let opts = if si then "si" else "" in + let shp = H.string_of_graph () in + let attrs = ["hierarchy", shp; "options", opts] in + tag root attrs ~contents out 0; + close_out och