w3c / rdf-turtle

https://w3c.github.io/rdf-turtle/
Other
4 stars 4 forks source link

Order of Prefix Declarations #59

Open Edkamb opened 2 months ago

Edkamb commented 2 months ago

As far as I can tell, the normative part does not sufficiently specify how the order of prefix declaration interacts with the triples that use the prefix, in particular what if a prefix is declared after its first use. For example:

pref:infiv pref:pred pref:obj .
@prefix pref: <www.smolang.org/test#> .

The TTL parsers I tested (rapper, OWL-API) reject the above, but I see nothing in the normative part that forbids it: It is certainly defined by grammar and the part about parser state (7.1) does not specify order for the namespaces, only that "Outside of a prefixID production" a declared prefix will be replaced (not "After"). I think this should be clarified explicitly, Example 9 also does not cover this case.

afs commented 2 months ago

I agree it isn't as clear as it might be.

The grammar rules for triples work on IRIs,not prefixed names. e.g.

[10] subject ::= iri | BlankNode | collection

so any prefixed name must have been translated for the rule to match. A prefixed name does not match the "subject" rule.

The section Parser State defines how the map is maintained.

The second and third rule arguments (PNAME_NS and IRIREF) in the prefixID production assign a namespace name (IRIREF) for the prefix (PNAME_NS).

Combined with

When used in a PrefixedName production, the iri is the value in the namespaces map corresponding to the first argument of the rule.

the prefix declaration must be before its use.

How might the text be improved?

Edkamb commented 2 months ago

The IRI production refers to prefixed names, so subject would match:

[135s] iri ::= IRIREF | PrefixedName [136s] PrefixedName ::= PNAME_LN | PNAME_NS

The parser state part is, independent of the above, not clear about order, it states

Outside of a prefixID production, any PNAME_NS is substituted with the namespace.

But it should be clarified that "Outside" refers to "Last prefixID before the PNAME_NS".