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 2405 - QueryBody for MainModule can be very difficult to parse
Summary: QueryBody for MainModule can be very difficult to parse
Status: CLOSED INVALID
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQuery 1.0 (show other bugs)
Version: Working drafts
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Don Chamberlin
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-21 14:51 UTC by Henry Luo
Modified: 2007-02-25 23:48 UTC (History)
0 users

See Also:


Attachments

Description Henry Luo 2005-10-21 14:51:15 UTC
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 = "http://example.com"; 
declare union <union>for gibberish {
   for $for in for return <for>***div div</for>
}</union>, 
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 "function main()" "{" QueryBody "}"
Comment 1 Michael Kay 2005-10-21 15:13:36 UTC
You can tell when you've reached the end of the prolog if the next two tokens
aren't one of the pairs that can start a prolog declaration, for example
"declare default" or "import schema" or "declare function".

I'm afraid it'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's
unlikely that you'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 "gibberish" example
demonstrates).

Michael Kay (personal response)
Comment 2 Henry Luo 2005-10-21 15:55:17 UTC
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 ";" to surround the prologs, as
   MainModule ::= ";" Prolog ";" QueryBody  |  QueryBody  
so that the parser depend on the extra ";" rather than the first two tokens to
separate Prolog from QueryBody.
Comment 3 Michael Dyck 2005-10-23 07:37:45 UTC
(In reply to comment #2)
> 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.

If a future version of XQuery introduces new kinds of PrologDecl, then that will
(rather inescapably) "break" existing parsers. Tweaking the grammar to make the
start of the QueryBody easier to recognize isn't going to change that.
Comment 4 Henry Luo 2005-10-23 08:15:08 UTC
Can understand the rationale behind current design. 
OK to close this issue.
Comment 5 Jim Melton 2007-02-25 23:48:01 UTC
Closing bug because commenter has not objected to the resolution posted and more than two weeks have passed.