Search in sources :

Example 11 with Token

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);
}
Also used : Node(org.apache.jena.graph.Node) Token(org.apache.jena.riot.tokens.Token)

Example 12 with Token

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);
}
Also used : Node(org.apache.jena.graph.Node) Token(org.apache.jena.riot.tokens.Token)

Example 13 with Token

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;
    }
}
Also used : RiotParseException(org.apache.jena.riot.RiotParseException) Token(org.apache.jena.riot.tokens.Token) AtlasException(org.apache.jena.atlas.AtlasException)

Example 14 with Token

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);
}
Also used : Token(org.apache.jena.riot.tokens.Token)

Example 15 with Token

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);
}
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