grammar N3Grammer rule document statements end rule statements (space / (statement / directive) space* ('.' space*)? )* end rule statement subject space+ property_list end rule subject node end rule verb ">-" prop "->" # has xxx of / "<-" prop "<-" # is xxx of # / # / operator # has operator:xxx of??? NOT IMPLMENTED / prop # has xxx of -- shorthand # / "has" prop # has xxx of # / "is" prop "of" # is xxx of / "a" # has rdf:type of # / "=" # has daml:equivaent of end rule prop node end rule node uri_ref / anonnode / 'this' end rule anonnode "[" space* property_list space* "]" # something which ... / "{" statementlist "}" # the statementlist itself as a resource / "(" nodelist ")" { def anonnode; true; end } end rule property_list verb space+ object_list space* ";" space+ property_list / verb space+ object_list / ":-" anonnode #to allow two anonymous forms to be given eg [ a :Truth; :- { :sky :color :blue } ] ) / ":-" anonnode ";" property_list / '.' end rule object_list object "," space* object_list / object end rule directive '@prefix' space+ nprefix:nprefix? ':' space+ uri_ref:uri_ref { def directive; true; end } end rule uri_ref qname / "<" uri:URI_Reference ">" end rule qname nprefix ":" localname / ':' localname end rule object subject / literal end rule literal (string_single / string_multi) ("^^<" uri:URI_Reference ">" / "@" language )? end rule language [a-z]+ ( "-" [a-z0-9]+ )* end rule localname fragid end rule URI_Reference [^{}<>]* end rule nprefix ((alpha / "_") alphanumeric*) end rule fragid alpha alphanumeric* end rule alpha [a-zA-Z] end rule alphanumeric alpha / [0-9] / "_" end rule space [ \t\n\r]+ / comment end rule comment '#' (![\n\r] .)* end # " constant-value-with-escaping " rule string_single '""' !["] / '"' string_single_char+ '"' end rule string_single_char !["\n\r] ( ("\\" [\\\"nrt] / ( "u" hexdigit hexdigit hexdigit hexdigit ) / ( "U" "00" hexdigit hexdigit hexdigit hexdigit hexdigit hexdigit) ) / .) end rule hexdigit [0-9a-fA-F] end # """ constant value with escaping including single or double occurrences of quotes and/or newlines """ rule string_multi '"""' string_multi_char* '"""' end rule string_multi_char !'"""' . # something like this; need to think about it some more end end