Discussion:
[xquery-talk] Error when using predicate after arrow operator
Joe Wicentowski
2017-04-13 19:09:32 UTC
Permalink
Hi all,

As I understand the arrow operator
(https://www.w3.org/TR/xquery-31/#id-arrow-operator), the following
query:

"1.2.3" => tokenize("\.")

is equivalent to:

tokenize("1.2.3", "\.")

If this is so, then can anyone shed light on why appending a predicate
to the former would raise an error but not so for the latter? In
Saxon, eXist, and BaseX, the following expression:

"1.2.3" => tokenize("\.")[. < "3"]

raises an error like:

XPST0003: Unexpected token "[" beyond end of query

whereas the pre-XQuery 3.1 approach:

tokenize("1.2.3", "\.")[. < "3"]

returns the results I'd expect:

("1", "2")

Thanks,
Joe
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
John Snelson
2017-04-13 19:44:01 UTC
Permalink
The equivalence holds for how it functionally behaves, not for what
grammar the parser allows. You need parentheses:

("1.2.3" => tokenize("\."))[. < "3"]


John
Post by Joe Wicentowski
Hi all,
As I understand the arrow operator
(https://www.w3.org/TR/xquery-31/#id-arrow-operator), the following
"1.2.3" => tokenize("\.")
tokenize("1.2.3", "\.")
If this is so, then can anyone shed light on why appending a predicate
to the former would raise an error but not so for the latter? In
"1.2.3" => tokenize("\.")[. < "3"]
XPST0003: Unexpected token "[" beyond end of query
tokenize("1.2.3", "\.")[. < "3"]
("1", "2")
Thanks,
Joe
_______________________________________________
http://x-query.com/mailman/listinfo/talk
--
John Snelson, Principal Engineer http://twitter.com/jpcs
MarkLogic Corporation http://www.marklogic.com

_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
Joe Wicentowski
2017-04-13 20:36:21 UTC
Permalink
Hi John,

Thanks for your reply. I had discovered that parentheses would allow the
query to complete without error, but I struggled to see what rule in the
spec my query violated. Now I see it: the predicate isn't valid in the
ArrowFunctionSpecifier, defined at
https://www.w3.org/TR/xquery-31/#doc-xquery31-ArrowFunctionSpecifier as:

EQName | VarRef | ParenthesizedExpr

So the parser sees the ParenthesizedExpr in my `tokenize("\.")` and then
chokes on the following character, the open square bracket.

Thanks for helping me see this!
Joe
Post by John Snelson
The equivalence holds for how it functionally behaves, not for what
("1.2.3" => tokenize("\."))[. < "3"]
John
Post by Joe Wicentowski
Hi all,
As I understand the arrow operator
(https://www.w3.org/TR/xquery-31/#id-arrow-operator), the following
"1.2.3" => tokenize("\.")
tokenize("1.2.3", "\.")
If this is so, then can anyone shed light on why appending a predicate
to the former would raise an error but not so for the latter? In
"1.2.3" => tokenize("\.")[. < "3"]
XPST0003: Unexpected token "[" beyond end of query
tokenize("1.2.3", "\.")[. < "3"]
("1", "2")
Thanks,
Joe
_______________________________________________
http://x-query.com/mailman/listinfo/talk
--
John Snelson, Principal Engineer http://twitter.com/jpcs
MarkLogic Corporation http://www.marklogic.com
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Michael Kay
2017-04-13 20:06:58 UTC
Permalink
The precedence table at

https://www.w3.org/TR/xquery-31/#id-precedence-order

shows that [] has higher precedence than =>

I don't remember the exact details of the deliberations that led to this decision, but I know we looked at a number of examples. One of them was that

-1 => abs()

should mean

(-1) => abs()

rather than

- (1 => abs())

which was the effect of the original proposal.

Michael Kay
Saxonica
Post by Joe Wicentowski
Hi all,
As I understand the arrow operator
(https://www.w3.org/TR/xquery-31/#id-arrow-operator), the following
"1.2.3" => tokenize("\.")
tokenize("1.2.3", "\.")
If this is so, then can anyone shed light on why appending a predicate
to the former would raise an error but not so for the latter? In
"1.2.3" => tokenize("\.")[. < "3"]
XPST0003: Unexpected token "[" beyond end of query
tokenize("1.2.3", "\.")[. < "3"]
("1", "2")
Thanks,
Joe
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk

Loading...