Draft final TriG grammar
authorAndy Seaborne <andy.seaborne@apache.org>
Sat, 31 Aug 2013 15:10:51 +0100
changeset 1039 4eba39a10bb1
parent 1038 e02d1a0b3bdb
child 1040 b922947aae74
Draft final TriG grammar
trig/trig-bnf.html
trig/trig.bnf
--- a/trig/trig-bnf.html	Sat Aug 31 15:10:04 2013 +0100
+++ b/trig/trig-bnf.html	Sat Aug 31 15:10:51 2013 +0100
@@ -1,31 +1,37 @@
 <table  class="grammar">
     <tbody class="grammar-productions">
-            <tr id="grammar-production-trigDoc" data-grammar-original="[1g] trigDoc ::= (graph_statement)*" data-grammar-expression="(&#x27;*&#x27;, (&#x27;id&#x27;, &#x27;graph_statement&#x27;))" >
+            <tr id="grammar-production-trigDoc" data-grammar-original="[1g] trigDoc   ::= ( directive | block )*" data-grammar-expression="(&#x27;*&#x27;, (&#x27;|&#x27;, [(&#x27;id&#x27;, &#x27;directive&#x27;), (&#x27;id&#x27;, &#x27;block&#x27;)]))" >
     <td>[1g]</td>
     <td><code>trigDoc</code></td>
     <td>::=</td>
-    <td><a href='#grammar-production-graph_statement'>graph_statement</a><code class='grammar-star'>*</code></td>
+    <td>(<a href='#grammar-production-directive'>directive</a> <code>| </code> <a href='#grammar-production-block'>block</a>)<code class='grammar-star'>*</code></td>
 </tr>
-            <tr id="grammar-production-graph_statement" data-grammar-original="[2g] graph_statement ::= directive| graph" data-grammar-expression="(&#x27;|&#x27;, [(&#x27;id&#x27;, &#x27;directive&#x27;), (&#x27;id&#x27;, &#x27;graph&#x27;)])" >
+            <tr id="grammar-production-block" data-grammar-original="[2g] block   ::=   triplesOrGraph| wrappedGraph| triples2| &quot;GRAPH&quot; ( iri | BlankNode ) wrappedGraph" data-grammar-expression="(&#x27;|&#x27;, [(&#x27;id&#x27;, &#x27;triplesOrGraph&#x27;), (&#x27;id&#x27;, &#x27;wrappedGraph&#x27;), (&#x27;id&#x27;, &#x27;triples2&#x27;), (&#x27;,&#x27;, [(&quot;&#x27;&quot;, &#x27;GRAPH&#x27;), (&#x27;|&#x27;, [(&#x27;id&#x27;, &#x27;iri&#x27;), (&#x27;id&#x27;, &#x27;BlankNode&#x27;)]), (&#x27;id&#x27;, &#x27;wrappedGraph&#x27;)])])" >
     <td>[2g]</td>
-    <td><code>graph_statement</code></td>
+    <td><code>block</code></td>
     <td>::=</td>
-    <td><a href='#grammar-production-directive'>directive</a> <code>| </code> <a href='#grammar-production-graph'>graph</a></td>
+    <td><a href='#grammar-production-triplesOrGraph'>triplesOrGraph</a> <code>| </code> <a href='#grammar-production-wrappedGraph'>wrappedGraph</a> <code>| </code> <a href='#grammar-production-triples2'>triples2</a> <code>| </code> "<code class='grammar-literal'>GRAPH</code>" (<a href='#grammar-production-iri'>iri</a> <code>| </code> <a href='#grammar-production-BlankNode'>BlankNode</a>) <a href='#grammar-production-wrappedGraph'>wrappedGraph</a></td>
 </tr>
