<?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>2405</bug_id>
          
          <creation_ts>2005-10-21 14:51:15 +0000</creation_ts>
          <short_desc>QueryBody for MainModule can be very difficult to parse</short_desc>
          <delta_ts>2007-02-25 23:48:01 +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>XQuery 1.0</component>
          <version>Working drafts</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>INVALID</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="Henry Luo">henryluo</reporter>
          <assigned_to name="Don Chamberlin">chamberl</assigned_to>
          
          
          <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>6847</commentid>
    <comment_count>0</comment_count>
    <who name="Henry Luo">henryluo</who>
    <bug_when>2005-10-21 14:51:15 +0000</bug_when>
    <thetext>Current XQuery grammar for main module is
MainModule ::= Prolog QueryBody
which allows an expr to follow the prolog.
However because the XQuery grammar for expr is complicated, it can be very
difficult for the parser to determine when it has reach the last prolog declaration.

E.g. 
declare namespace namespace = &quot;http://example.com&quot;; 
declare union &lt;union&gt;for gibberish {
   for $for in for return &lt;for&gt;***div div&lt;/for&gt;
}&lt;/union&gt;, 
if(if) then then else else- +-++-**-* instance 
of element(*)* * * **---++div- div -div

Is it better to wrap the QueryBody in a special main() function, and make the
main() function the entry point of execution?
i.e. MainModule ::= Prolog &quot;function main()&quot; &quot;{&quot; QueryBody &quot;}&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6849</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2005-10-21 15:13:36 +0000</bug_when>
    <thetext>You can tell when you&apos;ve reached the end of the prolog if the next two tokens
aren&apos;t one of the pairs that can start a prolog declaration, for example
&quot;declare default&quot; or &quot;import schema&quot; or &quot;declare function&quot;.

I&apos;m afraid it&apos;s not good timing for a comment like this. If it had come during
the last call period, the WG would have happily given it a hearing. Given that
there are at least a dozen implementors who have solved this problem, it&apos;s
unlikely that you&apos;re now going to convince the WG to change the language. In any
case, the language should be designed for the convenience of users, not of
implementors.

The solution you propose would lose the nice property that every valid XPath
expression is also a valid query. It would also add a lot of red-tape for people
wanting to write simple one-line queries, perhaps embedded in a Java program or
written interactively in a dialog box. And there are plenty of other cases where
parsing needs to be a little bit context-sensitive (as your &quot;gibberish&quot; example
demonstrates).

Michael Kay (personal response)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6856</commentid>
    <comment_count>2</comment_count>
    <who name="Henry Luo">henryluo</who>
    <bug_when>2005-10-21 15:55:17 +0000</bug_when>
    <thetext>I think one of the problem with
  MainModule ::= Prolog QueryBody
is on forward compatibility.

If current parsers treat whatever prolog that they cannot recognize as
QueryBody, then it will be difficult to add new prologs without breaking
existing parsers.

May be a less drastical way is to 
have extra &quot;;&quot; to surround the prologs, as
   MainModule ::= &quot;;&quot; Prolog &quot;;&quot; QueryBody  |  QueryBody  
so that the parser depend on the extra &quot;;&quot; rather than the first two tokens to
separate Prolog from QueryBody.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6871</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2005-10-23 07:37:45 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; I think one of the problem with
&gt;   MainModule ::= Prolog QueryBody
&gt; is on forward compatibility.
&gt; 
&gt; If current parsers treat whatever prolog that they cannot recognize as
&gt; QueryBody, then it will be difficult to add new prologs without breaking
&gt; existing parsers.

If a future version of XQuery introduces new kinds of PrologDecl, then that will
(rather inescapably) &quot;break&quot; existing parsers. Tweaking the grammar to make the
start of the QueryBody easier to recognize isn&apos;t going to change that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6872</commentid>
    <comment_count>4</comment_count>
    <who name="Henry Luo">henryluo</who>
    <bug_when>2005-10-23 08:15:08 +0000</bug_when>
    <thetext>Can understand the rationale behind current design. 
OK to close this issue.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>14156</commentid>
    <comment_count>5</comment_count>
    <who name="Jim Melton">jim.melton</who>
    <bug_when>2007-02-25 23:48:01 +0000</bug_when>
    <thetext>Closing bug because commenter has not objected to the resolution posted and more than two weeks have passed.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>