This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
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 "}"
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)
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.
(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.
Can understand the rationale behind current design. OK to close this issue.
Closing bug because commenter has not objected to the resolution posted and more than two weeks have passed.