-            <tr id="grammar-production-graph" data-grammar-original="[3g] graph ::= graphName? &quot;{&quot; triplesBlock? &quot;}&quot;" data-grammar-expression="(&#x27;,&#x27;, [(&#x27;?&#x27;, (&#x27;id&#x27;, &#x27;graphName&#x27;)), (&quot;&#x27;&quot;, &#x27;{&#x27;), (&#x27;?&#x27;, (&#x27;id&#x27;, &#x27;triplesBlock&#x27;)), (&quot;&#x27;&quot;, &#x27;}&#x27;)])" >
+            <tr id="grammar-production-triplesOrGraph" data-grammar-original="[3g] triplesOrGraph   ::=( iri | BlankNode ) ( wrappedGraph | predicateObjectList &#x27;.&#x27; )" data-grammar-expression="(&#x27;,&#x27;, [(&#x27;|&#x27;, [(&#x27;id&#x27;, &#x27;iri&#x27;), (&#x27;id&#x27;, &#x27;BlankNode&#x27;)]), (&#x27;|&#x27;, [(&#x27;id&#x27;, &#x27;wrappedGraph&#x27;), (&#x27;,&#x27;, [(&#x27;id&#x27;, &#x27;predicateObjectList&#x27;), (&quot;&#x27;&quot;, &#x27;.&#x27;)])])])" >
     <td>[3g]</td>
-    <td><code>graph</code></td>
+    <td><code>triplesOrGraph</code></td>
     <td>::=</td>
-    <td><a href='#grammar-production-graphName'>graphName</a>? '<code class='grammar-literal'>{</code>' <a href='#grammar-production-triplesBlock'>triplesBlock</a>? '<code class='grammar-literal'>}</code>'</td>
+    <td>(<a href='#grammar-production-iri'>iri</a> <code>| </code> <a href='#grammar-production-BlankNode'>BlankNode</a>) (<a href='#grammar-production-wrappedGraph'>wrappedGraph</a> <code>| </code> <a href='#grammar-production-predicateObjectList'>predicateObjectList</a> '<code class='grammar-literal'>.</code>')</td>
 </tr>
-            <tr id="grammar-production-graphName" data-grammar-original="[4g] graphName ::= iri| BlankNode" data-grammar-expression="(&#x27;|&#x27;, [(&#x27;id&#x27;, &#x27;iri&#x27;), (&#x27;id&#x27;, &#x27;BlankNode&#x27;)])" >
+            <tr id="grammar-production-triples2" data-grammar-original="[4g] triples2   ::=( blankNodePropertyList | collection ) predicateObjectList? &#x27;.&#x27;" data-grammar-expression="(&#x27;,&#x27;, [(&#x27;|&#x27;, [(&#x27;id&#x27;, &#x27;blankNodePropertyList&#x27;), (&#x27;id&#x27;, &#x27;collection&#x27;)]), (&#x27;?&#x27;, (&#x27;id&#x27;, &#x27;predicateObjectList&#x27;)), (&quot;&#x27;&quot;, &#x27;.&#x27;)])" >
     <td>[4g]</td>
-    <td><code>graphName</code></td>
+    <td><code>triples2</code></td>
     <td>::=</td>
-    <td><a href='#grammar-production-iri'>iri</a> <code>| </code> <a href='#grammar-production-BlankNode'>BlankNode</a></td>
+    <td>(<a href='#grammar-production-blankNodePropertyList'>blankNodePropertyList</a> <code>| </code> <a href='#grammar-production-collection'>collection</a>) <a href='#grammar-production-predicateObjectList'>predicateObjectList</a>? '<code class='grammar-literal'>.</code>'</td>
 </tr>
-            <tr id="grammar-production-triplesBlock" data-grammar-original="[5g] triplesBlock ::= triples (&#x27;.&#x27; triplesBlock?)?" data-grammar-expression="(&#x27;,&#x27;, [(&#x27;id&#x27;, &#x27;triples&#x27;), (&#x27;?&#x27;, (&#x27;,&#x27;, [(&quot;&#x27;&quot;, &#x27;.&#x27;), (&#x27;?&#x27;, (&#x27;id&#x27;, &#x27;triplesBlock&#x27;))]))])" >
+            <tr id="grammar-production-wrappedGraph" data-grammar-original="[5g] wrappedGraph   ::=&#x27;{&#x27; triplesBlock &#x27;}&#x27;" data-grammar-expression="(&#x27;,&#x27;, [(&quot;&#x27;&quot;, &#x27;{&#x27;), (&#x27;id&#x27;, &#x27;triplesBlock&#x27;), (&quot;&#x27;&quot;, &#x27;}&#x27;)])" >
     <td>[5g]</td>
