Author: andy
Date: Sun Jul 7 17:44:58 2013
New Revision: 1500494
URL: http://svn.apache.org/r1500494
Log:
Attempt to DRY out the code.
Modified:
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTriG.java
Modified:
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTriG.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTriG.java?rev=1500494&r1=1500493&r2=1500494&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTriG.java
(original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTriG.java
Sun Jul 7 17:44:58 2013
@@ -60,6 +60,9 @@ public class LangTriG extends LangTurtle
nextToken() ;
mustBeNamedGraph = true ;
token = peekToken() ;
+ // GRAPH <g>
+ // GRAPH []
+
} else
exception(t, "Keyword '" + token.getImage() + "' not allowed
here") ;
}
@@ -80,20 +83,25 @@ public class LangTriG extends LangTurtle
token = peekToken() ;
Node blank = profile.createBlankNode(graphNode, t.getLine(),
t.getColumn()) ;
if ( lookingAt(RBRACKET) ) {
- // Can be [] :predicate or [] {
+ // Can be Turtle, "[] :predicate", or named graph "[] {"
nextToken() ;
if ( lookingAt(LBRACE) )
graphNode = blank ;
else {
+ if ( mustBeNamedGraph )
+ exception(t, "Keyword 'GRAPH' must start a named
graph") ;
// [] :p ...
- predicateObjectList(blank) ;
- expectEndOfTriplesTurtle() ;
+ turtle(blank) ;
return ;
}
} else {
+ // [ :p ... ]
+ // [ :p ... ] :p ...
// XXX This fragment must be in Turtle somewhere
+ if ( mustBeNamedGraph )
+ exception(t, "Keyword 'GRAPH' must start a named graph") ;
triplesBlankNode(blank) ;
-
+ // Following predicate.
if ( peekPredicate() )
predicateObjectList(blank) ;
@@ -109,15 +117,14 @@ public class LangTriG extends LangTurtle
if ( lookingAt(LBRACE) )
graphNode = n ;
else {
- // [ :p .... ] :q
- // In LangTurtle?
- predicateObjectList(n) ;
- expectEndOfTriplesTurtle() ;
+ if ( mustBeNamedGraph )
+ exception(t, "Keyword 'GRAPH' must start a named graph") ;
+ turtle(n) ;
return ;
}
} else if ( lookingAt(LPAREN) ) {
// Turtle - list
- triplesSameSubject() ;
+ turtle() ;
return ;
}
@@ -128,6 +135,16 @@ public class LangTriG extends LangTurtle
bracedGraph(t, graphNode) ;
}
+ protected final void turtle(Node n) {
+ predicateObjectList(n) ;
+ expectEndOfTriplesTurtle() ;
+ }
+
+ protected final void turtle() {
+ // This does expectEndOfTriplesTurtle() ;
+ triplesSameSubject() ;
+ }
+
protected final void oneNamedGraphBlock() {
// Directives are only between graph blocks.
Node graphNode = null ;