The RDF 1.0 formal grammar is defined according to the pattern language of XDuce and the XML Schema Formalism.

The grammar presented here is namespace aware, in that QName symbols represent the expanded element or attribute name, and the namespace pattern represents the namespace URI of the current type. For example the pattern ~[namespace] matches any element which has a non null namespace URI, and ~[namespace["http://example.org#"]] matches any element in the "http://example.org#" namespace.

  1. namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  2. type RDF = rdf:RDF[obj*]
  3. type obj = description | container
  4. type description = 
    	rdf:Description[
    		idAboutAttr?,
    		bagIdAttr?,
    		propAttr?,
    		propertyElt*
    	] |
    	typedNode
  5. type container = sequence | bag | alternative
  6. type idAboutAttr = idAttr | aboutAttr
  7. type idAttr = @rdf:ID[ID]
  8. type aboutAttr = @rdf:about[URIreference]
  9. type propAttr = typeAttr | @~[namespace]
  10. type typeAttr = @rdf:type[URIreference]
  11. type propertyElt =
        ~[namespace,idAttr?,value] |
        ~[namespace,idAttr?,parseLiteral,literal] |
        ~[namespace,idAttr?,parseResource,propertyElt*] |
        ~[namespace,idRefAttr?,bagIdAttr?,propAttr*]
    
  12. type typedNode = ~[namespace,idAboutAttr?,badIdAttr?,propAttr*,propertyElt*]
  13. type idRefAttr = (idAttr?,resourceAttr)
  14. type value = obj | String
  15. type sequence = 
    	rdf:Seq[
    		idAttr?,
    		memberAttr*,
    		member*
    	]
    
  16. type bag = rdf:Bag[idAttr?,memberAttr*,member*]
  17. type alternative = rdf:Alt[idAttr?,(memberAttr+,member*)|member+]
  18. type member = referencedItem | inlineItem
  19. type referencedItem = rdf:li[resourceAttr]
  20. type inlineItem = 
    	rdf:li[@xml:lang?,
    		(value |
    		(parseLiteral,literal) |
    		(parseResource,propertyElt*))
    	]
    
  21. type parseLiteral = @rdf:parseType["Literal"]
  22. type parseResource = @rdf:parseType["Resource"]
  23. type literal = any*
  24. type memberAttr = @~[ namespace[rdf], name["_",Integer], string ]
  25. type bagIdAttr = @rdf:bagId[ID]
  26. type resourceAttr = @rdf:resource[URIreference]
  27. type any = ~[@~,(String|any)*]

Jonathan Borden, Tufts University, The Open Healthcare Group June 20, 2001

Jonathan Borden ENS ENI