+    <td><code>wrappedGraph</code></td>
+    <td>::=</td>
+    <td>'<code class='grammar-literal'>{</code>' <a href='#grammar-production-triplesBlock'>triplesBlock</a> '<code class='grammar-literal'>}</code>'</td>
+</tr>
+            <tr id="grammar-production-triplesBlock" data-grammar-original="[6g] triplesBlock   ::=   triples ( &#x27;.&#x27; triplesBlock? )?" data-grammar-expression="(&#x27;,&#x27;, [(&#x27;id&#x27;, &#x27;triples&#x27;), (&#x27;?&#x27;, (&#x27;,&#x27;, [(&quot;&#x27;&quot;, &#x27;.&#x27;), (&#x27;?&#x27;, (&#x27;id&#x27;, &#x27;triplesBlock&#x27;))]))])" >
+    <td>[6g]</td>
     <td><code>triplesBlock</code></td>
     <td>::=</td>
     <td><a href='#grammar-production-triples'>triples</a> ('<code class='grammar-literal'>.</code>' <a href='#grammar-production-triplesBlock'>triplesBlock</a>?)?</td>
@@ -48,17 +54,17 @@
     <td>::=</td>
     <td>'<code class='grammar-literal'>@base</code>' <a href='#grammar-production-IRIREF'>IRIREF</a> '<code class='grammar-literal'>.</code>'</td>
 </tr>
-            <tr id="grammar-production-sparqlPrefix" data-grammar-original="[28*] sparqlPrefix ::= [Pp][Rr][Ee][Ff][Ii][Xx] PNAME_NS IRIREF" data-grammar-expression="(&#x27;,&#x27;, [(&#x27;[&#x27;, &#x27;Pp&#x27;), (&#x27;[&#x27;, &#x27;Rr&#x27;), (&#x27;[&#x27;, &#x27;Ee&#x27;), (&#x27;[&#x27;, &#x27;Ff&#x27;), (&#x27;[&#x27;, &#x27;Ii&#x27;), (&#x27;[&#x27;, &#x27;Xx&#x27;), (&#x27;id&#x27;, &#x27;PNAME_NS&#x27;), (&#x27;id&#x27;, &#x27;IRIREF&#x27;)])" >
-    <td>[28*]</td>
+            <tr id="grammar-production-sparqlPrefix" data-grammar-original="[28a] sparqlPrefix ::= &quot;PREFIX&quot; PNAME_NS IRIREF" data-grammar-expression="(&#x27;,&#x27;, [(&quot;&#x27;&quot;, &#x27;PREFIX&#x27;), (&#x27;id&#x27;, &#x27;PNAME_NS&#x27;), (&#x27;id&#x27;, &#x27;IRIREF&#x27;)])" >
+    <td>[28a]</td>
     <td><code>sparqlPrefix</code></td>
     <td>::=</td>
-    <td>[<code class='grammar-chars'>Pp</code>] [<code class='grammar-chars'>Rr</code>] [<code class='grammar-chars'>Ee</code>] [<code class='grammar-chars'>Ff</code>] [<code class='grammar-chars'>Ii</code>] [<code class='grammar-chars'>Xx</code>] <a href='#grammar-production-PNAME_NS'>PNAME_NS</a> <a href='#grammar-production-IRIREF'>IRIREF</a></td>
+    <td>"<code class='grammar-literal'>PREFIX</code>" <a href='#grammar-production-PNAME_NS'>PNAME_NS</a> <a href='#grammar-production-IRIREF'>IRIREF</a></td>
 </tr>
-            <tr id="grammar-production-sparqlBase" data-grammar-original="[29*] sparqlBase ::= [Bb][Aa][Ss][Ee] IRIREF" data-grammar-expression="(&#x27;,&#x27;, [(&#x27;[&#x27;, &#x27;Bb&#x27;), (&#x27;[&#x27;, &#x27;Aa&#x27;), (&#x27;[&#x27;, &#x27;Ss&#x27;), (&#x27;[&#x27;, &#x27;Ee&#x27;), (&#x27;id&#x27;, &#x27;IRIREF&#x27;)])" >
-    <td>[29*]</td>
+            <tr id="grammar-production-sparqlBase" data-grammar-original="[29a] sparqlBase ::= &quot;BASE&quot; IRIREF" data-grammar-expression="(&#x27;,&#x27;, [(&quot;&#x27;&quot;, &#x27;BASE&#x27;), (&#x27;id&#x27;, &#x27;IRIREF&#x27;)])" >
+    <td>[29a]</td>
     <td><code>sparqlBase</code></td>
     <td>::=</td>
