Update of /cvsroot/monetdb/pathfinder/compiler/semantics
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv7749/semantics
Modified Files:
normalize.brg ns.c typecheck.brg varscope.c xquery_fo.c
Log Message:
XQuery full-text search support initial version!
This initial version provides support to
-ftcontains keyword,
e.g., for $f in doc("menu.xml")//food[./name ftcontains "Belgian Waffles"]
return $f
The above query will return all the food nodes that has some relevancy over
"Belgian Waffles"
-initial score variable support
e.g., for $f score $s in doc("menu.xml")//food[./name ftcontains "Belgian
Waffles"]
return $s
The above query will return the relevancy score of all the matched food nodes,
however since its an initial version, the support to this score variable is
very limited.
Index: xquery_fo.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/semantics/xquery_fo.c,v
retrieving revision 1.189
retrieving revision 1.190
diff -u -d -r1.189 -r1.190
--- xquery_fo.c 12 Oct 2009 16:15:14 -0000 1.189
+++ xquery_fo.c 5 Nov 2009 16:24:00 -0000 1.190
@@ -2868,7 +2868,7 @@
, /* tijah:create-ft-index() as docmgmt */
{ .ns = PFns_tijah, .loc = "create-ft-index",
.arity = 0, .sig_count = 1, .sigs = { {
- .ret_ty = PFty_docmgmt () } },
+ .ret_ty = PFty_docmgmt () } },
.alg = PFbui_manage_fti_c_xx }
, /* tijah:create-ft-index(string*) as docmgmt */
{ .ns = PFns_tijah, .loc = "create-ft-index",
@@ -3085,6 +3085,42 @@
.par_ty = (PFty_t[]) { PFty_xs_integer () },
.ret_ty = PFty_xs_integer () } } }
#endif
+
+#ifdef HAVE_PFTIJAH
+
+ /* . Full-text functions */
+ , /* fts:ftcontains (node, string) as boolean */
+ { .ns = PFns_fts, .loc = "ftcontains",
+ .arity = 2, .sig_count = 1, .sigs = { {
+ .par_ty = (PFty_t[]) { PFty_xs_anyNode (),
+ PFty_xs_string () },
+ .ret_ty = PFty_xs_boolean () } },
+ .alg = PFbui_tijah_ftfun_b_sxx }
+ , /* fts:ftcontains (node?, string?) as boolean? */
+ { .ns = PFns_fts, .loc = "ftcontains",
+ .arity = 2, .sig_count = 1, .sigs = { {
+ .par_ty = (PFty_t[]) { PFty_opt (PFty_xs_anyNode ()),
+ PFty_opt (PFty_xs_string ()) },
+ .ret_ty = PFty_opt (PFty_xs_boolean ()) } },
+ .alg = PFbui_tijah_ftfun_b_sxx }
+
+
+ , /* fts:score (boolean) as dbl */
+ { .ns = PFns_fts, .loc = "score",
+ .arity = 1, .sig_count = 1, .sigs = { {
+ .par_ty = (PFty_t[]) { PFty_item () },
+ .ret_ty = PFty_xs_double () } },
+ .alg = PFbui_tijah_ftfun_score }
+ , /* fts:score (boolean?) as dbl? */
+ { .ns = PFns_fts, .loc = "score",
+ .arity = 1, .sig_count = 1, .sigs = { {
+ .par_ty = (PFty_t[]) { PFty_opt (PFty_item ()) },
+ .ret_ty = PFty_opt (PFty_xs_double ()) } },
+ .alg = PFbui_tijah_ftfun_score }
+
+#endif
+
+
, { .loc = 0 }
};
Index: ns.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/semantics/ns.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- ns.c 7 May 2009 14:28:44 -0000 1.45
+++ ns.c 5 Nov 2009 16:24:00 -0000 1.46
@@ -6,12 +6,12 @@
* Resolve XML namespaces (NS) in the abstract syntax tree (this is
* mainly based on W3C XQuery, 4.1 and W3C XML Namespaces).
*
- * Walk the abstract syntax tree to
+ * Walk the abstract syntax tree to
*
* (1) test if qualified names (QNames) refer to NS being actually in scope,
* and
* (2) attach URIs associated with used NS prefixes.
- *
+ *
* During the tree walk, we detect and handle the following NS-relevant
* XQuery constructs:
*
@@ -104,27 +104,27 @@
* prior declaration) in XQuery, see W3C XQuery, 4.12
*/
/** Predefined namespace `xml' for any query */
-PFns_t PFns_xml =
- { .prefix = "xml",
+PFns_t PFns_xml =
+ { .prefix = "xml",
.uri = "http://www.w3.org/XML/1998/namespace" };
/** Predefined namespace `xs' (XML Schema) for any query */
-PFns_t PFns_xs =
- { .prefix = "xs",
+PFns_t PFns_xs =
+ { .prefix = "xs",
.uri = "http://www.w3.org/2001/XMLSchema" };
/** Predefined namespace `xsi' (XML Schema Instance) for any query */
-PFns_t PFns_xsi =
- { .prefix = "xsi",
+PFns_t PFns_xsi =
+ { .prefix = "xsi",
.uri = "http://www.w3.org/2001/XMLSchema-instance" };
/** XQuery default function namespace (fn:...). */
PFns_t PFns_fn =
- { .prefix = "fn",
+ { .prefix = "fn",
.uri = "http://www.w3.org/2005/xpath-functions" };
/** Predefined namespace `xdt' (XPath Data Types) for any query */
-PFns_t PFns_xdt =
+PFns_t PFns_xdt =
{ .prefix = "xdt",
.uri = "http://www.w3.org/2003/11/xpath-datatypes" };
/** Predefined namespace `local' (XQuery Local Functions) for any query */
-PFns_t PFns_local =
+PFns_t PFns_local =
{ .prefix = "local",
.uri = "http://www.w3.org/2005/xquery-local-functions" };
/**
@@ -141,29 +141,38 @@
* XQuery operator namespace (op:...)
* (see W3C XQuery 1.0 and XPath 2.0 Function and Operators, 1.5).
*
- * This namespace is not accessible for the user
+ * This namespace is not accessible for the user
* (see W3C XQuery F&O, 1.5).
*/
-PFns_t PFns_op = { .prefix = "op",
+PFns_t PFns_op = { .prefix = "op",
.uri = "http://www.w3.org/2002/08/xquery-operators" };
-/**
+#ifdef HAVE_PFTIJAH
+/**
+ * XQuery full-text search operator namespace (fts:...)
+ */
+PFns_t PFns_fts = { .prefix = "fts",
+ .uri = "http://www.w3.org/TR/xpath-full-text-10/" };
+#endif
+
+
+/**
* Pathfinder's namespace for additional non-'fn' functions.
- */
-PFns_t PFns_lib = { .prefix = "pf",
+ */
+PFns_t PFns_lib = { .prefix = "pf",
.uri = "http://www.pathfinder-xquery.org/" };
-/**
+/**
* Pathfinder's namespace for additional tijah functions.
- */
-PFns_t PFns_tijah = { .prefix = "tijah",
+ */
+PFns_t PFns_tijah = { .prefix = "tijah",
.uri = "http://dbappl.cs.utwente.nl/pftijah/" };
-/**
+/**
* Pathfinder's namespace for XRPC extension.
- */
-PFns_t PFns_xrpc = { .prefix = "xrpc",
+ */
+PFns_t PFns_xrpc = { .prefix = "xrpc",
.uri = "http://monetdb.cwi.nl/XQuery" };
#ifdef HAVE_GEOXML
@@ -182,14 +191,16 @@
.uri = "http://dbappl.cs.utwente.nl/pxmlsup/" };
#endif
-/**
+
+
+/**
* Pathfinder's own internal NS (pf:...).
* Note that the prefix contains a character that cannot be entered in
- * a query.
+ * a query.
*
* This namespace is not accessible for the user.
- */
-PFns_t PFns_pf = { .prefix = "#pf",
+ */
+PFns_t PFns_pf = { .prefix = "#pf",
.uri = "http://www.pathfinder-xquery.org/internal/" };
/**
@@ -314,7 +325,7 @@
}
-/**
+/**
* NS equality (URI-based, then prefix-based):
* two NS with different prefixes are considered equal if they are bound
* to the same URI (see, W3C XQuery, 4.1).
@@ -328,7 +339,7 @@
PFns_eq (PFns_t ns1, PFns_t ns2)
{
/* NS equality is principally based on URI equality, so this is what
- * we test for first:
+ * we test for first:
*/
if (ns1.uri) {
if (ns2.uri)
@@ -340,7 +351,7 @@
if (ns2.uri)
return 1;
- /* two unbound (URI-less) NS are deliberately assumed to be equal
+ /* two unbound (URI-less) NS are deliberately assumed to be equal
* if their prefixes coincide:
*/
if (ns1.prefix) {
@@ -355,17 +366,17 @@
else
return 0;
}
-
+
}
/**
- * Collect and apply namespace declaration attributes
+ * Collect and apply namespace declaration attributes
* (W3C Namespaces):
*
* (1) xmlns:loc=ns locally (for the owning element) define
* NS prefix `loc:...' |-> ns
* (ns is required to be a literal string)
- *
+ *
* (2) xmlns=ns locally (for the owning element) re-define
* the default element NS
* (ns is required to be a literal string,
@@ -383,7 +394,7 @@
PFpnode_t *next = R(c);
assert (c);
-
+
switch (c->kind) {
case p_contseq:
@@ -392,7 +403,7 @@
if (L(c)->kind == p_attr) {
/* abstract syntax tree layout:
*
- * attr
+ * attr
* / \
* tag-ns:loc v
*/
@@ -418,8 +429,8 @@
* "xmlns":loc exprseq
* / \
* lit_str empty_seq
- *
- */
+ *
+ */
if ((R(a)->kind == p_exprseq
|| R(a)->kind == p_contseq) &&
RL(a)->kind == p_lit_str &&
@@ -431,7 +442,7 @@
/* finally remove this NS declaration attribute */
*c = *R(c);
-
+
/*
* visit the "same" node again in the next
* iteration (we have just overwritten it)
@@ -458,17 +469,17 @@
* Namespaces, 5.2), W3C XQuery, 4.1
*
* abstract syntax tree layout:
- *
+ *
* attr (a)
* / \
* "xmlns" exprseq
* / \
* lit_str empty_seq
*
- * content
+ * content
* / \ or nil
- * "ns"-lit_str nil
- */
+ * "ns"-lit_str nil
+ */
switch (R(a)->kind) {
case p_empty_seq:
/*
@@ -523,7 +534,7 @@
}
/**
- * Recursively walk abstract syntax tree to resolve NS usage.
+ * Recursively walk abstract syntax tree to resolve NS usage.
*
* @param n current abstract syntax tree node
*/
@@ -583,6 +594,9 @@
#ifdef HAVE_PROBXML
ns_add (PFns_pxmlsup);
#endif
+#ifdef HAVE_PFTIJAH
+ ns_add (PFns_fts);
+#endif
ns_add (PFns_fn);
fns = PFns_fn;
@@ -609,7 +623,7 @@
case p_fns_decl:
/*
- * default function namespace = "foo"
+ * default function namespace = "foo"
*
* abstract syntax tree layout:
*
@@ -623,7 +637,7 @@
case p_ens_decl:
/*
- * default element namespace = "foo"
+ * default element namespace = "foo"
*
* abstract syntax tree layout:
*
@@ -637,7 +651,7 @@
case p_ns_decl:
/*
- * declare namespace ns = "foo"
+ * declare namespace ns = "foo"
* import schema namespace ns = "foo" [at "url"]
*
* abstract syntax tree layout:
@@ -680,7 +694,7 @@
if (! new_ns.uri)
PFoops_loc (OOPS_BADNS, n->loc,
- "unknown namespace in qualified function name %s",
+ "unknown namespace in qualified function name %s",
PFqname_raw_str (n->sem.qname_raw));
n->sem.qname = PFqname (new_ns, n->sem.qname_raw.loc);
@@ -755,8 +769,8 @@
case p_req_name:
/*
- * This is the QName specification in an XPath location step.
- *
+ * This is the QName specification in an XPath location step.
+ *
* The spec says: ``An unprefixed QName, when used as a name
* test on an axis whose principal node kind is element, has
* the namespace URI of the default element/type namespace in
@@ -863,7 +877,7 @@
if (! new_ns.uri)
PFoops_loc (OOPS_BADNS, n->loc,
- "unknown namespace in qualified function name %s",
+ "unknown namespace in qualified function name %s",
PFqname_raw_str (n->sem.qname_raw));
n->sem.qname = PFqname (new_ns, n->sem.qname_raw.loc);
@@ -932,7 +946,7 @@
/*
* if element comes with a literal tag name resolve NS usage,
- * for computed tags skip ahead
+ * for computed tags skip ahead
*/
assert (L(n));
if (L(n)->kind == p_tag) {
@@ -946,7 +960,7 @@
L(n)->sem.qname = PFqname (new_ns, L(n)->sem.qname_raw.loc);
}
- else
+ else
ns_resolve (L(n));
/* NS resolution in element content c */
@@ -965,7 +979,7 @@
*
* attr
* / \
- * tag-ns:loc v
+ * tag-ns:loc v
*/
/*
@@ -1058,12 +1072,15 @@
#ifdef HAVE_PROBXML
ns_add (PFns_pxmlsup);
#endif
+#ifdef HAVE_PFTIJAH
+ ns_add (PFns_fts);
+#endif
/* bring the function and operator NS into scope
* and make fn:... the default function NS
*/
ns_add (PFns_fn);
-
+
fns = PFns_fn;
/* ``undefine'' the default element NS */
@@ -1083,7 +1100,7 @@
PFns_resolve (PFpnode_t *root)
{
/* initiate the actual NS resolution */
- ns_resolve (root);
+ ns_resolve (root);
}
/* vim:set shiftwidth=4 expandtab: */
Index: varscope.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/semantics/varscope.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- varscope.c 7 May 2009 14:29:07 -0000 1.22
+++ varscope.c 5 Nov 2009 16:24:00 -0000 1.23
@@ -9,8 +9,8 @@
* a stack-type environment, variable scoping is checked. On any occurence of
*
* - a @c flwr, @c some or @c every node, or a function declaration
- * node, the current variable environment is saved and restored
- * after the node has been processed. The variables are bound only within
+ * node, the current variable environment is saved and restored
+ * after the node has been processed. The variables are bound only within
* the rightmost subtree of the node.
*
* - a @c typeswitch node, the leftmost child is processed (which may
@@ -27,8 +27,8 @@
* @c struct is pushed onto the variabel environment stack.
* If we find a variable of the same name on the stack (i.e., in
* scope), issue a warning about variable reuse. Note that
- * a @c bind node may bring into scope up to two variables
- * (positional variables in @c for).
+ * a @c bind node may bring into scope up to two variables
+ * (positional variables in @c for).
*
* - a variable usage, the stack is scanned top down for the first
* occurence of a variable with the same name. If the variable is
@@ -115,7 +115,7 @@
/**
* Push a new variable onto the variable environment stack.
*
- * @param n variable to push onto the stack.
+ * @param n variable to push onto the stack.
* @return Status code as described in pathfinder/oops.c
*/
static void
@@ -131,12 +131,12 @@
assert (varname);
if (! (var = PFnew_var (*varname)))
- PFoops (OOPS_OUTOFMEM,
+ PFoops (OOPS_OUTOFMEM,
"allocation of new variable failed");
/* If we find a variable of the same name on the stack (i.e., in scope),
- * issue a warning (the user might mistake an XQuery clause like
- * `let $x := $x + 1' for an imperative variable update).
+ * issue a warning (the user might mistake an XQuery clause like
+ * `let $x := $x + 1' for an imperative variable update).
*/
if (PFscope_lookup (var_env, *varname))
PFinfo_loc (OOPS_WARN_VARREUSE, n->loc, "$%s", PFqname_str (*varname));
@@ -191,70 +191,70 @@
* to report them all to the user.
*/
var = find_var (n->sem.qname);
-
+
if (!var) {
PFinfo_loc (OOPS_UNKNOWNVAR, n->loc,
"$%s", PFqname_str (n->sem.qname));
scoping_failed = true;
}
-
+
n->sem.var = var;
n->kind = p_var;
-
+
break;
-
- case p_flwr:
+
+ case p_flwr:
/* flwr
* / | | \
* binds o p e
*
- * (1) save current variable environment
- * (2) process variable bindings
+ * (1) save current variable environment
+ * (2) process variable bindings
* (3) process o `order by', p `where', and e `return' clauses
* (4) restore variable environment
*/
-
+
/* (1) */
PFscope_open (var_env);
-
+
/* (2) */
scope (n->child[0]);
-
+
/* (3) */
scope (n->child[1]);
-
+
/* (4) */
PFscope_close (var_env);
-
+
break;
-
- case p_some:
- case p_every:
+
+ case p_some:
+ case p_every:
/* some/every
* / \
* binds e
*
- * (1) save current variable environment
- * (2) process variable bindings
+ * (1) save current variable environment
+ * (2) process variable bindings
* (3) process quantifier body e `satifies' clause
* (4) restore variable environment
*/
-
+
/* (1) */
PFscope_open (var_env);
-
+
/* (2) */
scope (n->child[0]);
-
+
/* (3) */
scope (n->child[1]);
-
+
/* (4) */
PFscope_close (var_env);
-
+
break;
-
- case p_fun_decl:
+
+ case p_fun_decl:
/* fun_decl
* / \
* fun_sig e
@@ -262,28 +262,28 @@
* params t
*
*
- * (1) save current variable environment
+ * (1) save current variable environment
* (2) process function parameters
* (3) process function body e
* (4) restore variable environment
*/
-
+
/* (1) */
PFscope_open (var_env);
-
+
/* (2) */
scope (n->child[0]);
-
+
/* (3) */
scope (n->child[1]);
-
+
/* (4) */
PFscope_close (var_env);
-
+
break;
-
- case p_bind:
- /* bind
+
+ case p_bind: if(n->child[0]->child[0]->child[0]->kind == p_varref){
+ /* bind
* / \
* vars e for $v as t at $i in e
* / \ some $v as t satisfies e
@@ -297,7 +297,7 @@
* (2) bring v into scope
* (3) bring i into scope (if present)
*/
-
+
/*
* Raise an error if positional variable and bound
* variable have the same name, e.g.
@@ -316,7 +316,7 @@
PFqname_str (n->child[0]->child[1]->sem.qname));
}
}
-
+
/* (1) */
scope (n->child[1]);
@@ -326,41 +326,141 @@
&& n->child[0]->child[0]->child[0]->kind == p_varref);
push (n->child[0]->child[0]->child[0]);
-
+
/* (3) */
assert (n->child[0] && n->child[0]->child[1]);
if (n->child[0]->child[1]->kind == p_varref)
push (n->child[0]->child[1]);
+ } else {
+ /* bind
+ * / \
+ * vars e for $v as t at $i score $s in e
+ * / \ some $v as t satisfies e
+ * vars s
+ * / \
+ * var_type i
+ * / \
+ * v t
+ *
+ * (i and s may be nil: no positional or score vars for some/every)
+ *
+ * (1) process e (v, i, s not yet visible in e)
+ * (2) bring v into scope
+ * (3) bring i into scope (if present)
+ * (4) bring s into scope (if present)
+ */
+
+ /*
+ * Raise an error if positional variable and bound
+ * variable have the same name, e.g.
+ *
+ * for $x at $x in e return e'
+ */
+ if (n->child[0]->child[0]->child[1]->kind == p_varref) {
+ if (!PFqname_eq
(n->child[0]->child[0]->child[0]->child[0]->sem.qname,
+ n->child[0]->child[0]->child[1]->sem.qname)) {
+ PFoops_loc (OOPS_VARREDEFINED, n->loc,
+ "it is illegal to use the same name for "
+ "positional and binding variable (`for $%s "
+ "at $%s ...')",
+ PFqname_str
(n->child[0]->child[0]->child[0]->child[0]
+ ->sem.qname),
+ PFqname_str
(n->child[0]->child[0]->child[1]->sem.qname));
+ }
+ }
+
+ /*
+ * Raise an error if score variable and bound
+ * variable have the same name, e.g.
+ *
+ * for $x score $x in e return e'
+ */
+ if (n->child[0]->child[1]->kind == p_varref) {
+ if (!PFqname_eq
(n->child[0]->child[0]->child[0]->child[0]->sem.qname,
+ n->child[0]->child[1]->sem.qname)) {
+ PFoops_loc (OOPS_VARREDEFINED, n->loc,
+ "it is illegal to use the same name for "
+ "positional and binding variable (`for $%s "
+ "at $%s ...')",
+ PFqname_str
(n->child[0]->child[0]->child[0]->child[0]
+ ->sem.qname),
+ PFqname_str (n->child[0]->child[1]->sem.qname));
+ }
+ }
+
+
+ /* (1) */
+ scope (n->child[1]);
+
+ /* (2) */
+ assert (n->child[0] && n->child[0]->child[0]
+ && n->child[0]->child[0]->child[0]
+ && n->child[0]->child[0]->child[0]->child[0]
+ && n->child[0]->child[0]->child[0]->child[0]->kind ==
p_varref);
+
+ push (n->child[0]->child[0]->child[0]->child[0]);
+
+ /* (3) */
+ assert (n->child[0] && n->child[0]->child[0]
+ && n->child[0]->child[0]->child[1]);
+
+ if (n->child[0]->child[0]->child[1]->kind == p_varref)
+ push (n->child[0]->child[0]->child[1]);
+
+ /* (4) */
+ assert (n->child[0] && n->child[0]->child[1]);
+
+ if (n->child[0]->child[1]->kind == p_varref)
+ push (n->child[0]->child[1]);
+ }
break;
- case p_let:
+ case p_let: if (n->child[0]->kind == p_varref){
+
/* let
* / \
- * var_type e let $v as t := e
+ * v e let score $v := e
+ *
+ * (1) process e (score variable v not yet visible in e)
+ * (2) bring v into scope
+ */
+
+ /* (1) */
+ scope (n->child[1]);
+
+ /* (2) */
+ assert (n->child[0] && n->child[0]->kind == p_varref);
+
+ push (n->child[0]);
+
+ } else {
+ /* let
+ * / \
+ * var_type e let $v as t := e
* / \
* v t
*
* (1) process e (v not yet visible in e)
* (2) bring v into scope
*/
-
+
/* (1) */
scope (n->child[1]);
-
+
/* (2) */
assert (n->child[0] && n->child[0]->child[0]
&& n->child[0]->child[0]->kind == p_varref);
push (n->child[0]->child[0]);
-
+ }
break;
case p_param: /* function parameter */
/* Abstract syntax tree layout:
*
- * param
+ * param
* / \ declare function ... (..., t v, ...)
* t v
*/
@@ -380,7 +480,7 @@
* v t
*
*/
-
+
/* occurrence of a branch variable is optional */
assert (n->child[0] && n->child[0]->child[0]);
@@ -392,7 +492,7 @@
/* visit the case branch e itself */
assert (n->child[1]);
-
+
scope (n->child[1]);
PFscope_close (var_env);
@@ -555,7 +655,7 @@
switch (n->kind) {
case p_lib_mod:
- {
+ {
/* back up variable environment */
PFscope_t *old_var_env = var_env;
Index: typecheck.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/semantics/typecheck.brg,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- typecheck.brg 15 Oct 2009 13:54:33 -0000 1.82
+++ typecheck.brg 5 Nov 2009 16:24:00 -0000 1.83
@@ -176,6 +176,9 @@
/* Pathfinder extension: XRPC */
%term xrpc = 76 /**< XRPC calls: "execute at" */
+ /* Associated For variable holders */
+%term vars = 77 /**< variable pair (position. var + score. var)
of a for */
+
%%
Query: main (FunctionDecls, CoreExpr) = 1 (10);
@@ -302,6 +305,25 @@
/* Pathfinder extension: XRPC */
CoreExpr: xrpc (CoreExpr, CoreExpr) = 88 (10);
+/*full-text support*/
+OptBindExpr: for_ (forbind (forvars (var,
+
vars (nil, nil)),
+ CoreExpr),
+ OptBindExpr) = 89 (10);
+OptBindExpr: for_ (forbind (forvars (var,
+
vars (var, nil)),
+ CoreExpr),
+ OptBindExpr) = 90 (10);
+
+OptBindExpr: for_ (forbind (forvars (var,
+
vars (nil, var)),
+ CoreExpr),
+ OptBindExpr) = 91 (10);
+OptBindExpr: for_ (forbind (forvars (var,
+
vars (var, var)),
+ CoreExpr),
+ OptBindExpr) = 92 (10);
+
%%
/** Type of a core tree node */
@@ -449,7 +471,7 @@
case 5:
TY(p) = *PFty_simplify (L(p)->sem.flwr.quantifier (TY(R(p))));
break;
-
+
/* OptBindExpr: for_ (forbind (forvars (var, nil),
CoreExpr),
OptBindExpr) */
@@ -1282,6 +1304,289 @@
TY(p) = TY(R(p));
break;
+
+ /* OptBindExpr: for_ (forbind (forvars (var,
+
vars (nil, nil)),
+ CoreExpr),
+ OptBindExpr) */
+ case 89:
+ { /* TOPDOWN */
+
+ /* W3C XQuery, 5.8.2
+ *
+ * E |- CoreExpr : t1 E[Var : prime (t1)] |- CoreExpr : t2
+ * -------------------------------------------------------------
+ * for_ (Var, nil, nil, CoreExpr, OptBindExpr) : t2 . quantifier
(t1)
+ */
+ PFty_t t1;
+
+ /* nil : none */
+ TY(LLRL(p)) = PFty_none ();
+ TY(LLRR(p)) = PFty_none ();
+
+ /* E |- CoreExpr : t1 */
+ reduce (kids[0], nts[0]);
+ t1 = TY(LR(p));
+
+ /*
+ * The specs prohibit the (statically typed) empty sequence
+ * in many places. (see XQuery FS, beginning of Section 4)
+ */
+ if (PFty_subtype (t1, PFty_empty ()))
+ PFoops (OOPS_TYPECHECK,
+ "binding sequence in a for clause has static "
+ "type `empty'");
+
+ /*
+ * XQuery Update Facility disallows updates in the `for'
+ * part.
+ */
+ if (!PFty_disjoint (PFty_stmt (),
+ PFty_prime (PFty_defn (t1))))
+ PFoops (OOPS_TYPECHECK,
+ "err:XUST0101: binding sequence may not contain "
+ "an updating expression (has type `%s')",
+ PFty_str (t1));
+
+ /* sanity check */
+ if (!PFty_subtype (t1, PFty_star (PFty_item ())))
+ PFoops (OOPS_TYPECHECK,
+ "illegal binding in for clause, cannot iterate over "
+ "type `%s'",
+ PFty_str (t1));
+
+ /* Var : prime (t1) */
+ TY(LLL(p)) = *PFty_simplify (PFty_prime (PFty_defn (t1)));
+
+ /* Var1 should now have a sensible type (not `none') */
+ assert (PFty_subtype (TY(LLL(p)), PFty_star (PFty_item ())));
+
+ /* E[Var : prime (t1)] |- CoreExpr : t2 */
+ assert (LLL(p)->sem.var);
+ TY( LLL(p)->sem.var ) = TY(LLL(p));
+ reduce (kids[1], nts[1]);
+
+ p->sem.flwr.quantifier = PFty_quantifier
+ (R(p)->sem.flwr.quantifier (
+ PFty_defn (t1)));
+
+ } break;
+
+ /* OptBindExpr: for_ (forbind (forvars (var,
+
vars (var, nil)),
+ CoreExpr),
+ OptBindExpr) */
+ case 90:
+ { /* TOPDOWN */
+
+ /* W3C XQuery, 5.8.2
+ *
+ * E |- CoreExpr : t1
+ * E[Var1:prime (t1), Var2:xs:integer] |- OptBindExpr : t2
+ * --------------------------------------------------------------
+ * for_ (Var1, Var2, nil, CoreExpr, CoreExpr) : t2 . quantifier
(t1)
+ */
+ PFty_t t1;
+
+ /* E |- CoreExpr : t1 */
+ reduce (kids[0], nts[0]);
+ t1 = TY(LR(p));
+
+ /*
+ * The specs prohibit the (statically typed) empty sequence
+ * in many places. (see XQuery FS, beginning of Section 4)
+ */
+ if (PFty_subtype (t1, PFty_empty ()))
+ PFoops (OOPS_TYPECHECK,
+ "binding sequence in a for clause has static "
+ "type `empty'");
+
+ /*
+ * XQuery Update Facility disallows updates in the `for'
+ * part.
+ */
+ if (!PFty_disjoint (PFty_stmt (),
+ PFty_prime (PFty_defn (t1))))
+ PFoops (OOPS_TYPECHECK,
+ "err:XUST0101: binding sequence may not contain "
+ "an updating expression (has type `%s')",
+ PFty_str (t1));
+
+ /* sanity check */
+ if (!PFty_subtype (t1, PFty_star (PFty_item ())))
+ PFoops (OOPS_TYPECHECK,
+ "illegal binding in for clause, cannot iterate over "
+ "type `%s'",
+ PFty_str (t1));
+
+ /* Var2 : xs:integer */
+ TY(LLRL(p)) = PFty_xs_integer ();
+ assert (LLRL(p)->sem.var);
+ TY( LLRL(p)->sem.var ) = TY(LLRL(p));
+
+ /* Var3 : nil */
+ TY(LLRR(p)) = PFty_none ();;
+
+ /* Var1 : prime (t1) */
+ TY(LLL(p)) = *PFty_simplify (PFty_prime (PFty_defn (t1)));
+
+ /* Var1 should now have a sensible type (not `none') */
+ assert (PFty_subtype (TY(LLL(p)), PFty_star (PFty_item ())));
+
+ /* E[Var1 : prime (t1), Var2 : xs:integer] |- CoreExpr : t2 */
+ assert (LLL(p)->sem.var);
+ TY( LLL(p)->sem.var ) = TY(LLL(p));
+ reduce (kids[1], nts[1]);
+
+ p->sem.flwr.quantifier = PFty_quantifier
+ (R(p)->sem.flwr.quantifier (PFty_defn (t1)));
+
+ } break;
+
+ /* OptBindExpr: for_ (forbind (forvars (var,
+
vars (nil, var)),
+ CoreExpr),
+ OptBindExpr) */
+ case 91:
+ { /* TOPDOWN */
+
+ /* W3C XQuery, 5.8.2
+ *
+ * E |- CoreExpr : t1 E[Var : prime (t1)] |- CoreExpr : t2
+ * -------------------------------------------------------------
+ * for_ (Var, nil, Var3, CoreExpr, OptBindExpr) : t2 . quantifier
(t1)
+ */
+ PFty_t t1;
+
+ /* nil : none */
+ TY(LLRL(p)) = PFty_none ();
+
+ /* E |- CoreExpr : t1 */
+ reduce (kids[0], nts[0]);
+ t1 = TY(LR(p));
+
+ /*
+ * The specs prohibit the (statically typed) empty sequence
+ * in many places. (see XQuery FS, beginning of Section 4)
+ */
+ if (PFty_subtype (t1, PFty_empty ()))
+ PFoops (OOPS_TYPECHECK,
+ "binding sequence in a for clause has static "
+ "type `empty'");
+
+ /*
+ * XQuery Update Facility disallows updates in the `for'
+ * part.
+ */
+ if (!PFty_disjoint (PFty_stmt (),
+ PFty_prime (PFty_defn (t1))))
+ PFoops (OOPS_TYPECHECK,
+ "err:XUST0101: binding sequence may not contain "
+ "an updating expression (has type `%s')",
+ PFty_str (t1));
+
+ /* sanity check */
+ if (!PFty_subtype (t1, PFty_star (PFty_item ())))
+ PFoops (OOPS_TYPECHECK,
+ "illegal binding in for clause, cannot iterate over "
+ "type `%s'",
+ PFty_str (t1));
+
+ /* Var3 : xs:double */
+ TY(LLRR(p)) = PFty_xs_double ();
+ assert (LLRR(p)->sem.var);
+ TY( LLRR(p)->sem.var ) = TY(LLRR(p));
+
+ /* Var : prime (t1) */
+ TY(LLL(p)) = *PFty_simplify (PFty_prime (PFty_defn (t1)));
+
+ /* Var1 should now have a sensible type (not `none') */
+ assert (PFty_subtype (TY(LLL(p)), PFty_star (PFty_item ())));
+
+ /* E[Var : prime (t1)] |- CoreExpr : t2 */
+ assert (LLL(p)->sem.var);
+ TY( LLL(p)->sem.var ) = TY(LLL(p));
+ reduce (kids[1], nts[1]);
+
+ p->sem.flwr.quantifier = PFty_quantifier
+ (R(p)->sem.flwr.quantifier (
+ PFty_defn (t1)));
+
+ } break;
+
+ /* OptBindExpr: for_ (forbind (forvars (var,
+
vars (var, var)),
+ CoreExpr),
+ OptBindExpr) */
+ case 92:
+ { /* TOPDOWN */
+
+ /* W3C XQuery, 5.8.2
+ *
+ * E |- CoreExpr : t1
+ * E[Var1:prime (t1), Var2:xs:integer] |- OptBindExpr : t2
+ * --------------------------------------------------------------
+ * for_ (Var1, Var2, Var3, CoreExpr, CoreExpr) : t2 . quantifier
(t1)
+ */
+ PFty_t t1;
+
+ /* E |- CoreExpr : t1 */
+ reduce (kids[0], nts[0]);
+ t1 = TY(LR(p));
+
+ /*
+ * The specs prohibit the (statically typed) empty sequence
+ * in many places. (see XQuery FS, beginning of Section 4)
+ */
+ if (PFty_subtype (t1, PFty_empty ()))
+ PFoops (OOPS_TYPECHECK,
+ "binding sequence in a for clause has static "
+ "type `empty'");
+
+ /*
+ * XQuery Update Facility disallows updates in the `for'
+ * part.
+ */
+ if (!PFty_disjoint (PFty_stmt (),
+ PFty_prime (PFty_defn (t1))))
+ PFoops (OOPS_TYPECHECK,
+ "err:XUST0101: binding sequence may not contain "
+ "an updating expression (has type `%s')",
+ PFty_str (t1));
+
+ /* sanity check */
+ if (!PFty_subtype (t1, PFty_star (PFty_item ())))
+ PFoops (OOPS_TYPECHECK,
+ "illegal binding in for clause, cannot iterate over "
+ "type `%s'",
+ PFty_str (t1));
+
+ /* Var2 : xs:integer */
+ TY(LLRL(p)) = PFty_xs_integer ();
+ assert (LLRL(p)->sem.var);
+ TY( LLRL(p)->sem.var ) = TY(LLRL(p));
+
+ /* Var3 : xs:double */
+ TY(LLRR(p)) = PFty_xs_double ();
+ assert (LLRR(p)->sem.var);
+ TY( LLRR(p)->sem.var ) = TY(LLRR(p));
+
+ /* Var1 : prime (t1) */
+ TY(LLL(p)) = *PFty_simplify (PFty_prime (PFty_defn (t1)));
+
+ /* Var1 should now have a sensible type (not `none') */
+ assert (PFty_subtype (TY(LLL(p)), PFty_star (PFty_item ())));
+
+ /* E[Var1 : prime (t1), Var2 : xs:integer] |- CoreExpr : t2 */
+ assert (LLL(p)->sem.var);
+ TY( LLL(p)->sem.var ) = TY(LLL(p));
+ reduce (kids[1], nts[1]);
+
+ p->sem.flwr.quantifier = PFty_quantifier
+ (R(p)->sem.flwr.quantifier (PFty_defn (t1)));
+
+ } break;
+
default:
PFoops (OOPS_FATAL, "untranslated expression '%s'",
PFtypecheck_string[rule]);
Index: normalize.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/semantics/normalize.brg,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- normalize.brg 7 May 2009 14:28:39 -0000 1.27
+++ normalize.brg 5 Nov 2009 16:24:00 -0000 1.28
@@ -208,6 +208,13 @@
%term seed = 128
%term xrpc = 129
%term docmgmt_ty = 130
+%term ftcontains = 131
+%term ftfilter = 132
+%term ftignore = 133
+%term ftor = 134
+%term ftand = 135
+%term ftmildnot = 136
+%term ftnot = 137
%%
@@ -417,22 +424,22 @@
AndExpr: ComparisonExpr = 118 (10);
AndExpr: and (ComparisonExpr, AndExpr) = 119 (10);
-ComparisonExpr: RangeExpr = 120 (10);
-ComparisonExpr: eq (RangeExpr, RangeExpr) = 121 (10);
-ComparisonExpr: ne (RangeExpr, RangeExpr) = 122 (10);
-ComparisonExpr: lt (RangeExpr, RangeExpr) = 123 (10);
-ComparisonExpr: le (RangeExpr, RangeExpr) = 124 (10);
-ComparisonExpr: gt (RangeExpr, RangeExpr) = 125 (10);
-ComparisonExpr: ge (RangeExpr, RangeExpr) = 126 (10);
-ComparisonExpr: val_eq (RangeExpr, RangeExpr) = 127 (10);
-ComparisonExpr: val_ne (RangeExpr, RangeExpr) = 128 (10);
-ComparisonExpr: val_lt (RangeExpr, RangeExpr) = 129 (10);
-ComparisonExpr: val_le (RangeExpr, RangeExpr) = 130 (10);
-ComparisonExpr: val_gt (RangeExpr, RangeExpr) = 131 (10);
-ComparisonExpr: val_ge (RangeExpr, RangeExpr) = 132 (10);
-ComparisonExpr: is (RangeExpr, RangeExpr) = 133 (10);
-ComparisonExpr: ltlt (RangeExpr, RangeExpr) = 135 (10);
-ComparisonExpr: gtgt (RangeExpr, RangeExpr) = 136 (10);
+ComparisonExpr: FTContainsExpr = 120 (10);
+ComparisonExpr: eq (FTContainsExpr, FTContainsExpr) = 121 (10);
+ComparisonExpr: ne (FTContainsExpr, FTContainsExpr) = 122 (10);
+ComparisonExpr: lt (FTContainsExpr, FTContainsExpr) = 123 (10);
+ComparisonExpr: le (FTContainsExpr, FTContainsExpr) = 124 (10);
+ComparisonExpr: gt (FTContainsExpr, FTContainsExpr) = 125 (10);
+ComparisonExpr: ge (FTContainsExpr, FTContainsExpr) = 126 (10);
+ComparisonExpr: val_eq (FTContainsExpr, FTContainsExpr) = 127 (10);
+ComparisonExpr: val_ne (FTContainsExpr, FTContainsExpr) = 128 (10);
+ComparisonExpr: val_lt (FTContainsExpr, FTContainsExpr) = 129 (10);
+ComparisonExpr: val_le (FTContainsExpr, FTContainsExpr) = 130 (10);
+ComparisonExpr: val_gt (FTContainsExpr, FTContainsExpr) = 131 (10);
+ComparisonExpr: val_ge (FTContainsExpr, FTContainsExpr) = 132 (10);
+ComparisonExpr: is (FTContainsExpr, FTContainsExpr) = 133 (10);
+ComparisonExpr: ltlt (FTContainsExpr, FTContainsExpr) = 135 (10);
+ComparisonExpr: gtgt (FTContainsExpr, FTContainsExpr) = 136 (10);
RangeExpr: AdditiveExpr = 137 (10);
RangeExpr: range (RangeExpr, RangeExpr) = 138 (10);
@@ -617,7 +624,53 @@
FunctionDeclaration: fun_decl (fun_sig (OptParamList_,
seq_ty (docmgmt_ty (nil))),
OptExpr) = 249 (10);
+
+/* Pathfinder full-text support */
+FTContainsExpr: RangeExpr = 250 (10);
+FTContainsExpr: ftcontains (RangeExpr, FTSelectionExpr) = 251 (10);
+FTContainsExpr: ftcontains (RangeExpr, FTFilterExpr) = 252 (10);
+
+VarPosBinding: bind (vars (vars (var_type
+ (varref,
+ OptTypeDeclaration_),
+ OptPositionalVar_),
+ OptFTScoreVar_),
+ OptExpr) = 253 (10);
+
+
+OptFTScoreVar_: nil = 254 (10);
+OptFTScoreVar_: FTScoreVar = 255 (10);
+
+FTScoreVar: varref = 256 (10);
+
+FTFilterExpr: ftfilter (FTSelectionExpr,
+ FTIgnoreOption) = 257 (10);
+FTIgnoreOption: ftignore (UnionExpr) = 258 (10);
+
+FTSelectionExpr: FTOrExpr = 259 (10);
+
+FTOrExpr: FTAndExpr = 260 (10);
+FTOrExpr: ftor (FTOrExpr, FTAndExpr) = 261 (10);
+
+FTAndExpr: FTMildNot = 262 (10);
+FTAndExpr: ftand (FTAndExpr, FTMildNot) = 263 (10);
+
+FTMildNot: FTUnaryNot = 264 (10);
+FTMildNot: ftmildnot (FTMildNot, FTUnaryNot) = 265 (10);
+
+FTUnaryNot: FTPrimaryWithOptions = 266 (10);
+FTUnaryNot: ftnot (FTPrimaryWithOptions) = 267 (10);
+FTPrimaryWithOptions: FTPrimaryExpr = 268 (10);
+
+FTPrimaryExpr: FTWordsExpr = 269 (10);
+FTPrimaryExpr: FTSelectionExpr = 270 (10);
+
+FTWordsExpr: FTWordsValueExpr = 271 (10);
+
+FTWordsValueExpr: Literal = 272 (10);
+
+LetBinding_: let (varref, OptExpr) = 273 (10);
%%
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins