<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>22767</bug_id>
          
          <creation_ts>2013-07-23 09:18:30 +0000</creation_ts>
          <short_desc>Default priority calculation for parenthesized patterns</short_desc>
          <delta_ts>2014-05-15 14:00:32 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XSLT 3.0</component>
          <version>Working drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Vitaliy">vyudenkov</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          <cc>abel.braaksma</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>91122</commentid>
    <comment_count>0</comment_count>
    <who name="Vitaliy">vyudenkov</who>
    <bug_when>2013-07-23 09:18:30 +0000</bug_when>
    <thetext>The &quot;XSL Transformations (XSLT) Version 3.0&quot; working draft specification of 10 July 2012 defines EBNF for patterns, which allows parenthesized patterns.

At the same time in section 6.5 doesn&apos;t have special rule for parenthesized expression, the only:

     11. In all other cases, the priority is +0.5.

Therefore, if I use pattern &quot;/&quot;, then it&apos;s default priority calculated as &quot;-0.5&quot;. But if to write match=&quot;(/)&quot; - the priority will be &quot;+0.5&quot;.
It confuses me, because I thought that &quot;/&quot; and &quot;(/)&quot; could be used as equivalent expressions.


Similar misunderstanding could be when I use union in parenthesized expression, for example: patterns &quot;a | b&quot; vs &quot;(a | b)&quot;:

The first pattern is an equivalent to two separate template rules: match=&quot;a&quot; and match =&quot;b&quot;. And each separate template rule has it&apos;s own default priority - &quot;0&quot;.
The second pattern we could not devide into two separate template rules, therefore the default priority is calculated to whole pattern and equals &quot;+0.5&quot;.

Thank you, 
Vitaliy</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91130</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2013-07-23 10:55:36 +0000</bug_when>
    <thetext>Your understanding of the current specification is correct.

Basing the default priority on the syntactic form of the pattern has always had the potential to create anomalies, for example many people are caught out that match=&quot;//a&quot; has a different priority to match=&quot;a&quot;. We have to find a compromise between keeping the rules simple and easy to explain, and giving intuitive results for people who do not know the rules.

It would certainly be possible to have a rule that redundant outer parentheses are stripped before applying the other rules.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91135</commentid>
    <comment_count>2</comment_count>
    <who name="Vitaliy">vyudenkov</who>
    <bug_when>2013-07-23 13:29:37 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; Your understanding of the current specification is correct.
&gt; 
&gt; Basing the default priority on the syntactic form of the pattern has always
&gt; had the potential to create anomalies, for example many people are caught
&gt; out that match=&quot;//a&quot; has a different priority to match=&quot;a&quot;. We have to find
&gt; a compromise between keeping the rules simple and easy to explain, and
&gt; giving intuitive results for people who do not know the rules.
&gt; 
&gt; It would certainly be possible to have a rule that redundant outer
&gt; parentheses are stripped before applying the other rules.

Thank you, for response.

Yes, probably a good solution just to remove unnecessary parentheses before default priority calculation.

Could be the pattern EBNF be simplified as following:

    Pattern30            ::= ParenthesizedPattern | Pattern

    Pattern              ::= PatternTerm ( (&apos;|&apos; | &apos;union&apos;) PatternTerm )*

    ParenthesizedPattern ::= &apos;(&apos; Pattern &apos;)&apos; 

    QualifiedPattern     ::= ParenthesizedPattern PredicateList

Thank you, 
Vitaliy</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91344</commentid>
    <comment_count>3</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2013-07-27 12:57:53 +0000</bug_when>
    <thetext>In the current internal WD, the following Note was added:

&quot;The rules are based on the raw syntax of the pattern as written. So, for example, enclosing a pattern in parentheses changes its priority; and the rule that a template rule with match=&quot;a|b&quot; is treated as two separate template rules does not apply if the pattern is written as match=&quot;(a|b)&quot;.&quot;

I&apos;m not sure whether the editor&apos;s intention was to expand on this or change it in a later draft.

This fixes the problem spec-wise, but I believe we can do better. It benefits both users and implementations if they are allowed to remove the redundant parenthesis, if and only if they encompass the whole expression.

Otherwise, we cannot rewrite (a | b) as a | b, which I think is odd and counter-intuitive, and removes the ability to expand that expression as multiple matching templates match=&quot;a&quot; and match=&quot;b&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91347</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2013-07-27 17:03:10 +0000</bug_when>
    <thetext>The paragraph was added as clarification of the existing rules, because when a reader of the spec says confusion and misunderstanding are possible then it&apos;s best to assume that they are right.

It doesn&apos;t prejudge whether we might be able to change/improve the rules.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91911</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2013-08-12 16:19:58 +0000</bug_when>
    <thetext>The WG resolved to add the following rule as the first rule in 6.5, which has the effect that redundant outer parentheses do not affect the semantics:

&lt;p&gt;If the top-level pattern is a ParenthesizedExprP then the outer parentheses are effectively stripped; these rules are applied recursively to the UnionExprP contained in the ParenthesizedExprP.&lt;/p&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>