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 (* Andrea Asperti <asperti@cs.unibo.it> *)
33 (**************************************************************************)
35 module C2P = Cexpr2pres;;
36 module P = Mpresentation;;
50 let m_open_fence = P.Mtext([], "(")
51 let b_open_fence = Box.b_text [] "("
53 let m_close_fence = P.Mtext([], ")")
54 let b_close_fence = Box.b_text [] ")"
57 let b_h_with_open_fence attrs a b op =
58 Box.b_h attrs [ b_open_fence; a; Box.b_object op; b ]
59 let b_h_without_open_fence attrs a b op =
60 Box.b_h attrs [ a; Box.b_object op; b ]
61 let b_v_with_open_fence attrs a b op =
63 Box.b_h [] [ b_open_fence; a];
64 Box.b_indent (Box.b_h [] [ Box.b_object op; b ])
66 let b_v_without_open_fence attrs a b op =
69 Box.b_indent (Box.b_h [] [ Box.b_object op; b ])
72 let m_row_with_open_fence = P.row_with_brackets
73 let m_row_without_open_fence = P.row_without_brackets
75 let m_close_fence = ")"
76 let b_close_fence = ")"
83 Content_expressions.cexpr ->
85 ~(cexpr2pres_charcount:
89 Content_expressions.cexpr ->
90 Mpresentation.mpres Box.box)
94 Hashtbl.add C2P.symbol_table "arrow" (binary
95 (fun a b ~priority ~assoc ~tail aattr sattr ->
96 if (priority > 5) || (priority = 5 && assoc) then
97 m_row_with_open_fence aattr
98 (cexpr2pres ~priority:5 ~assoc:false ~tail:[] a)
99 (cexpr2pres ~priority:5 ~assoc:true
100 ~tail:((m_close_fence)::tail) b)
101 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2192))
103 m_row_without_open_fence aattr
104 (cexpr2pres ~priority:5 ~assoc:false ~tail:[] a)
105 (cexpr2pres ~priority:5 ~assoc:true ~tail:tail b)
106 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2192))));
108 Hashtbl.add C2P.symbol_table_charcount "arrow" (binary
109 (fun a b ~priority ~assoc ~tail aattr sattr ->
110 if (priority > 40) || (priority = 40 && assoc) then
111 b_v_with_open_fence aattr
112 (cexpr2pres_charcount ~priority:40 ~assoc:false ~tail:[] a)
113 (cexpr2pres_charcount ~priority:40 ~assoc:true
114 ~tail:(b_close_fence::tail) b)
115 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2192))
117 b_v_without_open_fence aattr
118 (cexpr2pres_charcount ~priority:5 ~assoc:false ~tail:[] a)
119 (cexpr2pres_charcount ~priority:5 ~assoc:true ~tail:tail b)
120 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2192))));
123 Hashtbl.add C2P.symbol_table "eq" (binary
124 (fun a b ~priority ~assoc ~tail aattr sattr ->
125 if (priority > 40) || (priority = 40 && assoc) then
126 m_row_with_open_fence aattr
127 (cexpr2pres ~priority:40 ~assoc:true ~tail:[] a)
128 (cexpr2pres ~priority:40 ~assoc:false
129 ~tail:(m_close_fence::tail) b)
132 m_row_without_open_fence aattr
133 (cexpr2pres ~priority:40 ~assoc:true ~tail:[] a)
134 (cexpr2pres ~priority:40 ~assoc:false ~tail:tail b)
137 Hashtbl.add C2P.symbol_table_charcount "eq" (binary
138 (fun a b ~priority ~assoc ~tail aattr sattr ->
139 if (priority > 40) || (priority = 40 && assoc) then
140 b_v_with_open_fence aattr
141 (cexpr2pres_charcount ~priority:40 ~assoc:true ~tail:[] a)
142 (cexpr2pres_charcount ~priority:40 ~assoc:false
143 ~tail:(b_close_fence::tail) b)
146 b_v_without_open_fence aattr
147 (cexpr2pres_charcount ~priority:40 ~assoc:true ~tail:[] a)
148 (cexpr2pres_charcount ~priority:40 ~assoc:false ~tail:tail b)
152 Hashtbl.add C2P.symbol_table "and" (binary
153 (fun a b ~priority ~assoc ~tail aattr sattr ->
154 if (priority > 20) || (priority = 20 && assoc) then
155 m_row_with_open_fence aattr
156 (cexpr2pres ~priority:20 ~assoc:true ~tail:[] a)
157 (cexpr2pres ~priority:20 ~assoc:false
158 ~tail:(m_close_fence::tail) b)
159 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2227))
161 m_row_without_open_fence aattr
162 (cexpr2pres ~priority:20 ~assoc:true ~tail:[] a)
163 (cexpr2pres ~priority:20 ~assoc:false ~tail:tail b)
164 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2227))));
166 Hashtbl.add C2P.symbol_table_charcount "and" (binary
167 (fun a b ~priority ~assoc ~tail aattr sattr ->
168 if (priority > 20) || (priority = 20 && assoc) then
169 b_v_with_open_fence aattr
170 (cexpr2pres_charcount ~priority:20 ~assoc:true ~tail:[] a)
171 (cexpr2pres_charcount ~priority:20 ~assoc:false
172 ~tail:(b_close_fence::tail) b)
173 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2227))
175 b_v_without_open_fence aattr
176 (cexpr2pres_charcount ~priority:20 ~assoc:true ~tail:[] a)
177 (cexpr2pres_charcount ~priority:20 ~assoc:false ~tail:tail b)
178 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2227))));
181 Hashtbl.add C2P.symbol_table "or" (binary
182 (fun a b ~priority ~assoc ~tail aattr sattr ->
183 if (priority > 10) || (priority = 10 && assoc) then
184 m_row_with_open_fence aattr
185 (cexpr2pres ~priority:10 ~assoc:true ~tail:[] a)
186 (cexpr2pres ~priority:10 ~assoc:false
187 ~tail:(m_close_fence::tail) b)
188 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2228))
190 m_row_without_open_fence aattr
191 (cexpr2pres ~priority:10 ~assoc:true ~tail:[] a)
192 (cexpr2pres ~priority:10 ~assoc:false ~tail:tail b)
193 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2228))));
195 Hashtbl.add C2P.symbol_table_charcount "or" (binary
196 (fun a b ~priority ~assoc ~tail aattr sattr ->
197 if (priority > 10) || (priority = 10 && assoc) then
198 b_v_with_open_fence aattr
199 (cexpr2pres_charcount ~priority:10 ~assoc:true ~tail:[] a)
200 (cexpr2pres_charcount ~priority:10 ~assoc:false
201 ~tail:(b_close_fence::tail) b)
202 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2228))
204 b_v_without_open_fence aattr
205 (cexpr2pres_charcount ~priority:10 ~assoc:true ~tail:[] a)
206 (cexpr2pres_charcount ~priority:10 ~assoc:false ~tail:tail b)
207 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2228))));
210 Hashtbl.add C2P.symbol_table "iff" (binary
211 (fun a b ~priority ~assoc ~tail aattr sattr ->
212 if (priority > 5) || (priority = 5 && assoc) then
213 m_row_with_open_fence aattr
214 (cexpr2pres ~priority:5 ~assoc:true ~tail:[] a)
215 (cexpr2pres ~priority:5 ~assoc:false
216 ~tail:(m_close_fence::tail) b)
217 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x21D4))
219 m_row_without_open_fence aattr
220 (cexpr2pres ~priority:5 ~assoc:true ~tail:[] a)
221 (cexpr2pres ~priority:5 ~assoc:false ~tail:tail b)
222 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x21D4))));
224 Hashtbl.add C2P.symbol_table_charcount "iff" (binary
225 (fun a b ~priority ~assoc ~tail aattr sattr ->
226 if (priority > 5) || (priority = 5 && assoc) then
227 b_v_with_open_fence aattr
228 (cexpr2pres_charcount ~priority:5 ~assoc:true ~tail:[] a)
229 (cexpr2pres_charcount ~priority:5 ~assoc:false
230 ~tail:(b_close_fence::tail) b)
231 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x21D4))
233 b_v_without_open_fence aattr
234 (cexpr2pres_charcount ~priority:5 ~assoc:true ~tail:[] a)
235 (cexpr2pres_charcount ~priority:5 ~assoc:false ~tail:tail b)
236 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x21D4))));
239 Hashtbl.add C2P.symbol_table "not" (unary
240 (fun a ~priority ~assoc ~tail attr sattr ->
242 m_open_fence; P.Mo([],Netconversion.ustring_of_uchar `Enc_utf8 0xAC);
243 cexpr2pres a; P.Mtext ([], m_close_fence)])))) ;
246 Hashtbl.add C2P.symbol_table "inv" (unary
247 (fun a ~priority ~assoc ~tail attr sattr ->
252 P.Mtext ([], m_close_fence)]),
258 Hashtbl.add C2P.symbol_table "opp" (unary
259 (fun a ~priority ~assoc ~tail attr sattr ->
264 P.Mtext ([], m_close_fence)])));
267 Hashtbl.add C2P.symbol_table "leq" (binary
268 (fun a b ~priority ~assoc ~tail aattr sattr ->
269 if (priority > 40) || (priority = 40 && assoc) then
270 m_row_with_open_fence aattr
271 (cexpr2pres ~priority:40 ~assoc:true ~tail:[] a)
272 (cexpr2pres ~priority:40 ~assoc:false
273 ~tail:(m_close_fence::tail) b)
274 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2264))
276 m_row_without_open_fence aattr
277 (cexpr2pres ~priority:40 ~assoc:true ~tail:[] a)
278 (cexpr2pres ~priority:40 ~assoc:false ~tail:tail b)
279 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2264))));
281 Hashtbl.add C2P.symbol_table_charcount "leq" (binary
282 (fun a b ~priority ~assoc ~tail aattr sattr ->
283 if (priority > 40) || (priority = 40 && assoc) then
284 b_v_with_open_fence aattr
285 (cexpr2pres_charcount ~priority:40 ~assoc:true ~tail:[] a)
286 (cexpr2pres_charcount ~priority:40 ~assoc:false
287 ~tail:(b_close_fence::tail) b)
288 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2264))
290 b_v_without_open_fence aattr
291 (cexpr2pres_charcount ~priority:40 ~assoc:true ~tail:[] a)
292 (cexpr2pres_charcount ~priority:40 ~assoc:false ~tail:tail b)
293 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2264))));
296 Hashtbl.add C2P.symbol_table "lt" (binary
297 (fun a b ~priority ~assoc ~tail aattr sattr ->
298 if (priority > 40) || (priority = 40 && assoc) then
299 m_row_with_open_fence aattr
300 (cexpr2pres ~priority:40 ~assoc:true ~tail:[] a)
301 (cexpr2pres ~priority:40 ~assoc:false
302 ~tail:(m_close_fence::tail) b)
305 m_row_without_open_fence aattr
306 (cexpr2pres ~priority:40 ~assoc:true ~tail:[] a)
307 (cexpr2pres ~priority:40 ~assoc:false ~tail:tail b)
308 (P.Mo(sattr,"<"))));
310 Hashtbl.add C2P.symbol_table_charcount "lt" (binary
311 (fun a b ~priority ~assoc ~tail aattr sattr ->
312 if (priority > 40) || (priority = 40 && assoc) then
313 b_v_with_open_fence aattr
314 (cexpr2pres_charcount ~priority:40 ~assoc:true ~tail:[] a)
315 (cexpr2pres_charcount ~priority:40 ~assoc:false
316 ~tail:(b_close_fence::tail) b)
319 b_v_without_open_fence aattr
320 (cexpr2pres_charcount ~priority:40 ~assoc:true ~tail:[] a)
321 (cexpr2pres_charcount ~priority:40 ~assoc:false ~tail:tail b)
322 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2265))));
325 Hashtbl.add C2P.symbol_table "geq" (binary
326 (fun a b ~priority ~assoc ~tail aattr sattr ->
327 if (priority > 40) || (priority = 40 && assoc) then
328 m_row_with_open_fence aattr
329 (cexpr2pres ~priority:40 ~assoc:true ~tail:[] a)
330 (cexpr2pres ~priority:40 ~assoc:false
331 ~tail:(m_close_fence::tail) b)
332 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2265))
334 m_row_without_open_fence aattr
335 (cexpr2pres ~priority:40 ~assoc:true ~tail:[] a)
336 (cexpr2pres ~priority:40 ~assoc:false ~tail:tail b)
337 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2265))));
339 Hashtbl.add C2P.symbol_table_charcount "geq" (binary
340 (fun a b ~priority ~assoc ~tail aattr sattr ->
341 if (priority > 40) || (priority = 40 && assoc) then
342 b_v_with_open_fence aattr
343 (cexpr2pres_charcount ~priority:40 ~assoc:true ~tail:[] a)
344 (cexpr2pres_charcount ~priority:40 ~assoc:false
345 ~tail:(b_close_fence::tail) b)
346 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2265))
348 b_v_without_open_fence aattr
349 (cexpr2pres_charcount ~priority:40 ~assoc:true ~tail:[] a)
350 (cexpr2pres_charcount ~priority:40 ~assoc:false ~tail:tail b)
351 (P.Mo(sattr,Netconversion.ustring_of_uchar `Enc_utf8 0x2265))));
354 Hashtbl.add C2P.symbol_table "gt" (binary
355 (fun a b ~priority ~assoc ~tail aattr sattr ->
356 if (priority > 40) || (priority = 40 && assoc) then
357 m_row_with_open_fence aattr
358 (cexpr2pres ~priority:40 ~assoc:true ~tail:[] a)
359 (cexpr2pres ~priority:40 ~assoc:false
360 ~tail:(m_close_fence::tail) b)
363 m_row_without_open_fence aattr
364 (cexpr2pres ~priority:40 ~assoc:true ~tail:[] a)
365 (cexpr2pres ~priority:40 ~assoc:false ~tail:tail b)
368 Hashtbl.add C2P.symbol_table_charcount "gt" (binary
369 (fun a b ~priority ~assoc ~tail aattr sattr ->
370 if (priority > 40) || (priority = 40 && assoc) then
371 b_v_with_open_fence aattr
372 (cexpr2pres_charcount ~priority:40 ~assoc:true ~tail:[] a)
373 (cexpr2pres_charcount ~priority:40 ~assoc:false
374 ~tail:(b_close_fence::tail) b)
377 b_v_without_open_fence aattr
378 (cexpr2pres_charcount ~priority:40 ~assoc:true ~tail:[] a)
379 (cexpr2pres_charcount ~priority:40 ~assoc:false ~tail:tail b)
383 Hashtbl.add C2P.symbol_table "plus" (binary
384 (fun a b ~priority ~assoc ~tail aattr sattr ->
385 if (priority > 60) || (priority = 60 && assoc) then
386 m_row_with_open_fence aattr
387 (cexpr2pres ~priority:60 ~assoc:true ~tail:[] a)
388 (cexpr2pres ~priority:60 ~assoc:false
389 ~tail:(m_close_fence::tail) b)
392 m_row_without_open_fence aattr
393 (cexpr2pres ~priority:60 ~assoc:true ~tail:[] a)
394 (cexpr2pres ~priority:60 ~assoc:false ~tail:tail b)
397 Hashtbl.add C2P.symbol_table_charcount "plus" (binary
398 (fun a b ~priority ~assoc ~tail aattr sattr ->
399 if (priority > 60) || (priority = 60 && assoc) then
400 b_v_with_open_fence aattr
401 (cexpr2pres_charcount ~priority:60 ~assoc:true ~tail:[] a)
402 (cexpr2pres_charcount ~priority:60 ~assoc:false
403 ~tail:(b_close_fence::tail) b)
406 b_v_without_open_fence aattr
407 (cexpr2pres_charcount ~priority:60 ~assoc:true ~tail:[] a)
408 (cexpr2pres_charcount ~priority:60 ~assoc:false ~tail:tail b)
412 Hashtbl.add C2P.symbol_table "times" (binary
413 (fun a b ~priority ~assoc ~tail aattr sattr ->
414 if (priority > 70) || (priority = 70 && assoc) then
415 m_row_with_open_fence aattr
416 (cexpr2pres ~priority:70 ~assoc:true ~tail:[] a)
417 (cexpr2pres ~priority:70 ~assoc:false
418 ~tail:(m_close_fence::tail) b)
421 m_row_without_open_fence aattr
422 (cexpr2pres ~priority:70 ~assoc:true ~tail:[] a)
423 (cexpr2pres ~priority:70 ~assoc:false ~tail:tail b)
426 Hashtbl.add C2P.symbol_table_charcount "times" (binary
427 (fun a b ~priority ~assoc ~tail aattr sattr ->
428 if (priority > 70) || (priority = 70 && assoc) then
429 b_v_with_open_fence aattr
430 (cexpr2pres_charcount ~priority:70 ~assoc:true ~tail:[] a)
431 (cexpr2pres_charcount ~priority:70 ~assoc:false
432 ~tail:(b_close_fence::tail) b)
435 b_v_without_open_fence aattr
436 (cexpr2pres_charcount ~priority:70 ~assoc:true ~tail:[] a)
437 (cexpr2pres_charcount ~priority:70 ~assoc:false ~tail:tail b)
441 Hashtbl.add C2P.symbol_table "minus" (binary
442 (fun a b ~priority ~assoc ~tail aattr sattr ->
443 if (priority > 60) || (priority = 60 && assoc) then
444 m_row_with_open_fence aattr
445 (cexpr2pres ~priority:60 ~assoc:true ~tail:[] a)
446 (cexpr2pres ~priority:60 ~assoc:false
447 ~tail:(m_close_fence::tail) b)
450 m_row_without_open_fence aattr
451 (cexpr2pres ~priority:60 ~assoc:true ~tail:[] a)
452 (cexpr2pres ~priority:60 ~assoc:false ~tail:tail b)
455 Hashtbl.add C2P.symbol_table_charcount "minus" (binary
456 (fun a b ~priority ~assoc ~tail aattr sattr ->
457 if (priority > 60) || (priority = 60 && assoc) then
458 b_v_with_open_fence aattr
459 (cexpr2pres_charcount ~priority:60 ~assoc:true ~tail:[] a)
460 (cexpr2pres_charcount ~priority:60 ~assoc:false
461 ~tail:(b_close_fence::tail) b)
464 b_v_without_open_fence aattr
465 (cexpr2pres_charcount ~priority:60 ~assoc:true ~tail:[] a)
466 (cexpr2pres_charcount ~priority:60 ~assoc:false ~tail:tail b)
470 Hashtbl.add C2P.symbol_table "div" (binary
471 (fun a b ~priority ~assoc ~tail aattr sattr ->
472 if (priority > 60) || (priority = 60 && assoc) then
473 m_row_with_open_fence aattr
474 (cexpr2pres ~priority:60 ~assoc:true ~tail:[] a)
475 (cexpr2pres ~priority:60 ~assoc:false
476 ~tail:(m_close_fence::tail) b)
479 m_row_without_open_fence aattr
480 (cexpr2pres ~priority:60 ~assoc:true ~tail:[] a)
481 (cexpr2pres ~priority:60 ~assoc:false ~tail:tail b)
484 Hashtbl.add C2P.symbol_table_charcount "div" (binary
485 (fun a b ~priority ~assoc ~tail aattr sattr ->
486 if (priority > 60) || (priority = 60 && assoc) then
487 b_v_with_open_fence aattr
488 (cexpr2pres_charcount ~priority:60 ~assoc:true ~tail:[] a)
489 (cexpr2pres_charcount ~priority:60 ~assoc:false
490 ~tail:(b_close_fence::tail) b)
493 b_v_without_open_fence aattr
494 (cexpr2pres_charcount ~priority:60 ~assoc:true ~tail:[] a)
495 (cexpr2pres_charcount ~priority:60 ~assoc:false ~tail:tail b)