use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class JSONInputIterator method expect.
protected final void expect(String msg, TokenType ttype) {
if (!lookingAt(ttype)) {
Token location = peekToken();
exception(location, msg);
}
nextToken();
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class JSONInputIterator method parseBoolean.
private void parseBoolean() {
isBooleanResults = true;
if (lookingAt(TokenType.KEYWORD)) {
Token t = nextToken();
String keyword = t.getImage();
if (keyword.equals("true")) {
boolResult = true;
} else if (keyword.equals("false")) {
boolResult = false;
} else {
exception(t, "Unexpected keyword %s encountered, expected true or false", keyword);
}
} else {
exception(peekToken(), "Unexpected token when a true/false keyword was expected for the value of the boolean property");
}
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class NodeFactoryExtra method parseNode.
/**
* Parse a string into a node.
* <p>
* Allows surrounding white space.
* </p>
*
* @param nodeString Node string to parse
* @param pmap Prefix Map, null to use no prefix mappings
* @return Parsed Node
* @throws RiotException Thrown if a valid node cannot be parsed
*/
public static Node parseNode(String nodeString, PrefixMap pmap) {
Tokenizer tokenizer = TokenizerFactory.makeTokenizerString(nodeString);
if (!tokenizer.hasNext())
throw new RiotException("Empty RDF term");
Token token = tokenizer.next();
Node node = token.asNode(pmap);
if (node == null)
throw new RiotException("Bad RDF Term: " + nodeString);
if (tokenizer.hasNext())
throw new RiotException("Trailing characters in string: " + nodeString);
if (node.isURI()) {
// Lightly test for bad URIs.
String x = node.getURI();
if (x.indexOf(' ') >= 0)
throw new RiotException("Space(s) in IRI: " + nodeString);
}
return node;
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class JSONInputIterator method ignoreValue.
private void ignoreValue() {
if (isPropertyName()) {
// Just a string value so can discard and then check for the
// subsequent comma
nextToken();
checkComma(TokenType.RBRACE);
} else if (lookingAt(TokenType.DECIMAL) || lookingAt(TokenType.INTEGER) || lookingAt(TokenType.DOUBLE) || lookingAt(TokenType.KEYWORD)) {
// Just a numeric/keyword (boolean) value do discard and check for
// subsequent comma
nextToken();
checkComma(TokenType.RBRACE);
} else if (lookingAt(TokenType.LBRACE)) {
// Start of an Object
nextToken();
// TODO We should really care about the syntactic validity of
// objects we are ignoring but that seems like a bit too much effort
int openBraces = 1;
while (openBraces >= 1) {
Token next = nextToken();
if (next.getType().equals(TokenType.LBRACE)) {
openBraces++;
} else if (next.getType().equals(TokenType.RBRACE)) {
openBraces--;
}
}
checkComma(TokenType.RBRACE);
} else if (lookingAt(TokenType.LBRACKET)) {
// Start of an Array
nextToken();
// TODO We should really care about the syntactic validity of
// objects we are ignoring but that seems like a bit too much effort
int openBraces = 1;
while (openBraces >= 1) {
Token next = nextToken();
if (next.getType().equals(TokenType.LBRACKET)) {
openBraces++;
} else if (next.getType().equals(TokenType.RBRACKET)) {
openBraces--;
}
}
checkComma(TokenType.RBRACE);
} else {
exception(peekToken(), "Unexpected Token");
}
}
use of org.apache.jena.riot.tokens.Token in project jena by apache.
the class JSONInputIterator 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;
}
}
Aggregations