]> matita.cs.unibo.it Git - helm.git/commitdiff
new semantics for relation and attribute
authorFerruccio Guidi <ferruccio.guidi@unibo.it>
Sat, 21 Sep 2002 18:44:02 +0000 (18:44 +0000)
committerFerruccio Guidi <ferruccio.guidi@unibo.it>
Sat, 21 Sep 2002 18:44:02 +0000 (18:44 +0000)
helm/ocaml/mathql/mQueryTLexer.mll
helm/ocaml/mathql/mQueryTParser.mly
helm/ocaml/mathql/mQueryUtil.ml
helm/ocaml/mathql/mathQL.ml

index 5f9b2ebac254b9d7dee42ae15674e2fbc3c861ad..89d62375a24c1730c0a43e2eaa5ee2ff49b9dc18 100644 (file)
@@ -60,6 +60,7 @@ and query_token = parse
    | '$'         { DL }
    | '.'         { FS }
    | ','         { CM }
+   | '/'         { SL }
    | "and"       { AND    }
    | "attr"      { ATTR   }
    | "attribute" { ATTRIB }
index a90c90e71d63b20f8dd14212ed99f3b7192f719d..9af1be4f0d59dc3e3040e63d01671efdd768901c 100644 (file)
 %{
 %}
    %token    <string> ID STR
-   %token    IS LC RC CM SC LP RP AT PC DL FS DQ EOF 
+   %token    SL IS LC RC CM SC LP RP AT PC DL FS DQ EOF 
    %token    AND ATTR ATTRIB BE DIFF EQ EX FALSE FUN IN INTER LET MEET NOT OR
    %token    PAT REF REFOF REL SELECT SUB SUPER TRUE UNION WHERE
    %left     DIFF WHERE REFOF  
    %left     OR UNION
    %left     AND INTER
-   %nonassoc STR
+   %nonassoc REL
    %nonassoc NOT EX IN ATTR
 
    %start    qstr query result
       | vvar CM vvar_list { $1 :: $3 }
       | vvar              { [$1]     }
    ;
+   qstr_path:
+      | STR SL qstr_path { $1 :: $3 }
+      | STR              { [$1]     } 
+   ;
    ref_op:
       | SUB   { MathQL.SubOp   }
       | SUPER { MathQL.SuperOp }
       |       { MathQL.ExactOp }
    ;
    val_exp:
-      | STR                       { MathQL.Const [$1]             } 
-      | FUN STR val_exp           { MathQL.Fun ($2, $3)           }
-      | ATTRIB ref_op STR val_exp { MathQL.Attribute ($2, $3, $4) }
-      | rvar FS vvar              { MathQL.Record ($1, $3)        }
-      | vvar                      { MathQL.VVar $1                }
-      | LC qstr_list RC           { MathQL.Const $2               }
-      | LC RC                     { MathQL.Const []               }
-      | REFOF set_exp             { MathQL.RefOf $2               }
+      | STR                             { MathQL.Const [$1]             } 
+      | FUN STR val_exp                 { MathQL.Fun ($2, $3)           }
+      | ATTRIB ref_op qstr_path val_exp { MathQL.Attribute ($2, $3, $4) }
+      | rvar FS vvar                    { MathQL.Record ($1, $3)        }
+      | vvar                            { MathQL.VVar $1                }
+      | LC qstr_list RC                 { MathQL.Const $2               }
+      | LC RC                           { MathQL.Const []               }
+      | REFOF set_exp                   { MathQL.RefOf $2               }
    ;
    boole_exp:
       | TRUE                    { MathQL.True          }
       | boole_exp OR boole_exp  { MathQL.Or ($1, $3)   }
    ;   
    set_exp:
