This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: XQuery repl + "document" not found when loading in Scheme mode(u sing XQeury from Scheme)
- From: Per Bothner <per at bothner dot com>
- To: "Hoehle, Joerg-Cyril" <Joerg-Cyril dot Hoehle at t-systems dot com>
- Cc: kawa at sources dot redhat dot com
- Date: Wed, 22 May 2002 11:06:20 -0700
- Subject: Re: XQuery repl + "document" not found when loading in Scheme mode(u sing XQeury from Scheme)
- References: <DFD875E85664D3118FA6080006277DE7058234C4@U8PN2.blf01.telekom.de>
Hoehle, Joerg-Cyril wrote:
> Can I call a function defined via
> "define function" in a .xql file
> from Scheme?
Yes, in principle, at least.
> #|kawa:3|# (descendent-or-self "<a>")
> <a>
> Calling descendent-or-self in Scheme looks a lot like the identity function!?
You'll get the same (correct) result from XQuery if the argument is
a child-less string. What result did you expect?
> #|kawa:1|# (load "xquerytest")
> gnu.mapping.UnboundSymbol: Unbound symbol document
Yep. The following should work:
(define document (static-field <gnu.kawa.xml.Document> 'document))
> Furthermore, it seems that the typical #|(---:3|# prompt is lost in the XQuery toplevel.
I just changed the XQuery prompt to look like an XQuery comment:
{--3--}
> I can only enter
> let $result := (document("file:i:/.../foo.xml")) return $result
> in a single line to the terminal, which is quite inconvenient for copy&paste
> and interactive sessions.
>
> xquery[1]: let $result := (document("file:i:/foo.xml"))
> xquery[2]: return $result
> <stdin>:2:1: missing 'return' clause
Actually, if you put pathenetheses around the expression, then you
can use multiple lines:
xquery[1]: (let $result := (document("file:i:/foo.xml"))
xquery[2]: return $result)
However, the parens shouldn't be need in this case, since the
parser knows that the 'let' is incomplete. I've attached a
patch to fix this.
> 3) I call (parse-xml-from-url "file:i:/...Example.xml")
> which outputs a (lots of (...))-looking list
> But it's just output?
No, it's data. Specifically, it's a a TreeList (a <document>).
> Hot to build a list from that, e.g. "pipe" it to the Scheme reader?
You can print it and then read it back, but it is better to use
the <document> object directly. Unfortunately, I haven't gotten around
to writing a nice Scheme API for this.
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/
--- XQParser.java~ Thu May 16 23:02:01 2002
+++ XQParser.java Wed May 22 10:57:36 2002
@@ -1686,6 +1696,7 @@
else
{
Expression cond;
+ nesting++;
if (curToken == OP_WHERE)
{
getRawToken();
@@ -1697,6 +1708,7 @@
}
else
cond = null;
+ nesting--;
boolean sawReturn = match("return");
if (! sawReturn && ! match("let") && ! match("for"))
return syntaxError("missing 'return' clause");
@@ -1757,7 +1769,9 @@
return syntaxError("missing ':=' in 'let' clause - "+curToken);
}
getRawToken();
+ nesting++;
Expression value = parseBinaryExpr(priority(OP_OR));
+ nesting--;
return parseFLWRExpression(isFor, name, value);
}