Package org.apache.jena.riot.tokens

Examples of org.apache.jena.riot.tokens.Token


        if ( tokenEOF != null )
            return true ;
       
        if ( ! moreTokens() )
        {
            tokenEOF = new Token(tokens.getLine(), tokens.getColumn()) ;
            tokenEOF.setType(EOF) ;
            return true ;
        }
        return false ;
    }
View Full Code Here


        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) ;
View Full Code Here

   
    protected final void expect(String msg, TokenType ttype)
    {
        if ( ! lookingAt(ttype) )
        {
            Token location = peekToken() ;
            exception(location, msg) ;
        }
        nextToken() ;
    }
View Full Code Here

       
        private void directives()
        {
            while ( lookingAt(TokenType.KEYWORD) )
            {
                Token t = nextToken() ;
                if ( t.getImage().equalsIgnoreCase("VARS") )
                {
                    directiveVars() ;
                    continue ;
                }
                if ( t.getImage().equalsIgnoreCase("PREFIX") )
                {
                    directivePrefix() ;
                    continue ;
                }
            }
View Full Code Here

                if ( i >= vars.size() )
                    exception(peekToken(), "Too many items in a line.  Expected "+vars.size()) ;
               
                Var v = vars.get(i) ;
               
                Token token = nextToken() ;
                if ( ! token.hasType(TokenType.MINUS ) )
                {
                    Node n ;
                    // One case; VARS line then *
                    if ( token.hasType(TokenType.STAR ) || ( token.isCtlCode() && token.getCntrlCode() == -1 ) )
                        n = lastLine.get(v) ;
                    else if ( token.hasType(TokenType.BNODE) )
                        n = NodeFactory.createAnon(new AnonId(NodeFmtLib.decodeBNodeLabel(token.getImage()))) ;
                    else
                        n = profile.create(null, token) ;
                    binding.add(v, n) ;
                }
                i++ ;
            }
            if ( eof() )
                exception(peekToken(), "Line does not end with a DOT") ;
           
            Token dot = nextToken() ;
           
            if ( i != vars.size() )
            {
                Var v = vars.get(vars.size()-1) ;
                exception(dot, "Too many items in a line.  Expected "+vars.size()) ;
View Full Code Here

        private void directiveVars()
        {
            vars.clear() ;
            while (! eof() && ! lookingAt(DOT) )
            {
                Token t = nextToken() ;
                if ( ! t.hasType(TokenType.VAR) )
                    exception(t, "VARS requires a list of variables (found '"+t+"')") ;
                Var v = Var.alloc(t.getImage()) ;
                vars.add(v) ;
            }
            nextToken() ;   // DOT
        }
View Full Code Here

      }
      else if (isPropertyName())
      {
        subjectExpected = false;
        //Is a Property Name so represents a Subject
        Token t = nextToken() ;
        Node subj;
        if (t.getImage().startsWith("_:"))
        {
          subj = profile.createBlankNode(null, t.getImage().substring(2), t.getLine(), t.getColumn()) ;
        }
        else
        {
          subj = profile.createURI(t.getImage(), t.getLine(), t.getColumn()) ;
        }

        //Should always be a : after a Property Name
        checkColon() ;
View Full Code Here

    {
      if (isPropertyName())
      {
        first = false;
        propertyNameExpected = false;
        Token t = nextToken();
        Node pred = profile.createURI(t.getImage(), t.getLine(), t.getColumn()) ;

        //Must be a : after Property Name
        checkColon() ;

        //Then we can try and parse the Object List
View Full Code Here

    //JSON Object
    //It has mandatory properties 'value' and 'type' plus optional
    //properties 'lang', 'xml:lang' and 'datatype'

    Node obj = null;
    Token value = null, type = null, lang = null, datatype = null;

    //First we expect to see the { character to start the JSON Object
    if (lookingAt(TokenType.LBRACE))
    {
      //Discard the {
      nextToken();

      //Then see a stream of tokens which are property value pairs
      //representing the properties of the object
      boolean first = true;
      boolean propertyNameExpected = true;
      while (true)
      {
        if (isPropertyName())
        {
          first = false;
          propertyNameExpected = false;

          Token t = nextToken();
          String name = t.getImage();

          //Must always be a : after a property name
          checkColon();

          //Is this one of our valid properties
                    switch ( name )
                    {
                        case "value":
                            if ( value == null )
                            {
                                value = checkValidForObjectProperty();
                            }
                            else
                            {
                                exception( t,
                                           "Encountered the value property on an Object when the value property has already been specified" );
                            }
                            break;
                        case "type":
                            if ( type == null )
                            {
                                type = checkValidForObjectProperty();
                            }
                            else
                            {
                                exception( t,
                                           "Encountered the type property on an Object when the type property has already been specified" );
                            }
                            break;
                        case "lang":
                        case "xml:lang":
                            if ( lang == null && datatype == null )
                            {
                                lang = checkValidForObjectProperty();
                            }
                            else
                            {
                                exception( t,
                                           "Encountered the %s property on an Object when lang/datatype has already been specified",
                                           name );
                            }
                            break;
                        case "datatype":
                            if ( lang == null && datatype == null )
                            {
                                datatype = checkValidForObjectProperty();
                            }
                            else
                            {
                                exception( t,
                                           "Encountered the %s property on an Object when lang/datatype has already been specified",
                                           name );
                            }
                            break;
                        default:
                            exception( t,
                                       "Unexpected Property Name %s encountered, expected one of value, type, lang or datatype",
                                       t.getImage() );
                            break;
                    }

          //After each Property Value pair we may optionally
          //see a comma to indicate further pairs are present
View Full Code Here

    return lookingAt(TokenType.STRING1) || lookingAt(TokenType.STRING2);
  }

    private Token checkValidForObjectProperty()
    {
      Token t = null;
      if (lookingAt(TokenType.STRING1) || lookingAt(TokenType.STRING2))
        t = nextToken();
      else
        exception(peekToken(), "JSON Values given for properties for an Object must be Strings") ;
      return t;
View Full Code Here

TOP

Related Classes of org.apache.jena.riot.tokens.Token

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.