w3c / sparql-query

https://w3c.github.io/sparql-query/
Other
7 stars 0 forks source link

The SPARQL grammar allows `()` in reified triples and triple terms. #157

Open afs opened 5 days ago

afs commented 5 days ago

In SPARQL, () is a parser token NIL.

It allows () to be used as a term in its own right, not just in RDF collections (....). e.g. in VALUES and expressions. this is in SPARQL 1.1.

The grammar in the current editors working draft allows:

<< _:b ex:x () >>
<<( _:b ex:x () )>>

Turtle is different. Parentheses only occur in collection ::= '(' object* ')'.

The SPARQL grammar changed to align with Turtle for reified triples and triple terms.

From: https://github.com/w3c/rdf-tests/issues/140#issuecomment-2376596889

kasei commented 2 days ago

I think I'd be OK forbidding this in triple terms and reified triples, as the use of () as a term is an affordance for dealing with collections of unknown size. But if we're not supporting non-empty collections, I don't see a need to support NIL, even if it avoids the primary issue of TT/RF that might syntactically represent multiple triples. And alignment with Turtle here would be good (though it seems the current Turtle spec draft does support collections in reified triples, which I think w3c/rdf-turtle#71 seeks to fix).

afs commented 2 days ago

NIL seems to be a SPARQL 1.0-ism - an easy way to handle () as zero-lists and as zero argument functions.

But it is allowed in VALUES which has to call it out specially. It is also treated in special ways in functions.

Not for this PR - maybe the grammar can be made more regular (and still the same language) by removing NIL as a terminal and replacing it by LPAREN/RPAREN.

Recorded as: https://github.com/w3c/sparql-query/issues/160