1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (* AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
33 (* low level functions *****************************************************)
35 let string_of_position p =
36 let ns = "http://www.cs.unibo.it/helm/schemas/schema-helm#" in
38 | T.MainHypothesis -> ns ^ "MainHypothesis"
39 | T.InHypothesis -> ns ^ "InHypothesis"
40 | T.MainConclusion -> ns ^ "MainConclusion"
41 | T.InConclusion -> ns ^ "InConclusion"
42 | T.InBody -> ns ^ "InBody"
44 let string_of_sort = function
50 let string_of_depth = string_of_int
52 let mathql_of_position = function
53 | T.MainHypothesis -> "$MH"
54 | T.InHypothesis -> "$IH"
55 | T.MainConclusion -> "$MC"
56 | T.InConclusion -> "$IC"
59 let mathql_of_sort = function
65 let mathql_of_depth = string_of_int
67 let mathql_of_uri u = u
69 let mathql_of_specs out l =
70 let rec iter f = function
72 | [s] -> out "\""; out (f s); out "\""
73 | s :: tail -> out "\""; out (f s); out "\", "; iter f tail
75 let txt_uri l = out "{"; iter mathql_of_uri l; out "} " in
76 let txt_pos l = out "{"; iter mathql_of_position l; out "} " in
77 let txt_sort l = out "{"; iter mathql_of_sort l; out "} " in
78 let txt_depth l = out "{"; iter mathql_of_depth l; out "} " in
79 let txt_spec = function
80 | T.MustObj (u, p, d) -> out "mustobj "; txt_uri u; txt_pos p; txt_depth d; out "\n"
81 | T.MustSort (s, p, d) -> out "mustsort "; txt_sort s; txt_pos p; txt_depth d; out "\n"
82 | T.MustRel ( p, d) -> out "mustrel "; txt_pos p; txt_depth d; out "\n"
83 | T.OnlyObj (u, p, d) -> out "onlyobj "; txt_uri u; txt_pos p; txt_depth d; out "\n"
84 | T.OnlySort (s, p, d) -> out "onlysort "; txt_sort s; txt_pos p; txt_depth d; out "\n"
85 | T.OnlyRel ( p, d) -> out "onlyrel "; txt_pos p; txt_depth d; out "\n"
86 | T.Universe ( p ) -> out "universe "; txt_pos p; out "\n"
90 let position_of_mathql = function
91 | "$MH" -> T.MainHypothesis
92 | "$IH" -> T.InHypothesis
93 | "$MC" -> T.MainConclusion
94 | "$IC" -> T.InConclusion
96 | _ -> raise Parsing.Parse_error
98 let sort_of_mathql = function
102 | "$CPROP" -> T.CProp
103 | _ -> raise Parsing.Parse_error
105 let depth_of_mathql s =
107 let d = int_of_string s in
108 if d < 0 then raise (Failure "") else d
109 with Failure _ -> raise Parsing.Parse_error
111 let uri_of_mathql s = s
113 (* high level functions ****************************************************)
115 let text_of_position = function
116 | `MainHypothesis _ -> "MainHypothesis"
117 | `MainConclusion _ -> "MainConclusion"
118 | `InHypothesis -> "InHypothesis"
119 | `InConclusion -> "InConclusion"
120 | `InBody -> "InBody"
122 let text_of_depth pos no_depth_text = match pos with
123 | `MainHypothesis (Some d)
124 | `MainConclusion (Some d) -> string_of_int d
127 let text_of_sort = function
133 let is_main_position = function
135 | `MainConclusion _ -> true
138 let is_conclusion = function
140 | `InConclusion -> true
143 let set_full_position pos depth = match pos with
144 | `MainHypothesis _ -> `MainHypothesis depth
145 | `MainConclusion _ -> `MainConclusion depth
148 let set_main_position pos depth = match pos with
149 | `MainHypothesis _ -> `MainHypothesis depth
150 | `MainConclusion _ -> `MainConclusion depth