2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
21 path: T.id list; (* current section path *)
22 line: int; (* line number *)
23 sort: int; (* first default sort index *)
24 mk_uri:Y.uri_generator (* uri generator *)
27 let henv_size = 7000 (* hash tables initial size *)
29 let henv = Hashtbl.create henv_size (* optimized global environment *)
31 (* Internal functions *******************************************************)
33 let initial_status mk_uri = {
34 path = []; line = 1; sort = 0; mk_uri = mk_uri
37 let name_of_id ?(r=true) id = Y.Name (id, r)
39 let mk_lref f i j k = f (D.TLRef ([Y.Apix k], i, j))
41 let mk_gref f uri = f (D.TGRef ([], uri))
43 let uri_of_id st id path =
44 let str = String.concat "/" path in
45 let str = Filename.concat str id in
46 let str = st.mk_uri str in
49 let resolve_gref err f st id =
50 try f (Hashtbl.find henv id)
51 with Not_found -> err ()
53 let rec xlate_term f st lenv = function
55 | T.Impl _ -> assert false
59 let f h = f (D.TSort ([], h)) in
60 H.sort_of_string C.err f id
62 D.get_index C.err (mk_lref f i j) i j lenv
64 let err () = resolve_gref C.err (mk_gref f) st id in
65 D.resolve_lref err (mk_lref f) id lenv
67 let f uu tt = f (D.TCast ([], uu, tt)) in
68 let f uu = xlate_term (f uu) st lenv t in
69 xlate_term f st lenv u
71 let map f = xlate_term f st lenv in
72 let f vvs tt = f (D.TAppl ([], vvs, tt)) in
73 let f vvs = xlate_term (f vvs) st lenv t in
76 let abst_map (lenv, a, wws) (id, r, w) =
77 let attr = name_of_id ~r id in
78 let ww = xlate_term C.start st lenv w in
79 D.push2 C.err C.start lenv attr ~t:ww (), attr :: a, ww :: wws
81 let abbr_map (lenv, a, wws) (id, w) =
82 let attr = name_of_id id in
83 let ww = xlate_term C.start st lenv w in
84 D.push2 C.err C.start lenv attr ~t:ww (), attr :: a, ww :: wws
86 let void_map (lenv, a, n) id =
87 let attr = name_of_id id in
88 D.push2 C.err C.start lenv attr (), attr :: a, succ n
90 let lenv, aa, bb = match b with
92 let lenv = D.push_bind C.start lenv [] (D.Abst []) in
93 let lenv, aa, wws = List.fold_left abst_map (lenv, [], []) xws in
96 let lenv = D.push_bind C.start lenv [] (D.Abbr []) in
97 let lenv, aa, vvs = List.fold_left abbr_map (lenv, [], []) xvs in
100 let lenv = D.push_bind C.start lenv [] (D.Void 0) in
101 let lenv, aa, n = List.fold_left void_map (lenv, [], 0) ids in
104 let f tt = f (D.TBind (aa, bb, tt)) in
105 xlate_term f st lenv t
107 let xlate_term f st lenv t =
108 TT.contract (xlate_term f st lenv) t
110 let mk_contents tt = function
111 | T.Decl -> [], Y.Abst tt
112 | T.Ax -> [], Y.Abst tt
113 | T.Def -> [], Y.Abbr tt
114 | T.Th -> [], Y.Abbr tt
116 let xlate_entity err f st = function
117 | T.Section (Some name) ->
118 err {st with path = name :: st.path}
120 begin match st.path with
122 err {st with path = ptl}
126 let map st (xix, s) =
127 let ix = match xix with
131 {st with sort = H.set_sorts ix [s]}
133 err (List.fold_left map st sorts)
135 assert (H.set_graph id); err st
136 | T.Entity (kind, id, meta, t) ->
137 let uri = uri_of_id st id st.path in
138 Hashtbl.add henv id uri;
139 let tt = xlate_term C.start st D.empty_lenv t in
141 print_newline (); CrgOutput.pp_term print_string tt;
143 let a, b = mk_contents tt kind in
144 let a = if meta <> "" then Y.Meta meta :: a else a in
145 let entity = Y.Mark st.line :: a, uri, b in
146 f {st with line = succ st.line} entity
148 (* Interface functions ******************************************************)
150 let initial_status mk_uri =
151 initial_status mk_uri
153 let crg_of_txt = xlate_entity