This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 30015 - TransformWithExpr and ArrowExpr grammar entries conflict for Update Facility 3.1
Summary: TransformWithExpr and ArrowExpr grammar entries conflict for Update Facility 3.1
Status: NEW
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Update 3.1 (show other bugs)
Version: Working drafts
Hardware: PC Linux
: P2 major
Target Milestone: ---
Assignee: Jonathan Robie
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-19 10:50 UTC by Reece H. Dunn
Modified: 2016-11-21 07:17 UTC (History)
1 user (show)

See Also:


Attachments

Description Reece H. Dunn 2016-11-19 10:50:20 UTC
The Update Facility 3.0 grammar contains the constructs:

[96] CastExpr ::= TransformWithExpr ( "cast" "as" SingleType )?
[97] TransformWithExpr ::= UnaryExpr ( "transform" "with" "{" Expr? "}" )?
[98] UnaryExpr ::= ("-" | "+")* ValueExpr

The XQuery 3.1 Candidate Recommendation grammar contains the constructs:

[95] CastExpr ::= ArrowExpr ( "cast" "as" SingleType )?
[96] ArrowExpr ::= UnaryExpr ( "=>" ArrowFunctionSpecifier ArgumentList )*
[97] UnaryExpr ::= ("-" | "+")* ValueExpr

As such, it is unclear what order TransformWithExpr and ArrowExpr should be applied in.

Using `ArrowExpr > TransformWithExpr` allows:

    $x => upper-case() transform with {}

Using `TransformWithExpr > ArrowExpr` allows:

    $x transform with {} => upper-case()

From this, using `ArrowExpr > TransformWithExpr` would make more sense. That would mean that the Update Facility 3.1 grammar would be:

[..] CastExpr ::= ArrowExpr ( "cast" "as" SingleType )?
[..] ArrowExpr ::= TransformWithExpr ( "=>" ArrowFunctionSpecifier ArgumentList )*
[..] TransformWithExpr ::= UnaryExpr ( "transform" "with" "{" Expr? "}" )?
[..] UnaryExpr ::= ("-" | "+")* ValueExpr
Comment 1 Michael Dyck 2016-11-19 14:51:06 UTC
Your suggested EBNF allows
    $x transform with {} => upper-case()
and not
    $x => upper-case() transform with {}

I.e., it's the solution that you refer to as `TransformWithExpr > ArrowExpr`,
whereas you said that `ArrowExpr > TransformWithExpr` would make more sense.

So it's unclear which you actually prefer.
Comment 2 Reece H. Dunn 2016-11-19 16:03:29 UTC
Oops :). You are correct on the ordering from the grammar. Thinking about this some more, I am not sure what is the best ordering.

The Update Facility 3.0 specification (in section 5.7) states that:

    N transform with { U }          [1]

is equivalent to:

    copy $v := N                    [2]
    modify $v!(U)
    return $v

This would mean that:

    N => A transform with { U }     [3]

would be equivalent to:

    copy $v := N => A               [4]
    modify $v!(U)
    return $v

while:

    N transform with { U } => A     [5]

would be equivalent to:

    copy $v := N                    [6]
    modify $v!(U)
    return $v => A

Thus, on a second look, I am not sure which of [4] or [6] would be most useful.
Comment 3 Reece H. Dunn 2016-11-19 18:00:32 UTC
Another option would be to place ArrowExpr and TransformWithExpr at the same level:

    CastExpr ::= (ArrowExpr | TransformWithExpr) ( "cast" "as" SingleType )?
    ArrowExpr ::= UnaryExpr ( "=>" ArrowFunctionSpecifier ArgumentList )*
    TransformWithExpr ::= UnaryExpr ( "transform" "with" "{" Expr? "}" )?

This would mean that ArrowExpr and TransformWithExpr cannot be used in the same expression without parenthesis. This would probably be the best option, as otherwise there is the issue of how to handle multiple arrows, as in:

    $x => f() transform with {} => g()

A use case for mixing the two would be in something like:

    $x => doc() transform with { rename node . as "abc" }

which could be done with parenthesis if required:

    ($x => doc()) transform with { rename node . as "abc" }
Comment 4 Michael Dyck 2016-11-19 22:56:44 UTC
I should point out that there is currently no great enthusiasm (that we know of) for doing the work to take Update 3.0 to Recommendation status. An Update *3.1* spec would be even less likely. So the point of this bug is probably moot. Unless you know of someone planning to add an Update Facility to an XQuery 3.1 processor?
Comment 5 Reece H. Dunn 2016-11-20 07:43:47 UTC
I am working on developer tools (syntax highlighting, validation, etc.) for XQuery (the xquery-intellij-plugin for the IntelliJ IDE). I have recently added support for parsing XQuery 3.1, and am now working on supporting Update Facility 3.0, which is why I encountered this issue.

I have currently opted to implement option 3, as that is compatible with both specifications and does not introduce any additional functionality. If that changes with an Update Facility 3.1 in the future, I can make the necessary changes at that point.
Comment 6 Michael Dyck 2016-11-21 03:09:46 UTC
According to the minutes of meeting #596 (2015-01-27), when the WG decided to change the precedence of TransformWithExpr wrt the XQuery 3.0 grammar, there was also some discussion of where it should fit wrt the XQuery *3.1* grammar (specifically ArrowExpr). The upshot is that, in our grammar/parser/applet system, if you request the 'xquery31' base with the 'update30' extension, you get the productions:
  CastExpr ::= TransformWithExpr ("cast" "as" SingleType)?
  TransformWithExpr ::= ArrowExpr ("transform" "with" "{" Expr? "}")?
  ArrowExpr ::= UnaryExpr ("=>" ArrowFunctionSpecifier ArgumentList)*
  UnaryExpr ::= ...

Note that, while this answers your original question, it isn't really an official answer, because xquery31+update30 isn't an authorized combination of specifications. (If Update 3.1 ever comes to pass, it might decide to place TransformWithExpr differently.) However, the likelihood seems high that it's the closest thing you'll ever get to an official answer.
Comment 7 Reece H. Dunn 2016-11-21 07:17:26 UTC
Thanks for looking this up. Until an Update 3.1 specification is created, I am going to stick with using:

    CastExpr ::= (ArrowExpr | TransformWithExpr) ( "cast" "as" SingleType )?

As this is consistent with xquery31 and update30 without adding any additional behaviour that would be generated by using the constructs from the W3C internal grammar applet.