]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/mqint.ml
new MathQL syntax
[helm.git] / helm / ocaml / mathql_interpreter / mqint.ml
index 8aa07a36879bc5add524bff23822c9f9e2e38521..dce67f86494d9fc3f95006622eae5af340626a51 100644 (file)
@@ -26,7 +26,7 @@
 (*
  * implementazione del'interprete MathQL
  *)
-open Mathql;;
+open MathQL;;
 open Eval;;
 open Utility;;
 open Dbconn;;
@@ -60,35 +60,37 @@ let fi_to_string fi =
  *)
 let init () = Dbconn.init ();;
 
+(* execute_ex env q                                                   *)
+(*  [env] is the attributed uri environment in which the query [q]    *)
+(*        must be evaluated                                           *)
+(*  [q]   is the query to evaluate                                    *)
+(*  It returns a [Mathql_semantics.result]                            *)
+let rec execute_ex env =
+ function
+    MQSelect (apvar, alist, abool) ->
+     select_ex env apvar (execute_ex env alist) abool
+ |  MQUsedBy (alist, asvar) ->
+     use_ex (execute_ex env alist) asvar "F" (*"refObj"*)
+ |  MQUse (alist, asvar) ->
+     use_ex (execute_ex env alist) asvar "B" (*"backPointer"*)
+ |  MQPattern (apreamble, apattern, afragid) ->
+     pattern_ex (apreamble, apattern, afragid)
+ |  MQUnion (l1, l2) ->
+     union_ex (execute_ex env l1) (execute_ex env l2)
 (*
- * esecuzione di una query
- *
- * parametri:
- * q
- *
- * output: string list list; risultato internto formato da uri + contesto.
- *)
-let rec execute_ex q =
-   match q with
-      MQSelect (apvar, alist, abool) ->
-       select_ex apvar (execute_ex alist) abool
-   |  MQUsedBy (alist, asvar) ->
-       use_ex (execute_ex alist) asvar "refObj"
-   |  MQUse (alist, asvar) ->
-       use_ex (execute_ex alist) asvar "backPointer"
-   |  MQPattern (apreamble, apattern, afragid) ->
-       (*let _ = print_endline ("*********" ^ apreamble ^ (fi_to_string afragid)); flush stdout in*)
-       pattern_ex apreamble apattern afragid
-   |  MQUnion (l1, l2) ->
-       union_ex (execute_ex l1) (execute_ex l2)
-   |  MQDiff (l1, l2) ->
-       diff_ex (execute_ex l1) (execute_ex l2)
-   |  MQSortedBy (l, o, f) ->
-       sortedby_ex (execute_ex l) o f
-   |  MQIntersect (l1, l2) ->
-       intersect_ex (execute_ex l1) (execute_ex l2)
+ |  MQDiff (l1, l2) ->
+     diff_ex (execute_ex env l1) (execute_ex env l2)
+ |  MQSortedBy (l, o, f) ->
+     sortedby_ex (execute_ex env l) o f
+*)
+ |  MQIntersect (l1, l2) ->
+     intersect_ex (execute_ex env l1) (execute_ex env l2)
+ |  MQRVarOccur rvar -> [List.assoc rvar env]
 ;;
 
+(* Let's initialize the execute in Select, creating a cyclical recursion *)
+Select.execute := execute_ex;;
+
 (*
  * converte il risultato interno di una query (uri + contesto)
  * in un risultato di sole uri
@@ -120,7 +122,9 @@ let rec execute_ex q =
  * la uri puo' far parte del risultato.
  *)
 let xres_to_res l =
- let tmp = List.map List.hd (List.tl l) in
+ 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
     (function l ->
@@ -129,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
    )
+*)
 ;;
 
 
@@ -179,7 +184,7 @@ let xres_to_res l =
  *)
 let execute q =
  match q with
-    MQList qq -> xres_to_res (execute_ex qq)
+    MQList qq -> xres_to_res (execute_ex [] qq)
 ;;
 
 (*