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 (******************************************************************************)
38 (* string linearization of a reference *)
40 let str_btoken = function
47 let str_ftoken = function
48 | MQFC i -> "/" ^ string_of_int i
52 let str_prot = function
56 let rec str_body = function
58 | head :: tail -> str_btoken head ^ str_body tail
61 let rec str_fi start = function
64 (if start then "#1" else "") ^ str_ftoken t ^ str_fi false l
67 let str_tref (p, b, i) =
68 str_prot p ^ ":/" ^ str_body b ^ str_frag i
71 let rec str_fi start = function
74 (if start then "#1" else "") ^ string_of_int i ^ str_fi false l
75 in UriManager.string_of_uri u ^ str_fi true i
77 (* raw HTML representation *)
79 let key s = "<font color=\"blue\">" ^ s ^ " </font>"
85 let str s = "<font color=\"red\">'" ^ s ^ "' </font>"
87 let pat s = "<font color=\"red\">\"" ^ s ^ "\" </font>"
89 let res s = "<font color=\"brown\">\"" ^ s ^ "\" </font>"
95 (* HTML representation of a query *)
97 let out_rvar s = sym s
99 let out_svar s = sep "$" ^ sym s
101 let out_tref r = pat (str_tref r)
103 let out_pat p = out_tref p
105 let out_func = function
106 | MQName -> key "name"
108 let out_str = function
110 | MQRVar s -> out_rvar s
111 | MQSVar s -> out_svar s
112 | MQFunc (f, r) -> out_func f ^ out_rvar r
113 | MQMConclusion -> key "mainconclusion"
114 | MQConclusion -> key "conclusion"
116 let rec out_bool = function
117 | MQTrue -> key "true"
118 | MQFalse -> key "false"
119 | MQIs (s, t) -> out_str s ^ key "is" ^ out_str t
120 | MQNot b -> key "not" ^ out_bool b
121 | MQAnd (b1, b2) -> sep "(" ^ out_bool b1 ^ key "and" ^ out_bool b2 ^ sep ")"
122 | MQOr (b1, b2) -> sep "(" ^ out_bool b1 ^ key "or" ^ out_bool b2 ^ sep ")"
124 let rec out_list = function
125 | MQSelect (r, l, b) ->
126 key "select" ^ out_rvar r ^ key "in" ^ out_list l ^ key "where" ^ out_bool b
127 | MQUse (l, v) -> key "use" ^ out_list l ^ key "position" ^ out_svar v
128 | MQUsedBy (l, v) -> key "usedby" ^ out_list l ^ key "position" ^ out_svar v
129 | MQPattern p -> key "pattern" ^ out_pat p
130 | MQUnion (l1, l2) -> sep "(" ^ out_list l1 ^ key "union" ^ out_list l2 ^ sep ")"
131 | MQIntersect (l1, l2) -> sep "(" ^ out_list l1 ^ key "intersect" ^ out_list l2 ^ sep ")"
133 let out_query = function
134 | MQList l -> out_list l
136 (* HTML representation of a query result *)
138 let rec out_list = function
140 | u :: l -> res u ^ nl () ^ out_list l
143 par () ^ "Result:" ^ nl () ^
145 | MQRefs l -> out_list l
147 (* Converting functions *)
150 let s = str_uref u in
151 MQueryTParser.ref MQueryTLexer.rtoken (Lexing.from_string s)
154 let lexbuf = Lexing.from_channel ch in
155 MQueryTParser.query MQueryTLexer.qtoken lexbuf