-      | REF val_exp                            { MathQL.Ref $2                    }
-      | PAT val_exp                            { MathQL.Pattern $2                } 
-      | LP set_exp RP                          { $2                               }
-      | SELECT rvar IN set_exp WHERE boole_exp { MathQL.Select ($2, $4, $6)       }
-      | REL ref_op STR set_exp ATTR vvar_list  { MathQL.Relation ($2, $3, $4, $6) }
-      | REL ref_op STR set_exp                 { MathQL.Relation ($2, $3, $4, []) }
-      | svar                                   { MathQL.SVar $1                   }
-      | rvar                                   { MathQL.RVar $1                   }
-      | set_exp UNION set_exp                  { MathQL.Union ($1, $3)            }
-      | set_exp INTER set_exp                  { MathQL.Intersect ($1, $3)        }
-      | set_exp DIFF set_exp                   { MathQL.Diff ($1, $3)             }
-      | LET svar BE set_exp IN set_exp         { MathQL.LetSVar ($2, $4, $6)      }      
-      | LET vvar BE val_exp IN set_exp         { MathQL.LetVVar ($2, $4, $6)      }      
+      | REF val_exp                                 { MathQL.Ref $2                    }
+      | PAT val_exp                                 { MathQL.Pattern $2                } 
+      | LP set_exp RP                               { $2                               }
+      | SELECT rvar IN set_exp WHERE boole_exp      { MathQL.Select ($2, $4, $6)       }
+      | REL ref_op qstr_path set_exp ATTR vvar_list { MathQL.Relation ($2, $3, $4, $6) }
+      | REL ref_op qstr_path set_exp                { MathQL.Relation ($2, $3, $4, []) }
+      | svar                                        { MathQL.SVar $1                   }
+      | rvar                                        { MathQL.RVar $1                   }
+      | set_exp UNION set_exp                       { MathQL.Union ($1, $3)            }
+      | set_exp INTER set_exp                       { MathQL.Intersect ($1, $3)        }
+      | set_exp DIFF set_exp                        { MathQL.Diff ($1, $3)             }
+      | LET svar BE set_exp IN set_exp              { MathQL.LetSVar ($2, $4, $6)      }      
+      | LET vvar BE val_exp IN set_exp              { MathQL.LetVVar ($2, $4, $6)      }      
    ;
    query:
       | set_exp EOF { $1 }
index 73006b60675994d0a5e8b5d69ed7718600d52b3f..450e40210560b8d40c063f213212a223f3c0fdfd 100644 (file)
@@ -54,7 +54,7 @@ let text_of_query x =
       | M.SuperOp -> "super "
    in
    let txt_vvar_list l =
-      txt_list txt_vvar ", " l
+      l
    in
    let rec txt_val = function
       | M.Const [s]           -> txt_qstr s
@@ -62,7 +62,7 @@ let text_of_query x =
       | 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.Attribute (r, p, x) -> "attribute " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_val x
       | M.RefOf x             -> "refof " ^ txt_set x
    and txt_boole = function
       | M.False       -> "false"
@@ -77,8 +77,8 @@ let text_of_query x =
    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.Relation (r, p, x, []) -> "relation " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_set x
+      | M.Relation (r, p, x, l)  -> "relation " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_set x ^ " attr " ^ txt_list txt_vvar ", " 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 ^ ")"
@@ -87,7 +87,7 @@ let text_of_query x =
       | 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
+   in 
    txt_set x
 
 let text_of_result x sep =
@@ -100,7 +100,7 @@ let text_of_result x sep =
       | (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
+   let txt_set l = txt_list txt_res ("; " ^ sep) l ^ sep in
    txt_set x
 
 let query_of_text lexbuf =
index b424d110b56bc8247b6fa8b750487668bf603842..60b19297aa2e8581e0171e10f013cc5aa9b6a2d7 100644 (file)
@@ -47,13 +47,15 @@ type refine_op = ExactOp
                | SubOp
               | SuperOp
 
+type path = string list
+
 type vvar_list = vvar list
 
 type set_exp = SVar of svar
             | RVar of rvar
              | Ref of val_exp
              | Pattern of val_exp
-            | Relation of refine_op * string * set_exp * vvar_list
+            | Relation of refine_op * path * set_exp * vvar_list
              | Select of rvar * set_exp * boole_exp
             | Union of set_exp * set_exp
             | Intersect of set_exp * set_exp
@@ -76,7 +78,7 @@ and val_exp = Const of string list
            | Record of rvar * vvar
            | VVar of vvar
            | Fun of string * val_exp
-           | Attribute of refine_op * string * val_exp
+           | Attribute of refine_op * path * val_exp
 
 type query = set_exp