Bug 16197 - [XP30] Precedence of the Simple Map Operator
Summary: [XP30] Precedence of the Simple Map Operator
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XPath 3.0 (show other bugs)
Version: Last Call drafts
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Jonathan Robie
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
Depends on:
Reported: 2012-03-02 12:48 UTC by John Snelson
Modified: 2014-09-16 18:47 UTC (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description John Snelson 2012-03-02 12:48:48 UTC
I find the precedence of the simple map operator a little surprising in general use. For instance, this is valid syntax:

foo ! bar

But this is not valid syntax:

foo ! /bar

I think we should change the grammar to make this expression valid, as follows:

ValueExpr ::= ValidateExpr | SimpleMapExpr | ExtensionExpr

SimpleMapExpr ::= PathExpr ("!" PathExpr)*

PathExpr ::= ("/" RelativePathExpr?)
           | ("//" RelativePathExpr)
           | RelativePathExpr
RelativePathExpr ::= StepExpr (("/" | "//") StepExpr)*
Comment 1 John Snelson 2012-05-21 16:29:58 UTC
Actually this change would also affect the associativity of "!" with respect to "/". The current grammar has "/" and "!" at the same precedence, and left associative. Here's an example where that makes a difference:

let $doc := document { <a><b>1</b><a><b>2</b></a></a>,<a><b>3</b></a> }
  $doc // a ! descendant::b / text()

This is implicitly parameterized like this:

(($doc // a) ! descendant::b) / text()    -> ("1", "2", "3")

However my proposed change parameterizes it like this:

($doc // a) ! (descendant::b / text())    -> ("1", "2", "2", "3")

I believe that by using the "!" operator, the user has explicitly chosen not to have document ordering and duplicate removal applied to the result sequence. The latter precedence and associativity more closely matches this expectation.

Other more minor differences with my proposed change include the one in the bug description above, as well as allowing the following currently illegal syntax:

/ ! document-uri(.)
Comment 2 Michael Kay 2012-05-21 23:27:19 UTC
I think I'm persuaded. It seems that (apart from a syntactic interaction with edge cases involving lone-slash), the only impact is on expressions that use "/" to the right of "!". And it's hard to construct realistic examples where (under the current rules) such a use of "!" is usefully different from "/", given that the lhs of "/" has to be nodes, and the "/" does any document-ordering that the "!" might otherwise have prevented. So the current precedence rules don't allow you to do anything very useful, wheras the proposed precedence rules allow expressions such as

$page//@href ! doc(.)//title

where the fact that "!" doesn't do document-ordering is potentially useful.
Comment 3 Jonathan Robie 2012-06-12 15:28:07 UTC
I'm persuaded also. This example from Comment 1 was particularly convincing:

$doc // a ! descendant::b / text()
Comment 4 Jonathan Robie 2012-06-12 15:58:57 UTC
The Working Group agrees. We will make this change.