(* Copyright (C) 2000, HELM Team. * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science * Department, University of Bologna, Italy. * * HELM is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * HELM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HELM; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, * http://cs.unibo.it/helm/. *) (******************************************************************************) (* *) (* PROJECT HELM *) (* *) (* Ferruccio Guidi *) (* 30/04/2002 *) (* *) (* *) (******************************************************************************) (* text linearization and parsing *******************************************) let rec txt_list f s = function | [] -> "" | [a] -> f a | a :: tail -> f a ^ s ^ txt_list f s tail let txt_qstr s = "\"" ^ s ^ "\"" let text_of_query x = let module M = MathQL in let txt_svar sv = "%" ^ sv in let txt_rvar rv = "@" ^ rv in let txt_vvar vv = "$" ^ vv in let txt_ref = function | M.ExactOp -> "" | M.SubOp -> "sub " | M.SuperOp -> "super " in let txt_vvar_list l = txt_list txt_vvar ", " l in let rec txt_val = function | M.Const [s] -> txt_qstr s | M.Const l -> "{" ^ txt_list txt_qstr ", " l ^ "}" | M.VVar vv -> txt_vvar vv | M.Record (rv, vv) -> txt_rvar rv ^ "." ^ txt_vvar vv | M.Fun (s, x) -> "fun " ^ txt_qstr s ^ " " ^ txt_val x | M.Attribute (r, s, x) -> "attribute " ^ txt_ref r ^ txt_qstr s ^ " " ^ txt_val x | M.RefOf x -> "refof " ^ txt_set x and txt_boole = function | M.False -> "false" | M.True -> "true" | M.Ex x -> "ex " ^ txt_boole x | M.Not x -> "not " ^ txt_boole x | M.And (x, y) -> "(" ^ txt_boole x ^ " and " ^ txt_boole y ^ ")" | M.Or (x, y) -> "(" ^ txt_boole x ^ " or " ^ txt_boole y ^ ")" | M.Sub (x, y) -> "(" ^ txt_val x ^ " sub " ^ txt_val y ^ ")" | M.Meet (x, y) -> "(" ^ txt_val x ^ " meet " ^ txt_val y ^ ")" | M.Eq (x, y) -> "(" ^ txt_val x ^ " eq " ^ txt_val y ^ ")" and txt_set = function | M.SVar sv -> txt_svar sv | M.RVar rv -> txt_rvar rv | M.Relation (r, s, x, []) -> "relation " ^ txt_ref r ^ txt_qstr s ^ " " ^ txt_set x | M.Relation (r, s, x, l) -> "relation " ^ txt_ref r ^ txt_qstr s ^ " " ^ txt_set x ^ " attr " ^ txt_vvar_list l | M.Union (x, y) -> "(" ^ txt_set x ^ " union " ^ txt_set y ^ ")" | M.Intersect (x, y) -> "(" ^ txt_set x ^ " intersect " ^ txt_set y ^ ")" | M.Diff (x, y) -> "(" ^ txt_set x ^ " diff " ^ txt_set y ^ ")" | M.LetSVar (sv, x, y) -> "let " ^ txt_svar sv ^ " be " ^ txt_set x ^ " in " ^ txt_set y | M.LetVVar (vv, x, y) -> "let " ^ txt_vvar vv ^ " be " ^ txt_val x ^ " in " ^ txt_set y | M.Select (rv, x, y) -> "select " ^ txt_rvar rv ^ " in " ^ txt_set x ^ " where " ^ txt_boole y | M.Pattern x -> "pattern " ^ txt_val x | M.Ref x -> "ref " ^ txt_val x in txt_set x let text_of_result x sep = let txt_attr = function | (s, []) -> txt_qstr s | (s, l) -> txt_qstr s ^ "=" ^ txt_list txt_qstr ", " l in let txt_group l = "{" ^ txt_list txt_attr "; " l ^ "}" in let txt_res = function | (s, []) -> txt_qstr s | (s, l) -> txt_qstr s ^ " attr " ^ txt_list txt_group ", " l in let txt_set l = txt_list txt_res ("; " ^ sep) l in txt_set x let query_of_text lexbuf = MQueryTParser.query MQueryTLexer.query_token lexbuf let result_of_text lexbuf = MQueryTParser.result MQueryTLexer.result_token lexbuf (* conversion functions *****************************************************) type uriref = UriManager.uri * (int list) let string_of_uriref (uri, fi) = let module UM = UriManager in let str = UM.string_of_uri uri in let xp t = "#xpointer(1/" ^ string_of_int (t + 1) in match fi with | [] -> str | [t] -> str ^ xp t ^ ")" | t :: c :: _ -> str ^ xp t ^ "/" ^ string_of_int c ^ ")"