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 (******************************************************************************)
30 (* Ferruccio Guidi <fguidi@cs.unibo.it> *)
34 (******************************************************************************)
37 (* text linearization and parsing *******************************************)
39 let rec txt_list f s = function
42 | a :: tail -> f a ^ s ^ txt_list f s tail
44 let txt_qstr s = "\"" ^ s ^ "\""
47 let module M = MathQL in
48 let txt_svar sv = "%" ^ sv in
49 let txt_rvar rv = "@" ^ rv in
50 let txt_vvar vv = "$" ^ vv in
51 let txt_ref = function
54 | M.SuperOp -> "super "
59 let rec txt_val = function
60 | M.Const [s] -> txt_qstr s
61 | M.Const l -> "{" ^ txt_list txt_qstr ", " l ^ "}"
62 | M.VVar vv -> txt_vvar vv
63 | M.Record (rv, vv) -> txt_rvar rv ^ "." ^ txt_vvar vv
64 | M.Fun (s, x) -> "fun " ^ txt_qstr s ^ " " ^ txt_val x
65 | M.Attribute (r, p, x) -> "attribute " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_val x
66 | M.RefOf x -> "refof " ^ txt_set x
67 and txt_boole = function
70 | M.Ex b x -> "ex " ^ txt_boole x
71 (* | M.Ex b x -> "ex [" ^ txt_list txt_rvar "," b ^ "] " ^ txt_boole x *)
72 | M.Not x -> "not " ^ txt_boole x
73 | M.And (x, y) -> "(" ^ txt_boole x ^ " and " ^ txt_boole y ^ ")"
74 | M.Or (x, y) -> "(" ^ txt_boole x ^ " or " ^ txt_boole y ^ ")"
75 | M.Sub (x, y) -> "(" ^ txt_val x ^ " sub " ^ txt_val y ^ ")"
76 | M.Meet (x, y) -> "(" ^ txt_val x ^ " meet " ^ txt_val y ^ ")"
77 | M.Eq (x, y) -> "(" ^ txt_val x ^ " eq " ^ txt_val y ^ ")"
78 and txt_set = function
79 | M.SVar sv -> txt_svar sv
80 | M.RVar rv -> txt_rvar rv
81 | M.Relation (r, p, x, []) -> "relation " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_set x
82 | M.Relation (r, p, x, l) -> "relation " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_set x ^ " attr " ^ txt_list txt_vvar ", " l
83 | M.Union (x, y) -> "(" ^ txt_set x ^ " union " ^ txt_set y ^ ")"
84 | M.Intersect (x, y) -> "(" ^ txt_set x ^ " intersect " ^ txt_set y ^ ")"
85 | M.Diff (x, y) -> "(" ^ txt_set x ^ " diff " ^ txt_set y ^ ")"
86 | M.LetSVar (sv, x, y) -> "let " ^ txt_svar sv ^ " be " ^ txt_set x ^ " in " ^ txt_set y
87 | M.LetVVar (vv, x, y) -> "let " ^ txt_vvar vv ^ " be " ^ txt_val x ^ " in " ^ txt_set y
88 | M.Select (rv, x, y) -> "select " ^ txt_rvar rv ^ " in " ^ txt_set x ^ " where " ^ txt_boole y
89 | M.Pattern x -> "pattern " ^ txt_val x
90 | M.Ref x -> "ref " ^ txt_val x
94 let text_of_result x sep =
95 let txt_attr = function
96 | (s, []) -> txt_qstr s
97 | (s, l) -> txt_qstr s ^ "=" ^ txt_list txt_qstr ", " l
99 let txt_group l = "{" ^ txt_list txt_attr "; " l ^ "}" in
100 let txt_res = function
101 | (s, []) -> txt_qstr s
102 | (s, l) -> txt_qstr s ^ " attr " ^ txt_list txt_group ", " l
104 let txt_set l = txt_list txt_res ("; " ^ sep) l ^ sep in
107 let query_of_text lexbuf =
108 MQueryTParser.query MQueryTLexer.query_token lexbuf
110 let result_of_text lexbuf =
111 MQueryTParser.result MQueryTLexer.result_token lexbuf
113 (* conversion functions *****************************************************)
115 type uriref = UriManager.uri * (int list)
117 let string_of_uriref (uri, fi) =
118 let module UM = UriManager in
119 let str = UM.string_of_uri uri in
120 let xp t = "#xpointer(1/" ^ string_of_int (t + 1) in
123 | [t] -> str ^ xp t ^ ")"
124 | t :: c :: _ -> str ^ xp t ^ "/" ^ string_of_int c ^ ")"