From: Ferruccio Guidi Date: Tue, 28 May 2002 17:48:08 +0000 (+0000) Subject: new MathQL syntax X-Git-Tag: V_0_3_0_debian_8~67 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=1cfcea66d7394a785ec439cd6b03497b276918c4;p=helm.git new MathQL syntax --- diff --git a/helm/ocaml/mathql_interpreter/.depend b/helm/ocaml/mathql_interpreter/.depend index 75754ac27..7ee73d95c 100644 --- a/helm/ocaml/mathql_interpreter/.depend +++ b/helm/ocaml/mathql_interpreter/.depend @@ -1,28 +1,22 @@ -eval.cmi: mathql.cmo -func.cmi: mathql.cmo -sortedby.cmi: mathql.cmo -select.cmi: mathql.cmo mathql_semantics.cmo +select.cmi: mathql_semantics.cmo intersect.cmi: mathql_semantics.cmo union.cmi: mathql_semantics.cmo -pattern.cmi: mathql.cmo mathql_semantics.cmo -use.cmi: mathql.cmo mathql_semantics.cmo -mqint.cmi: mathql.cmo -mathql_semantics.cmo: mathql.cmo -mathql_semantics.cmx: mathql.cmx -dbconn.cmo: mathql.cmo dbconn.cmi -dbconn.cmx: mathql.cmx dbconn.cmi -eval.cmo: mathql.cmo eval.cmi -eval.cmx: mathql.cmx eval.cmi +pattern.cmi: mathql_semantics.cmo +use.cmi: mathql_semantics.cmo +dbconn.cmo: dbconn.cmi +dbconn.cmx: dbconn.cmi +eval.cmo: eval.cmi +eval.cmx: eval.cmi utility.cmo: dbconn.cmi utility.cmi utility.cmx: dbconn.cmx utility.cmi -func.cmo: dbconn.cmi mathql.cmo utility.cmi func.cmi -func.cmx: dbconn.cmx mathql.cmx utility.cmx func.cmi +func.cmo: dbconn.cmi utility.cmi func.cmi +func.cmx: dbconn.cmx utility.cmx func.cmi diff.cmo: diff.cmi diff.cmx: diff.cmi -sortedby.cmo: func.cmi mathql.cmo utility.cmi sortedby.cmi -sortedby.cmx: func.cmx mathql.cmx utility.cmx sortedby.cmi -select.cmo: func.cmi mathql.cmo mathql_semantics.cmo utility.cmi select.cmi -select.cmx: func.cmx mathql.cmx mathql_semantics.cmx utility.cmx select.cmi +sortedby.cmo: func.cmi utility.cmi sortedby.cmi +sortedby.cmx: func.cmx utility.cmx sortedby.cmi +select.cmo: func.cmi mathql_semantics.cmo utility.cmi select.cmi +select.cmx: func.cmx mathql_semantics.cmx utility.cmx select.cmi intersect.cmo: mathql_semantics.cmo intersect.cmi intersect.cmx: mathql_semantics.cmx intersect.cmi union.cmo: mathql_semantics.cmo union.cmi @@ -31,9 +25,9 @@ pattern.cmo: dbconn.cmi eval.cmi mathql_semantics.cmo utility.cmi pattern.cmi pattern.cmx: dbconn.cmx eval.cmx mathql_semantics.cmx utility.cmx pattern.cmi use.cmo: dbconn.cmi mathql_semantics.cmo utility.cmi use.cmi use.cmx: dbconn.cmx mathql_semantics.cmx utility.cmx use.cmi -mqint.cmo: dbconn.cmi diff.cmi eval.cmi intersect.cmi mathql.cmo \ - mathql_semantics.cmo pattern.cmi select.cmi sortedby.cmi union.cmi \ - use.cmi utility.cmi mqint.cmi -mqint.cmx: dbconn.cmx diff.cmx eval.cmx intersect.cmx mathql.cmx \ - mathql_semantics.cmx pattern.cmx select.cmx sortedby.cmx union.cmx \ - use.cmx utility.cmx mqint.cmi +mqint.cmo: dbconn.cmi diff.cmi eval.cmi intersect.cmi mathql_semantics.cmo \ + pattern.cmi select.cmi sortedby.cmi union.cmi use.cmi utility.cmi \ + mqint.cmi +mqint.cmx: dbconn.cmx diff.cmx eval.cmx intersect.cmx mathql_semantics.cmx \ + pattern.cmx select.cmx sortedby.cmx union.cmx use.cmx utility.cmx \ + mqint.cmi diff --git a/helm/ocaml/mathql_interpreter/Makefile b/helm/ocaml/mathql_interpreter/Makefile index ccd485a59..28c71737d 100644 --- a/helm/ocaml/mathql_interpreter/Makefile +++ b/helm/ocaml/mathql_interpreter/Makefile @@ -1,16 +1,16 @@ PACKAGE = mathql_interpreter -REQUIRES = helm-urimanager pgocaml unix +REQUIRES = helm-urimanager pgocaml unix helm-mathql PREDICATES = INTERFACE_FILES = dbconn.mli eval.mli utility.mli func.mli diff.mli \ sortedby.mli select.mli intersect.mli union.mli \ pattern.mli use.mli mqint.mli -IMPLEMENTATION_FILES = mathql.ml mathql_semantics.ml \ +IMPLEMENTATION_FILES = mathql_semantics.ml \ $(INTERFACE_FILES:%.mli=%.ml) -EXTRA_OBJECTS_TO_INSTALL = mathql.ml mathql.cmi mathql_semantics.ml \ - mathql_semantics.cmi +EXTRA_OBJECTS_TO_INSTALL = mathql_semantics.ml mathql_semantics.cmi + EXTRA_OBJECTS_TO_CLEAN = diff --git a/helm/ocaml/mathql_interpreter/dbconn.ml b/helm/ocaml/mathql_interpreter/dbconn.ml index 185ea011d..e46f89cb2 100644 --- a/helm/ocaml/mathql_interpreter/dbconn.ml +++ b/helm/ocaml/mathql_interpreter/dbconn.ml @@ -31,7 +31,7 @@ * le eccezioni lanciate dalle funzioni init e pgc sono * definite nel modulo Mathql *) -open Mathql;; +open MathQL;; (* * paramentri della connessione diff --git a/helm/ocaml/mathql_interpreter/eval.ml b/helm/ocaml/mathql_interpreter/eval.ml index 4bc9a88db..81be80520 100644 --- a/helm/ocaml/mathql_interpreter/eval.ml +++ b/helm/ocaml/mathql_interpreter/eval.ml @@ -27,7 +27,7 @@ * *) -open Mathql;; +open MathQL;; (* * conversione di un pattern @@ -37,11 +37,11 @@ let rec patterneval p = [] -> "" | head::tail -> let h = match head with - MQString (s) -> Str.global_replace (Str.regexp "\.") "\\\\\." s - | MQSlash -> "/" - | MQAnyChr -> "[^/#]?" - | MQAst -> "[^/#]*" - | MQAstAst -> "[^#]*" + MQBC (s) -> Str.global_replace (Str.regexp "\.") "\\\\\." s + | MQBD -> "/" + | MQBQ -> "[^/#]?" + | MQBS -> "[^/#]*" + | MQBSS -> "[^#]*" in h ^ (patterneval tail) ;; @@ -50,14 +50,13 @@ let rec patterneval p = * conversione di un fragment identifier *) let fieval fi = - match fst fi with - None -> "" - | Some i -> +match fi with + [] -> "" + | MQFC i :: tail -> let s = "#xpointer\\\\(1/" ^ string_of_int (i) in - match snd fi with - None -> - s ^ "\\\\)" - | Some j -> + match tail with + [] -> s ^ "\\\\)" + | MQFC j :: tail2 -> s ^ "/" ^ string_of_int j ^ "\\\\)" ;; @@ -77,7 +76,8 @@ let exteval ext = * valuta il preambolo *) let preeval p = - p + match p with + Some s -> s ;; (* @@ -87,7 +87,7 @@ let preeval p = * SQL standard LIKE perche' MathQL prevede esperssioni con "*" * e con "**". *) -let pattern_match preamble pattern fragid = +let pattern_match (preamble, pattern, fragid) = " ~ '" ^ (preeval preamble) ^ ":/" ^ (patterneval pattern) ^ (fieval fragid) ^ "'" ;; diff --git a/helm/ocaml/mathql_interpreter/eval.mli b/helm/ocaml/mathql_interpreter/eval.mli index 1c634d977..00b64ed95 100644 --- a/helm/ocaml/mathql_interpreter/eval.mli +++ b/helm/ocaml/mathql_interpreter/eval.mli @@ -24,5 +24,4 @@ *) val pattern_match : - string -> - Mathql.mquptoken list -> int option * int option -> string + MathQL.mqtref -> string diff --git a/helm/ocaml/mathql_interpreter/func.ml b/helm/ocaml/mathql_interpreter/func.ml index 7f80da7f4..314ad2b01 100644 --- a/helm/ocaml/mathql_interpreter/func.ml +++ b/helm/ocaml/mathql_interpreter/func.ml @@ -29,7 +29,7 @@ open Dbconn;; open Utility;; -open Mathql;; +open MathQL;; (* * implementazione della funzione NAME diff --git a/helm/ocaml/mathql_interpreter/func.mli b/helm/ocaml/mathql_interpreter/func.mli index 5e9d77ff3..fb68df82a 100644 --- a/helm/ocaml/mathql_interpreter/func.mli +++ b/helm/ocaml/mathql_interpreter/func.mli @@ -23,4 +23,4 @@ * http://cs.unibo.it/helm/. *) -val apply_func: Mathql.mqfunc -> string -> string +val apply_func: MathQL.mqfunc -> string -> string diff --git a/helm/ocaml/mathql_interpreter/mathql.ml b/helm/ocaml/mathql_interpreter/mathql.ml deleted file mode 100644 index e78029036..000000000 --- a/helm/ocaml/mathql_interpreter/mathql.ml +++ /dev/null @@ -1,135 +0,0 @@ -(* 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 *) -(* Domenico Lordi *) -(* 30/04/2002 *) -(* *) -(* *) -(******************************************************************************) - -exception MQInvalidURI of string -exception MQConnectionFailed of string -exception MQInvalidConnection of string - -(* Input types **************************************************************) -(* main type is mquery *) - -type mqrvar = string (* name *) - -type mqsvar = string (* name *) - -type mquptoken = - | MQString of string (* a constant string *) - | MQSlash (* a slash: '/' *) - | MQAnyChr (* Any single character: '?' *) - | MQAst (* single asterisk: '*' *) - | MQAstAst (* double asterisk: '**' *) - -type mqup = mquptoken list (* uri pattern (helper) *) - -type mqfi = int option * int option - -type mqtref = string * mqup * mqfi (* HELM preamble, - uri pattern, - fragment identifier *) - -type mqpattern = mqtref (* constant pattern *) - -type mqfunc = - | MQName (* NAME *) - | MQTheory - | MQTitle - | MQContributor - | MQCreator - | MQPublisher - | MQSubject - | MQDescription - | MQDate - | MQType - | MQFormat - | MQIdentifier - | MQLanguage - | MQRelation - | MQSource - | MQCoverage - | MQRights - | MQInstitution - | MQContact - | MQFirstVersion - | MQModified - -type mqstring = - | MQCons of string (* constant *) - | MQFunc of mqfunc * mqrvar (* function, rvar *) - | MQRVar of mqrvar (* rvar *) - | MQSVar of mqsvar (* svar *) - | MQMConclusion (* main conclusion *) - | MQConclusion (* inner conclusion *) - -type mqorder = - | MQAsc - | MQDesc - -type mqbool = - | MQTrue - | MQFalse - | MQAnd of mqbool * mqbool - | MQOr of mqbool * mqbool - | MQNot of mqbool - | MQIs of mqstring * mqstring (* operands *) - | MQSetEqual of mqlist * mqlist (* the two lists denote the *) - (* same set *) - | MQSubset of mqlist * mqlist (* the two lists denote two *) - (* sets, the first one *) - (* subsect of the second one. *) - -and mqlist = - | MQSelect of mqrvar * mqlist * mqbool (* rvar, list, boolean *) - | MQUse of mqlist * mqsvar (* list, Position attribute *) - | MQUsedBy of mqlist * mqsvar (* list, Position attribute *) - | MQPattern of mqpattern (* pattern *) - | MQUnion of mqlist * mqlist (* *) - | MQDiff of mqlist * mqlist (* *) - | MQIntersect of mqlist * mqlist (* *) - | MQSortedBy of mqlist * mqorder * mqfunc (* *) - | MQRVarOccur of mqrvar - -type mquery = - | MQList of mqlist - -(* Output types *************************************************************) -(* main type is mqresult *) - -type mquref = UriManager.uri * mqfi (* uri, fragment identifier *) - -type mqrefs = mqtref list (* list of references (helper) *) - -type mqresult = - | MQRefs of mqrefs diff --git a/helm/ocaml/mathql_interpreter/mathql_semantics.ml b/helm/ocaml/mathql_interpreter/mathql_semantics.ml index e7e5ee5e5..f618e1e5c 100644 --- a/helm/ocaml/mathql_interpreter/mathql_semantics.ml +++ b/helm/ocaml/mathql_interpreter/mathql_semantics.ml @@ -25,9 +25,9 @@ (* attributes are sorted w.r.t. their name in increasing order *) type attributed_uri = - { uri: string ; attributes : (Mathql.mqsvar * string) list } + { uri: string ; attributes : (MathQL.mqsvar * string) list } type attributed_uri_env = - (Mathql.mqrvar * attributed_uri) list + (MathQL.mqrvar * attributed_uri) list type result = attributed_uri list diff --git a/helm/ocaml/mathql_interpreter/mqint.ml b/helm/ocaml/mathql_interpreter/mqint.ml index 2bf4d144e..dce67f864 100644 --- a/helm/ocaml/mathql_interpreter/mqint.ml +++ b/helm/ocaml/mathql_interpreter/mqint.ml @@ -26,7 +26,7 @@ (* * implementazione del'interprete MathQL *) -open Mathql;; +open MathQL;; open Eval;; open Utility;; open Dbconn;; @@ -74,7 +74,7 @@ let rec execute_ex env = | MQUse (alist, asvar) -> use_ex (execute_ex env alist) asvar "B" (*"backPointer"*) | MQPattern (apreamble, apattern, afragid) -> - pattern_ex apreamble apattern afragid + pattern_ex (apreamble, apattern, afragid) | MQUnion (l1, l2) -> union_ex (execute_ex env l1) (execute_ex env l2) (* @@ -122,6 +122,8 @@ Select.execute := execute_ex;; * la uri puo' far parte del risultato. *) let xres_to_res l = + MQRefs (List.map (function {Mathql_semantics.uri = uri} -> uri) l) +(* let tmp = List.map (function {Mathql_semantics.uri = uri} -> uri) l in MQRefs (List.map @@ -131,48 +133,49 @@ let xres_to_res l = match List.rev tl with ")"::n::"xpointer(1"::tail -> ( - hd, + Some hd, List.fold_left (fun par t -> match par with - [] -> [MQString t] - | _ -> (MQString t) :: MQSlash :: par + [] -> [MQBC t] + | _ -> (MQBC t) :: MQBD :: par ) [] tail, - (Some (int_of_string n), None) + [MQFC (int_of_string n)] ) | ")"::n::m::"xpointer(1"::tail -> ( - hd, + Some hd, List.fold_left (fun par t -> match par with - [] -> [MQString t] - | _ -> (MQString t) :: MQSlash :: par + [] -> [MQBC t] + | _ -> (MQBC t) :: MQBD :: par ) [] tail, - (Some (int_of_string m), Some (int_of_string n)) + [MQFC (int_of_string m); MQFC (int_of_string n)] ) | tail -> ( - hd, + Some hd, List.fold_left (fun par t -> match par with - [] -> [MQString t] - | _ -> (MQString t) :: MQSlash :: par + [] -> [MQBC t] + | _ -> (MQBC t) :: MQBD :: par ) [] tail, - (None, None) + [] ) ) | [] -> assert false ) tmp ) +*) ;; diff --git a/helm/ocaml/mathql_interpreter/mqint.mli b/helm/ocaml/mathql_interpreter/mqint.mli index 55836d940..60f00f50c 100644 --- a/helm/ocaml/mathql_interpreter/mqint.mli +++ b/helm/ocaml/mathql_interpreter/mqint.mli @@ -27,7 +27,7 @@ * interfaccia dell'interprete MathQL *) -open Mathql;; +open MathQL;; (* * inizializzazione del database diff --git a/helm/ocaml/mathql_interpreter/pattern.ml b/helm/ocaml/mathql_interpreter/pattern.ml index fa28f6cc5..7aa09f172 100644 --- a/helm/ocaml/mathql_interpreter/pattern.ml +++ b/helm/ocaml/mathql_interpreter/pattern.ml @@ -32,11 +32,11 @@ open Utility;; open Eval;; open Mathql_semantics;; -let pattern_ex apreamble apattern afragid = +let pattern_ex (apreamble, apattern, afragid) = let c = pgc () in (*let r1 = helm_class_id "MathResource" in*) (*let qq = "select att0 from t" ^ r1 ^ " where att0 " ^ (pattern_match apreamble apattern afragid) ^ " order by t" ^ r1 ^ ".att0 asc" in*) - let qq = "select uri from registry where uri " ^ (pattern_match apreamble apattern afragid) ^ " order by registry.uri asc" in + let qq = "select uri from registry where uri " ^ (pattern_match (apreamble, apattern, afragid)) ^ " order by registry.uri asc" in (*let _ = print_endline qq in*) let res = c#exec (qq) diff --git a/helm/ocaml/mathql_interpreter/pattern.mli b/helm/ocaml/mathql_interpreter/pattern.mli index 72d44dc41..1fd21bdba 100644 --- a/helm/ocaml/mathql_interpreter/pattern.mli +++ b/helm/ocaml/mathql_interpreter/pattern.mli @@ -24,5 +24,5 @@ *) val pattern_ex : - string -> Mathql.mquptoken list -> int option * int option -> + MathQL.mqtref -> Mathql_semantics.result diff --git a/helm/ocaml/mathql_interpreter/select.ml b/helm/ocaml/mathql_interpreter/select.ml index 4b2c26402..1e53a4ba4 100644 --- a/helm/ocaml/mathql_interpreter/select.ml +++ b/helm/ocaml/mathql_interpreter/select.ml @@ -27,7 +27,7 @@ * implementazione del comando SELECT *) -open Mathql;; +open MathQL;; open Func;; open Utility;; diff --git a/helm/ocaml/mathql_interpreter/select.mli b/helm/ocaml/mathql_interpreter/select.mli index 582fc0030..7c2fe9ddf 100644 --- a/helm/ocaml/mathql_interpreter/select.mli +++ b/helm/ocaml/mathql_interpreter/select.mli @@ -26,9 +26,9 @@ exception ExecuteFunctionNotInitialized;; val execute: (Mathql_semantics.attributed_uri_env -> - Mathql.mqlist -> Mathql_semantics.result) ref + MathQL.mqlist -> Mathql_semantics.result) ref val select_ex : Mathql_semantics.attributed_uri_env -> - Mathql.mqrvar -> Mathql_semantics.result -> Mathql.mqbool -> + MathQL.mqrvar -> Mathql_semantics.result -> MathQL.mqbool -> Mathql_semantics.result diff --git a/helm/ocaml/mathql_interpreter/sortedby.ml b/helm/ocaml/mathql_interpreter/sortedby.ml index a62926684..db2258d56 100644 --- a/helm/ocaml/mathql_interpreter/sortedby.ml +++ b/helm/ocaml/mathql_interpreter/sortedby.ml @@ -27,7 +27,7 @@ * implementazione del comando SORTEDBY *) -open Mathql;; +open MathQL;; open Func;; open Utility;; diff --git a/helm/ocaml/mathql_interpreter/sortedby.mli b/helm/ocaml/mathql_interpreter/sortedby.mli index ebed97055..6c01aa0e6 100644 --- a/helm/ocaml/mathql_interpreter/sortedby.mli +++ b/helm/ocaml/mathql_interpreter/sortedby.mli @@ -24,4 +24,4 @@ *) val sortedby_ex : - string list list -> Mathql.mqorder -> Mathql.mqfunc -> string list list + string list list -> MathQL.mqorder -> MathQL.mqfunc -> string list list diff --git a/helm/ocaml/mathql_interpreter/use.mli b/helm/ocaml/mathql_interpreter/use.mli index a8186b40a..0572ad5ac 100644 --- a/helm/ocaml/mathql_interpreter/use.mli +++ b/helm/ocaml/mathql_interpreter/use.mli @@ -24,4 +24,4 @@ *) val use_ex : - Mathql_semantics.result -> Mathql.mqsvar -> string -> Mathql_semantics.result + Mathql_semantics.result -> MathQL.mqsvar -> string -> Mathql_semantics.result