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 26324 - XQuery 3.0's PostfixExpr is not properly represented in XQueryX 3.0
Summary: XQuery 3.0's PostfixExpr is not properly represented in XQueryX 3.0
Status: CLOSED INVALID
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQueryX 3.0 (show other bugs)
Version: Recommendation
Hardware: All All
: P2 major
Target Milestone: ---
Assignee: Jim Melton
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-13 22:51 UTC by Jim Melton
Modified: 2014-07-14 08:10 UTC (History)
1 user (show)

See Also:


Attachments

Description Jim Melton 2014-07-13 22:51:40 UTC
In XQuery 3.0, the following expression is apparently valid:
   12(1,2)[3]
and is represented by the following BNF:
   PathExpr ::= ...
              | RelativePathExpr
   RelativePathExpr ::= StepExpr
   StepExpr ::= PostfixExpr | ...
   PostfixExpr ::= PrimaryExpr (Predicate | ArgumentList)*
   PrimaryExpr ::= Literal | ...

(Note: I don't claim that I understand why anybody would write such an expression, but it is apparently valid.)

The expressions is accepted by our syntax checker and produces the following parse tree:

|START [1:0 - 1:10]
|   QueryList [1:0 - 1:10]
|      Module [1:0 - 1:10]
|         MainModule [1:0 - 1:10]
|            Prolog [1:0 - 0:0]
|            QueryBody [1:0 - 1:10]
|               Expr [1:0 - 1:10]
|                  PathExpr [1:0 - 1:10]
|                     PostfixExpr [1:0 - 1:10]
|                        IntegerLiteral 12 [2:1 - 1:2]
|                        ArgumentList [2:1 - 1:7]
|                           Argument [2:3 - 1:4]
|                              PathExpr [2:3 - 1:4]
|                                 PostfixExpr [2:3 - 1:4]
|                                    IntegerLiteral 1 [2:4 - 1:4]
|                           Argument [2:5 - 1:6]
|                              PathExpr [2:5 - 1:6]
|                                 PostfixExpr [2:5 - 1:6]
|                                    IntegerLiteral 2 [2:6 - 1:6]
|                        Predicate [2:7 - 1:10]
|                           Expr [2:8 - 1:9]
|                              PathExpr [2:8 - 1:9]
|                                 PostfixExpr [2:8 - 1:9]
|                                    IntegerLiteral 3 [2:9 - 1:9]

Note particularly the appearance of "PostfixExpr" in the parse tree. 

However, in the XQueryX translation produced by the syntax checker, that same expression transforms to:

<?xml version="1.0"?>
<xqx:module xmlns:xqx="http://www.w3.org/2005/XQueryX"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.w3.org/2005/XQueryX
                                http://www.w3.org/2005/XQueryX/xqueryx.xsd">
  <xqx:mainModule>
    <xqx:queryBody>
      <xqx:pathExpr>
        <xqx:stepExpr>
          <xqx:filterExpr>
            <xqx:dynamicFunctionInvocationExpr>
              <xqx:functionItem>
                <xqx:integerConstantExpr>
                  <xqx:value>12</xqx:value>
                </xqx:integerConstantExpr>
              </xqx:functionItem>
              <xqx:arguments>
                <xqx:integerConstantExpr>
                  <xqx:value>1</xqx:value>
                </xqx:integerConstantExpr>
                <xqx:integerConstantExpr>
                  <xqx:value>2</xqx:value>
                </xqx:integerConstantExpr>
              </xqx:arguments>
            </xqx:dynamicFunctionInvocationExpr>
          </xqx:filterExpr>
          <xqx:predicates>
            <xqx:integerConstantExpr>
              <xqx:value>3</xqx:value>
            </xqx:integerConstantExpr>
          </xqx:predicates>
        </xqx:stepExpr>
      </xqx:pathExpr>
    </xqx:queryBody>
  </xqx:mainModule>
</xqx:module>

In this case, please note that the <xqx:functionItem> is an <xqx:integerConstantExpr> (12) followed by <xqx:arguments> (1 and 2).

The XQueryX 3.0 stylesheet would (does) transform to the original expression:
   12(1,2)[3]
But that is more an accident than a planned chain of events. 

DOES THE XQUERYX COMMUNITY BELIEVE THAT THIS SHOULD BE "FIXED"?  I presume that the fix would be to permit XQueryX code that looks something like this:

<?xml version="1.0"?>
<xqx:module xmlns:xqx="http://www.w3.org/2005/XQueryX"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.w3.org/2005/XQueryX
                                http://www.w3.org/2005/XQueryX/xqueryx.xsd">
  <xqx:mainModule>
    <xqx:queryBody>
      <xqx:pathExpr>
        <xqx:stepExpr>
          <xqx:postfixExpr>
            <xqx:integerConstantExpr>
              <xqx:value>12</xqx:value>
            </xqx:integerConstantExpr>
            <xqx:arguments>
              <xqx:integerConstantExpr>
                <xqx:value>1</xqx:value>
              </xqx:integerConstantExpr>
              <xqx:integerConstantExpr>
                <xqx:value>2</xqx:value>
              </xqx:integerConstantExpr>
            </xqx:arguments>
          </xqx:postfixExpr>
          <xqx:predicates>
            <xqx:integerConstantExpr>
              <xqx:value>3</xqx:value>
            </xqx:integerConstantExpr>
          </xqx:predicates>
        </xqx:stepExpr>
      </xqx:pathExpr>
    </xqx:queryBody>
  </xqx:mainModule>
</xqx:module>

(Note the use of <xqx:postfixExpr>, which does not appear at all in the XQueryX 3.0 schema or stylesheet.)

I believe that I have no choice but to make this kind of fix in XQueryX 3.1 because of the new alternatives in the production for PostfixExpr, and I *think* (I'm still working on it) I can do so with full XQueryX 3.0 compatibility with or without "fixing" this problem in XQueryX 3.0. 

Guidance, please!!
Comment 1 Jim Melton 2014-07-13 23:31:31 UTC
Upon additional consideration, especially after re-reading XQuery 3.0, section 3.2 "Postfix Expressions", last paragraph:

   An expression (other than a raw EQName) followed by an argument list in parentheses (that is, E1(E2, E3, ...)) is referred to as a dynamic function call. Its effect is to evaluate E1 to obtain a function, and then call that function, with E2, E3, ... as arguments. Dynamic function calls are described in 3.2.2 Dynamic Function Call.

I have concluded that the specific case of 12(1,2) is a useless artifact of allowing far more useful expressions such as $x(1,2) (which is a DynamicFunctionInvocation). 

The cost in "fixing" the case of 12(1,2) to be a (useless) Postfix Expression instead of a Dynamic Function Invocation is in no way worth the effort, particularly as it doesn't actually change any results. 

I am therefore marking this bug RESOLVED/INVALID and then marking it CLOSED. 

Sorry for the interruption.  Please carry on.
Comment 2 Michael Kay 2014-07-14 08:10:50 UTC
The expression 12(1) is syntactically valid but is always a type error (rather like the expression ("London"+1). So you're really asking a policy question: should XQueryX be able to represent every syntactically-valid XQuery expression, or should it only be required to represent expressions that have no static errors. (And then the sub-question, are type errors regarded as static errors for this purpose?)