use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class LangTriG method oneNamedGraphBlock2.
// Version for proposed Turtle-in-TriG and keyword GRAPH
protected final void oneNamedGraphBlock2() {
// Which may not be a graph block.
Node graphNode = null;
Token token = peekToken();
// Keep for error message.
Token t = token;
boolean mustBeNamedGraph = false;
if (lookingAt(KEYWORD)) {
if (token.getImage().equalsIgnoreCase("GRAPH")) {
nextToken();
mustBeNamedGraph = true;
token = peekToken();
// GRAPH <g>
// GRAPH []
} else
exception(t, "Keyword '" + token.getImage() + "' not allowed here");
}
if (lookingAt(LBRACKET)) {
nextToken();
token = peekToken();
Node blank = profile.createBlankNode(graphNode, t.getLine(), t.getColumn());
if (lookingAt(RBRACKET)) {
// 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 ...
turtle(blank);
return;
}
} else {
// 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);
expectEndOfTriplesTurtle();
return;
}
} else if (token.isNode()) {
// Either :s :p :o or :g { ... }
Node n = node();
nextToken();
token = peekToken();
if (lookingAt(LBRACE))
graphNode = n;
else {
if (mustBeNamedGraph)
exception(t, "Keyword 'GRAPH' must start a named graph");
turtle(n);
return;
}
} else if (lookingAt(LPAREN)) {
// Turtle - list
turtle();
return;
}
if (mustBeNamedGraph && graphNode == null)
exception(t, "Keyword 'GRAPH' must be followed by a graph name");
// braced graph
bracedGraph(t, graphNode);
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class LangTriG method oneNamedGraphBlock.
// Old version , tradition trig with RDF 1.1 Turtle tokens.
protected final void oneNamedGraphBlock() {
// Directives are only between graph blocks.
Node graphNode = null;
Token token = peekToken();
// Keep for error message.
Token t = token;
// [ ] { ... }
if (lookingAt(LBRACKET)) {
nextToken();
token = peekToken();
if (lookingAt(RBRACKET))
exception(t, "Broken term: [ not followed by ]");
graphNode = profile.createBlankNode(graphNode, t.getLine(), t.getColumn());
nextToken();
} else {
// { ... }
if (token.isNode()) {
graphNode = node();
nextToken();
}
}
bracedGraph(t, graphNode);
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class LangEngine method nextToken.
protected final Token nextToken() {
if (eof())
return tokenEOF;
// Tokenizer errors appear here!
try {
Token t = peekIter.next();
currLine = t.getLine();
currCol = t.getColumn();
return t;
} catch (RiotParseException ex) {
// Intercept to log it.
raiseException(ex);
throw ex;
} catch (AtlasException ex) {
// Bad I/O
RiotParseException ex2 = new RiotParseException(ex.getMessage(), -1, -1);
raiseException(ex2);
throw ex2;
}
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class LangTriG method bracedGraph.
private void bracedGraph(Token t, Node graphNode) {
if (graphNode != null) {
if (graphNode.isURI() || graphNode.isBlank())
setCurrentGraph(graphNode);
else
exception(t, "Not a legal graph name: " + graphNode);
} else
setCurrentGraph(Quad.tripleInQuad);
Token token = peekToken();
// = is optional and old style.
if (lookingAt(EQUALS)) {
if (isStrictMode)
exception(token, "Use of = {} is not part of standard TriG: " + graphNode);
// Skip.
nextToken();
token = peekToken();
}
if (!lookingAt(LBRACE))
exception(token, "Expected start of graph: got %s", peekToken());
nextToken();
while (true) {
token = peekToken();
if (lookingAt(RBRACE))
break;
// Unlike many operations in this parser suite,
// this does not assume that we are definitely entering
// this state and can throw an error if the first token
// is not acceptable.
triplesSameSubject();
}
// **** Turtle.
token = nextToken();
if (lookingAt(RBRACE))
exception(token, "Expected end of graph: got %s", token);
if (!isStrictMode) {
// Skip DOT after {}
token = peekToken();
if (lookingAt(DOT))
nextToken();
}
// End graph block.
setCurrentGraph(Quad.tripleInQuad);
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class LangTurtleBase method directiveKeyword.
protected final void directiveKeyword() {
Token t = peekToken();
String x = t.getImage();
nextToken();
if (x.equalsIgnoreCase("BASE")) {
directiveBase();
return;
}
if (x.equalsIgnoreCase("PREFIX")) {
directivePrefix();
return;
}
exception(t, "Unrecognized keyword for directive: %s", x);
}
Aggregations