Search in sources :

Example 26 with Token

use of org.apache.jena.riot.tokens.Token in project jena by apache.

the class LangTurtleBase method triplesList.

protected final Node triplesList() {
    nextToken();
    Node lastCell = null;
    Node listHead = null;
    startList();
    for (; ; ) {
        Token errorToken = peekToken();
        if (eof())
            exception(peekToken(), "Unterminated list");
        if (lookingAt(RPAREN)) {
            nextToken();
            break;
        }
        // The value.
        Node n = triplesNode();
        if (n == null)
            exception(errorToken, "Malformed list");
        // Node for the list structre.
        Node nextCell = NodeFactory.createBlankNode();
        if (listHead == null)
            listHead = nextCell;
        if (lastCell != null)
            emitTriple(lastCell, NodeConst.nodeRest, nextCell);
        lastCell = nextCell;
        emitTriple(nextCell, NodeConst.nodeFirst, n);
    }
    if (lastCell == null) {
        // Simple ()
        finishList();
        return NodeConst.nodeNil;
    }
    // Finish list.
    emitTriple(lastCell, NodeConst.nodeRest, NodeConst.nodeNil);
    finishList();
    return listHead;
}
Also used : Node(org.apache.jena.graph.Node) Token(org.apache.jena.riot.tokens.Token)

Example 27 with Token

use of org.apache.jena.riot.tokens.Token in project jena by apache.

the class LangTurtleBase method predicate.

/** Get predicate - maybe null for "illegal" */
protected final Node predicate() {
    Token t = peekToken();
    if (t.hasType(TokenType.KEYWORD)) {
        boolean strict = isStrictMode;
        Token tErr = peekToken();
        String image = peekToken().getImage();
        if (image.equals(KW_A))
            return NodeConst.nodeRDFType;
        // N3-isms
        if (!strict && image.equals(KW_SAME_AS))
            return nodeSameAs;
        // Relationship between two formulae in N3.
        //            if ( !strict && image.equals(KW_LOG_IMPLIES) )
        //                return log:implies;
        exception(tErr, "Unrecognized keyword: " + image);
    }
    Node n = node();
    if (n == null || !n.isURI())
        exception(t, "Expected IRI for predicate: got: %s", t);
    return n;
}
Also used : Node(org.apache.jena.graph.Node) Token(org.apache.jena.riot.tokens.Token)

Example 28 with Token

use of org.apache.jena.riot.tokens.Token in project jena by apache.

the class LangTurtleBase method runParser.

@Override
protected final void runParser() {
    while (moreTokens()) {
        Token t = peekToken();
        if (lookingAt(DIRECTIVE)) {
            // @form.
            directive();
            continue;
        }
        if (lookingAt(KEYWORD)) {
            if (t.getImage().equalsIgnoreCase("PREFIX") || t.getImage().equalsIgnoreCase("BASE")) {
                directiveKeyword();
                continue;
            }
        }
        oneTopLevelElement();
        if (lookingAt(EOF))
            break;
    }
}
Also used : Token(org.apache.jena.riot.tokens.Token)

Example 29 with Token

use of org.apache.jena.riot.tokens.Token in project jena by apache.

the class LangEngine method eof.

protected final boolean eof() {
    if (tokenEOF != null)
        return true;
    if (!moreTokens()) {
        tokenEOF = new Token(tokens.getLine(), tokens.getColumn());
        tokenEOF.setType(EOF);
        return true;
    }
    return false;
}
Also used : Token(org.apache.jena.riot.tokens.Token)

Example 30 with Token

use of org.apache.jena.riot.tokens.Token in project jena by apache.

the class LangEngine method expect.

protected final void expect(String msg, TokenType ttype) {
    if (!lookingAt(ttype)) {
        Token location = peekToken();
        exception(location, msg);
    }
    nextToken();
}
Also used : Token(org.apache.jena.riot.tokens.Token)

Aggregations

Token (org.apache.jena.riot.tokens.Token)40 Node (org.apache.jena.graph.Node)16 RiotException (org.apache.jena.riot.RiotException)4 Tokenizer (org.apache.jena.riot.tokens.Tokenizer)4 AtlasException (org.apache.jena.atlas.AtlasException)2 RiotParseException (org.apache.jena.riot.RiotParseException)2 InputStream (java.io.InputStream)1 NoSuchElementException (java.util.NoSuchElementException)1 NotImplemented (org.apache.jena.atlas.lib.NotImplemented)1 Timer (org.apache.jena.atlas.lib.Timer)1 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)1 IRI (org.apache.jena.iri.IRI)1 LabelToNode (org.apache.jena.riot.lang.LabelToNode)1 StreamRowRDF (org.apache.jena.riot.system.StreamRowRDF)1 StringType (org.apache.jena.riot.tokens.StringType)1 IRI (org.apache.jena.riot.tokens.TokenType.IRI)1 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)1 TDBException (org.apache.jena.tdb.TDBException)1