]> matita.cs.unibo.it Git - helm.git/blob - helm/software/helena/src/xml/xmlCrg.ml
- simpler attribute system
[helm.git] / helm / software / helena / src / xml / xmlCrg.ml
1 (*
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.                     
5     ||I||                                                                
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_______________________________________________________________ *)
11
12 module U  = NUri
13 module C  = Cps
14 module H  = Hierarchy
15 module E  = Entity
16 module R  = Alpha
17 module XL = XmlLibrary
18 module D  = Crg
19
20 (* internal functions *******************************************************)
21
22 let lenv_iter map_bind map_appl map_proj st e lenv out tab = 
23    let rec aux = function
24       | D.ESort              -> e
25       | D.EBind (e, a, y, b) ->
26          let e = aux e in
27 (* NOTE: the inner binders are alpha-converted first *)
28          let y = R.alpha D.mem e y in
29          map_bind st e a y b out tab; D.EBind (e, a, y, b)
30       | D.EAppl (e, x, v)    ->
31          let e = aux e in
32          map_appl st e x v out tab; D.EAppl (e, x, v)
33       | D.EProj (e, d)       ->
34          let e = aux e in
35          map_proj st e d out tab; D.EProj (e, d)
36    in
37    ignore (aux lenv)
38
39 let rec exp_term st e t out tab = match t with
40    | D.TSort k         ->
41       let y =
42          let err _ = E.empty_bind in
43          let f s = E.bind_attrs ~name:(s, true) () in
44          H.string_of_sort err f k
45       in
46       let attrs = [XL.position k; XL.name y] in
47       XL.tag XL.sort attrs out tab
48    | D.TLRef (_, i)    ->
49       let y = 
50          let err _ = E.empty_bind in
51          let f s r = E.bind_attrs ~name:(s, r) () in
52          D.get_name err f i e
53       in
54       let attrs = [XL.depth i; XL.name y] in
55       XL.tag XL.lref attrs out tab
56    | D.TGRef (_, n)    ->
57       let y = E.bind_attrs ~name:(U.name_of_uri n, true) () in
58       let attrs = [XL.uri n; XL.name y] in
59       XL.tag XL.gref attrs out tab
60    | D.TCast (u, t)    ->
61       let attrs = [] in
62       XL.tag XL.cast attrs ~contents:(exp_term st e u) out tab;
63       exp_term st e t out tab
64    | D.TAppl (x, v, t) ->
65       let attrs = [] in
66       XL.tag (XL.appl x) attrs ~contents:(exp_term st e v) out tab;
67       exp_term st e t out tab
68    | D.TProj (lenv, t) ->
69       let attrs = [] in
70       XL.tag XL.proj attrs ~contents:(lenv_iter exp_bind exp_appl exp_proj st e lenv) out tab;
71       exp_term st (D.push_proj C.start lenv e) t out tab
72    | D.TBind (y, b, t) ->
73 (* NOTE: the inner binders are alpha-converted first *)
74       let y = R.alpha D.mem e y in
75       exp_bind st e E.empty_node y b out tab; 
76       exp_term st (D.push_bind C.start E.empty_node y b e) t out tab 
77
78 and exp_appl st e x v out tab =
79    let attrs = [] in
80    XL.tag (XL.appl x) attrs ~contents:(exp_term st e v) out tab;
81
82 and exp_bind st e a y b out tab = match b with
83    | D.Abst (_, n, w) ->
84       let attrs = XL.layer st n :: XL.name y :: XL.side y @ XL.main y in
85       XL.tag XL.abst attrs ~contents:(exp_term st e w) out tab
86    | D.Abbr v         ->
87       let attrs = [XL.name y] in
88       XL.tag XL.abbr attrs ~contents:(exp_term st e v) out tab
89    | D.Void           ->
90       let attrs = [XL.name y] in
91       XL.tag XL.void attrs out tab
92
93 and exp_proj st e lenv out tab =
94    let attrs = [] in
95    XL.tag XL.proj attrs ~contents:(lenv_iter exp_bind exp_appl exp_proj st e lenv) out tab
96
97 (* interface functions ******************************************************)
98
99 let export_term st = exp_term st D.empty_lenv