Package org.openjena.riot.tokens

Examples of org.openjena.riot.tokens.Token


      }
      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
          if (name.equals("value"))
          {
            if (value == null)
            {
              value = checkValidForObjectProperty();
            }
            else
            {
              exception(t, "Encountered the value property on an Object when the value property has already been specified") ;
            }
          }
          else if (name.equals("type"))
          {
            if (type == null)
            {
              type = checkValidForObjectProperty();
            }
            else
            {
              exception(t, "Encountered the type property on an Object when the type property has already been specified") ;
            }
          }
          else if (name.equals("lang") || name.equals("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) ;
            }
          }
          else if (name.equals("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) ;
            }
          }
          else
          {
            exception(t, "Unexpected Property Name %s encountered, expected one of value, type, lang or datatype", t.getImage()) ;
          }

          //After each Property Value pair we may optionally
          //see a comma to indicate further pairs are present
          if (lookingAt(TokenType.COMMA))
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
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 = Node.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

                return createTypedLiteral(str, XSDDatatype.XSDdouble, line, col) ;
            case INTEGER:
                return createTypedLiteral(str, XSDDatatype.XSDinteger, line, col) ;
            case LITERAL_DT :
            {
                Token tokenDT = token.getSubToken() ;
                String uriStr ;
               
                switch(tokenDT.getType())
                {
                    case IRI:               uriStr = tokenDT.getImage() ; break ;
                    case PREFIXED_NAME:
                    {
                        String prefix = tokenDT.getImage() ;
                        String suffix = tokenDT.getImage2() ;
                        uriStr = expandPrefixedName(prefix, suffix, tokenDT) ;
                        break ;
                    }
                    default:
                        throw new RiotException("Expected IRI for datatype: "+token) ;
                }
               
                uriStr = resolveIRI(uriStr, tokenDT.getLine(), tokenDT.getColumn()) ;
                RDFDatatype dt = Node.getType(uriStr) ;
                return createTypedLiteral(str, dt, line, col) ;
            }
           
            case LITERAL_LANG :
View Full Code Here

        }

        Tokenizer tokenizer = TokenizerFactory.makeTokenizerString(str) ;
        if ( ! tokenizer.hasNext() )
            throw new TDBException("Failed to tokenise: "+str) ;
        Token t = tokenizer.next() ;

        try {
            Node n = t.asNode() ;
            if ( n == null ) throw new TDBException("Not a node: "+str) ;
            return n ;
        } catch (RiotException ex)
        {
            throw new TDBException("Bad string for node: "+str) ;
View Full Code Here

    @Override
    protected final void runParser()
    {
        while(moreTokens())
        {
            Token t = peekToken() ;
            if ( lookingAt(DIRECTIVE) )
            {
                directive() ;
                continue ;
            }
View Full Code Here

TOP

Related Classes of org.openjena.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.