RE: what is the meaning of literals in step expressions?

I agree, and have given this feedback previously.
 
Fortunately, there are no restrictions on when during the compile phase your
implementation does static type analysis.  You can choose a more appropriate
grammar that enforces some type restrictions during parse time (before
static analysis).  Having done this myself, I'd have to say it's not
difficult to make a stricter grammar that still accepts every valid XQuery
but finds certain classes of static errors earlier.
 
Of course, if you opt to do only dynamic type analysis in your
implementation, then you're stuck with the loose grammar provided.
 
It's no different than the situation with XPath 1.0, whose grammar allowed
goofy expressions like @comment() and namespace::text().  Most
implementations I've seen work from a modified grammar that catches these
during parse time (and maps them into the empty sequence, since they're not
errors), instead of evaluating them as written.
 
Cheers,
 
michaelb
 
P.S.
To be clear, non-node literals are allowed in steps, just not with / and //.
For example, (1, 2)[3] is perfectly valid (resulting in the empty sequence).
 
-----Original Message-----
From: www-ql-request@w3.org [mailto:www-ql-request@w3.org] On Behalf Of
Howard Katz
Sent: Friday, July 04, 2003 9:11 AM
To: Kay, Michael; www-ql@w3.org
Subject: RE: what is the meaning of literals in step expressions?



Thanks for the clarification. The other viewpoint (not that I'm espousing
it, just pointing it out as a point of information) is that the more rules
the grammar enforces, the less the type system (and the poor implementer :-)
has to do.
Ta,
Howard

-----Original Message-----
From: www-ql-request@w3.org [mailto:www-ql-request@w3.org]On Behalf Of Kay,
Michael
Sent: Friday, July 04, 2003 7:47 AM
To: Howard Katz; www-ql@w3.org
Subject: RE: what is the meaning of literals in step expressions?



> 
> I just realized that the existing grammar allows expressions 
> such as "1/3", "//book/2", and "/bib//46.5/editor". Do 
> patterns such as these (with literals in step expressions) 
> have any valid semantic interpretation? What should an XQuery 
> implementation do on encountering such an expression? Thanks, Howard 
> 

The operands of "/" must be nodes, and literals are never nodes, so such
expressions will always give a type error. We have generally chosen not to
make the grammar enforce rules that are better enforced by the type system.
Writing 1/3 is just like writing "a"+"b", which is also a type error rather
than a syntax error.

Michael Kay 

Received on Friday, 4 July 2003 15:01:29 UTC