-    <td>[<code class='grammar-chars'>Bb</code>] [<code class='grammar-chars'>Aa</code>] [<code class='grammar-chars'>Ss</code>] [<code class='grammar-chars'>Ee</code>] <a href='#grammar-production-IRIREF'>IRIREF</a></td>
+    <td>"<code class='grammar-literal'>BASE</code>" <a href='#grammar-production-IRIREF'>IRIREF</a></td>
 </tr>
             <tr id="grammar-production-triples" data-grammar-original="[6] triples ::= subject predicateObjectList |blankNodePropertyList predicateObjectList?" data-grammar-expression="(&#x27;|&#x27;, [(&#x27;,&#x27;, [(&#x27;id&#x27;, &#x27;subject&#x27;), (&#x27;id&#x27;, &#x27;predicateObjectList&#x27;)]), (&#x27;,&#x27;, [(&#x27;id&#x27;, &#x27;blankNodePropertyList&#x27;), (&#x27;?&#x27;, (&#x27;id&#x27;, &#x27;predicateObjectList&#x27;))])])" >
     <td>[6]</td>
@@ -168,7 +174,7 @@
     <td>::=</td>
     <td><a href='#grammar-production-BLANK_NODE_LABEL'>BLANK_NODE_LABEL</a> <code>| </code> <a href='#grammar-production-ANON'>ANON</a></td>
 </tr>
-<tr><td colspan="5"><h4 id="terminals">Productions for terminals</h4></td></tr>
+<tr><td colspan="4"><h4 id="terminals">Productions for terminals</h4></td></tr>
             <tr id="grammar-production-IRIREF" data-grammar-original="[19] IRIREF ::=  &#x27;&lt;&#x27; ([^#x00-#x20&lt;&gt;&quot;{}|^`\] | UCHAR)* &#x27;&gt;&#x27;" data-grammar-expression="(&#x27;,&#x27;, [(&quot;&#x27;&quot;, &#x27;&lt;&#x27;), (&#x27;*&#x27;, (&#x27;|&#x27;, [(&#x27;[&#x27;, &#x27;^#x00-#x20&lt;&gt;&quot;{}|^`\\&#x27;), (&#x27;id&#x27;, &#x27;UCHAR&#x27;)])), (&quot;&#x27;&quot;, &#x27;&gt;&#x27;)])" class='grammar-token'>
     <td>[19]</td>
     <td><code>IRIREF</code></td>
--- a/trig/trig.bnf	Sat Aug 31 15:10:04 2013 +0100
+++ b/trig/trig.bnf	Sat Aug 31 15:10:51 2013 +0100
@@ -1,14 +1,20 @@
-[1g] trigDoc ::= (graph_statement)* 
- 
-[2g] graph_statement ::= directive 
- | graph
+[1g] trigDoc   ::= ( directive | block )*
 
-[3g] graph ::= graphName? "{" triplesBlock? "}"
+[2g] block   ::=   triplesOrGraph
+  | wrappedGraph
+  | triples2
+  | "GRAPH" ( iri | BlankNode ) wrappedGraph
 
-[4g] graphName ::= iri 
-| BlankNode 
+[3g] triplesOrGraph   ::=
+  ( iri | BlankNode ) ( wrappedGraph | predicateObjectList '.' )
 
-[5g] triplesBlock ::= triples ('.' triplesBlock?)?
+[4g] triples2   ::=
+  ( blankNodePropertyList | collection ) predicateObjectList? '.'
+
+[5g] wrappedGraph   ::=
+  '{' triplesBlock '}'
+
+[6g] triplesBlock   ::=   triples ( '.' triplesBlock? )?
 
 [3] directive ::= prefixID 
  | base | sparqlPrefix | sparqlBase
@@ -16,8 +22,8 @@
  
 [5] base ::= '@base' IRIREF "."
 
-[28*] sparqlPrefix ::= [Pp][Rr][Ee][Ff][Ii][Xx] PNAME_NS IRIREF
-[29*] sparqlBase ::= [Bb][Aa][Ss][Ee] IRIREF
+[28a] sparqlPrefix ::= "PREFIX" PNAME_NS IRIREF
+[29a] sparqlBase ::= "BASE" IRIREF
  
 [6] triples ::= subject predicateObjectList |
 blankNodePropertyList predicateObjectList?