| s1 :: tl1, s2 :: tl2 -> s1 :: join tl1 tl2
in
let rec an_val = function
- | M.Const _ -> []
- | M.VVar _ -> []
- | M.Record (rv, _) -> [rv]
- | M.Fun (_, x) -> an_val x
- | M.Attribute (_, _, x) -> an_val x
- | M.RefOf x -> an_set x
+ | M.Const _ -> []
+ | M.VVar _ -> []
+ | M.Record (rv, _) -> [rv]
+ | M.Fun (_, x) -> an_val x
+ | M.Attribute (_, _, _, x) -> an_val x
+ | M.RefOf x -> an_set x
and an_boole = function
| M.False -> []
| M.True -> []
| M.Meet (x, y) -> join (an_val x) (an_val y)
| M.Eq (x, y) -> join (an_val x) (an_val y)
and an_set = function
- | M.SVar _ -> []
- | M.RVar _ -> []
- | M.Relation (_, _, x, _) -> an_set x
- | M.Pattern x -> an_val x
- | M.Ref x -> an_val x
- | M.Union (x, y) -> join (an_set x) (an_set y)
- | M.Intersect (x, y) -> join (an_set x) (an_set y)
- | M.Diff (x, y) -> join (an_set x) (an_set y)
- | M.LetSVar (_, x, y) -> join (an_set x) (an_set y)
- | M.LetVVar (_, x, y) -> join (an_val x) (an_set y)
- | M.Select (_, x, y) -> join (an_set x) (an_boole y)
+ | M.SVar _ -> []
+ | M.RVar _ -> []
+ | M.Relation (_, _, _, x, _) -> an_set x
+ | M.Pattern x -> an_val x
+ | M.Ref x -> an_val x
+ | M.Union (x, y) -> join (an_set x) (an_set y)
+ | M.Intersect (x, y) -> join (an_set x) (an_set y)
+ | M.Diff (x, y) -> join (an_set x) (an_set y)
+ | M.LetSVar (_, x, y) -> join (an_set x) (an_set y)
+ | M.LetVVar (_, x, y) -> join (an_val x) (an_set y)
+ | M.Select (_, x, y) -> join (an_set x) (an_boole y)
in
an_boole x
%}
%token <string> ID STR
%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
+ %token AND ATTR ATTRIB BE DIFF EQ EX FALSE FUN IN INTER INV LET MEET NOT
+ %token OR PAT REF REFOF REL SELECT SUB SUPER TRUE UNION WHERE
%left DIFF WHERE REFOF
%left OR UNION
%left AND INTER
vvar:
| DL ID { $2 }
;
- qstr_list:
- | STR CM qstr_list { $1 :: $3 }
- | STR { [$1] }
+ strs:
+ | STR CM strs { $1 :: $3 }
+ | STR { [$1] }
;
- vvar_list:
- | vvar CM vvar_list { $1 :: $3 }
- | vvar { [$1] }
+ vvars:
+ | vvar CM vvars { $1 :: $3 }
+ | vvar { [$1] }
;
- qstr_path:
- | STR SL qstr_path { $1 :: $3 }
- | STR { [$1] }
+ path:
+ | STR SL path { $1 :: $3 }
+ | STR { [$1] }
;
- ref_op:
+ ref:
| SUB { MathQL.SubOp }
| SUPER { MathQL.SuperOp }
| { MathQL.ExactOp }
;
+ inv:
+ | INV { true }
+ | { false }
+ ;
val_exp:
- | 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 }
- | LP val_exp RP { $2 }
+ | STR { MathQL.Const [$1] }
+ | FUN STR val_exp { MathQL.Fun ($2, $3) }
+ | ATTRIB inv ref path val_exp { MathQL.Attribute ($2, $3, $4, $5) }
+ | rvar FS vvar { MathQL.Record ($1, $3) }
+ | vvar { MathQL.VVar $1 }
+ | LC strs RC { MathQL.Const $2 }
+ | LC RC { MathQL.Const [] }
+ | REFOF set_exp { MathQL.RefOf $2 }
+ | LP val_exp RP { $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 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) }
+ | 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 inv ref path set_exp ATTR vvars { MathQL.Relation ($2, $3, $4, $5, $7) }
+ | REL inv ref path set_exp { MathQL.Relation ($2, $3, $4, $5, []) }
+ | 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 }
;
- attribute:
- | STR IS qstr_list { ($1, $3) }
- | STR { ($1, []) }
+ attr:
+ | STR IS strs { ($1, $3) }
+ | STR { ($1, []) }
;
- attr_list:
- | attribute SC attr_list { $1 :: $3 }
- | attribute { [$1] }
+ attrs:
+ | attr SC attrs { $1 :: $3 }
+ | attr { [$1] }
;
group:
- LC attr_list RC { $2 }
+ LC attrs RC { $2 }
;
- group_list:
- | group CM group_list { $1 :: $3 }
- | group { [$1] }
+ groups:
+ | group CM groups { $1 :: $3 }
+ | group { [$1] }
;
resource:
- | STR ATTR group_list { ($1, $3) }
- | STR { ($1, []) }
+ | STR ATTR groups { ($1, $3) }
+ | STR { ($1, []) }
;
- resource_list:
- | resource SC resource_list { $1 :: $3 }
- | resource { [$1] }
+ resources:
+ | resource SC resources { $1 :: $3 }
+ | resource { [$1] }
| { [] }
;
result:
- | resource_list EOF { $1 }
+ | resources EOF { $1 }
let txt_svar sv = "%" ^ sv in
let txt_rvar rv = "@" ^ rv in
let txt_vvar vv = "$" ^ vv in
+ let txt_inv i = if i then "inverse " else "" in
let txt_ref = function
| M.ExactOp -> ""
| M.SubOp -> "sub "
| M.SuperOp -> "super "
in
- let txt_vvar_list l =
- l
- in
+ let txt_refpath i r p = txt_inv i ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " 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, p, x) -> "attribute " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_val x
- | M.RefOf x -> "refof " ^ txt_set x
+ | 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 (i, r, p, x) -> "attribute " ^ txt_refpath i r p ^ txt_val x
+ | M.RefOf x -> "refof " ^ txt_set x
and txt_boole = function
| M.False -> "false"
| M.True -> "true"
| M.Ex b x -> "ex " ^ txt_boole x
-(* | M.Ex b x -> "ex [" ^ txt_list txt_rvar "," b ^ "] " ^ txt_boole x *)
- | M.Not x -> "not " ^ txt_boole x
+(* | M.Ex b x -> "ex [" ^ txt_list txt_rvar "," b ^ "] " ^ 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, 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 ^ ")"
- | 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
+ | M.SVar sv -> txt_svar sv
+ | M.RVar rv -> txt_rvar rv
+ | M.Relation (i, r, p, x, []) -> "relation " ^ txt_refpath i r p ^ txt_set x
+ | M.Relation (i, r, p, x, l) -> "relation " ^ txt_refpath i r 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 ^ ")"
+ | 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