Package org.allcolor.xml.parser

Examples of org.allcolor.xml.parser.CStringTokenizer$Token


      }

      StringMultiset tagAttributes = tag.getAttributes();

      while (index < size) {
        Token token = tokens.get(index);
        index++;
        TokenType tokenType = token.getType();
        if (ATTRIBUTE == tokenType) {
          String attribute = token.getValue();
          attribute = ignoreCase ? attribute.toLowerCase() : attribute;
          attributes.add(attribute);
          tagAttributes.add(attribute);
        } else if (TAG == tokenType) {
          // Tag closing token
          tag.setDirty(false);
          inTag = false;
          break;
        }
      }
      if (newAttributes && attributes.size() != 0) {
        line.putTag(TAG_ATTRIBUTES, attributes);
      } else if (!newAttributes && attributes.size() == 0) {
        line.putTag(TAG_ATTRIBUTES, null);
      }
    } else {
      line.putTag(TAG_ATTRIBUTES, null);
    }

    while (index < size) {
      Token token = tokens.get(index);
      index++;
      TokenType tokenType = token.getType();
      if (TAG == tokenType) {
        if (inTag) {
          if (">".equals(token.getValue()) || "/>".equals(token.getValue())) {
            // If type is "tag" and content is ">", this is HTML token.
            inTag = false;
          }
        } else {
          // Check that we are in html mode.
          if (CodeMirror2.HTML.equals(token.getMode())) {
            lastTagTokenIndex = index - 1;
            inTag = true;
          }
        }
      }
    }

    if (inTag) {
      if (lastTagTokenIndex != -1) {
        index = lastTagTokenIndex;
        Token token = tokens.get(index);
        index++;
        String tagName = token.getValue().substring(1).trim();
        tag = new HtmlTagWithAttributes(tagName);
        StringMultiset tagAttributes = tag.getAttributes();
        while (index < size) {
          token = tokens.get(index);
          index++;
          TokenType tokenType = token.getType();
          if (ATTRIBUTE == tokenType) {
            String attribute = token.getValue();
            tagAttributes.add(ignoreCase ? attribute.toLowerCase() : attribute);
          }
        }
      }
View Full Code Here


   */
  static boolean buildInvocationSequenceContext(
      JsonArray<Token> tokens, boolean expectingPeriod, JsonArray<String> contextParts) {
    // right-to-left tokens processing loop.
    while (!tokens.isEmpty()) {
      Token lastToken = tokens.pop();
      TokenType lastTokenType = lastToken.getType();
      String lastTokenValue = lastToken.getValue();

      // Omit whitespaces.
      if (lastTokenType == WHITESPACE) {
        continue;
      }
View Full Code Here

    if (result == null) {
      return new ExtendedParseResult<T>(null, Context.NOT_PARSED);
    }

    JsonArray<Token> tokens = result.getTokens();
    Token lastToken = tokens.peek();
    Preconditions.checkNotNull(lastToken,
        "Last token expected to be non-null; text='%s', position=%s", text, position);
    TokenType lastTokenType = lastToken.getType();
    String lastTokenValue = lastToken.getValue();
    if (!addSpace) {
      if (lastTokenType == STRING || lastTokenType == REGEXP) {
        return new ExtendedParseResult<T>(result, Context.IN_STRING);
      } else if (lastTokenType == TokenType.COMMENT) {
        return new ExtendedParseResult<T>(result, Context.IN_COMMENT);
      }

      // Python parser, for a purpose of simplicity, parses period and variable
      // name as a single token. If period is not followed by identifier, parser
      // states that this is and error, which is, generally, not truth.
      if ((lastTokenType == TokenType.ERROR) && LITERAL_PERIOD.equals(lastTokenValue)) {
        tokens.pop();
        tokens.add(new Token(lastToken.getMode(), TokenType.NULL, LITERAL_PERIOD));
      }

      return new ExtendedParseResult<T>(result, Context.IN_CODE);
    }

    // Remove / shorten last token to omit added whitespace.
    tokens.pop();
    if (lastTokenType == STRING || lastTokenType == REGEXP || lastTokenType == TokenType.COMMENT) {
      // Whitespace stuck to token - strip it.
      lastTokenValue = lastTokenValue.substring(0, lastTokenValue.length() - 1);
      tokens.add(new Token(lastToken.getMode(), lastTokenType, lastTokenValue));
      if (lastTokenType == STRING || lastTokenType == REGEXP) {
        return new ExtendedParseResult<T>(result, Context.IN_STRING);
      } else {
        return new ExtendedParseResult<T>(result, Context.IN_COMMENT);
      }
View Full Code Here

      }
      JsonArray<Token> tokens = parseResult.getTokens();
      if (tokens.isEmpty()) {
        return null;
      }
      Token lastToken = tokens.peek();
      return lastToken.getValue();
    }
View Full Code Here

    int indent = 0;
    if (TokenType.WHITESPACE == tokens.get(0).getType()) {
      indent = tokens.get(0).getValue().length();
    }

    Token lastToken = tokens.pop();
    TokenType lastTokenType = lastToken.getType();

    if (lastTokenType == WHITESPACE) {
      return new CompletionContext<T>("", "", false, CompletionType.GLOBAL, parseResult, indent);
    }

    String lastTokenValue = lastToken.getValue();

    if (lastTokenType == KEYWORD) {
      return new CompletionContext<T>(
          "", lastTokenValue, false, CompletionType.GLOBAL, parseResult, indent);
    }
View Full Code Here

    }

    private Token buildTokenModel(TokenInfo token) throws CloudException {
        Preconditions.checkNotNull(token);

        Token response = new Token();

        response.expires = TokenAuth.getExpiration(token);

        UserData user = authRepository.getUsers().find(token.getUserId());
        if (user == null) {
View Full Code Here

    return new JAVACCParser(reader, new SPARQLParser(reader));
  }

  @Override
  public TOKEN getNextToken() {
    final Token token = this.parser.getNextToken();
    if(token==null){
      return null;
    } else {
      return new SPARQLToken(token);
    }
View Full Code Here

   * @return DOCUMENT ME!
   */
  public static String getInnerRule(
    final String content,
    final List list) {
    CStringTokenizer tokenizer     = new CStringTokenizer(content,
        "{}@", true);
    CStringBuilder   resultContent = new CStringBuilder();
    String       previousToken = null;

    while (tokenizer.hasMoreTokens()) {
      String token = tokenizer.nextToken();

      if (token.equals("@")) {
        if (tokenizer.hasMoreTokens()) {
          String       selector = "@" +
            tokenizer.nextToken();
          CStringBuilder rule = new CStringBuilder();

          if (selector.indexOf(" ") != -1) {
            rule.append(selector.substring(selector.indexOf(
                  " ")).trim());
            selector = selector.substring(0,
                selector.indexOf(" ")).trim();
          } // end if

          if (rule.indexOf(";") != -1) {
            previousToken = rule.substring(rule.indexOf(";"));
            list.add(selector +
              rule.substring(0, rule.indexOf(";")));

            continue;
          } // end if

          int iOpen = 0;

          while (tokenizer.hasMoreTokens()) {
            String nToken = tokenizer.nextToken();

            if (nToken.equals("}")) {
              iOpen--;

              if (iOpen > 0) {
                rule.append(nToken);
              }
            } // end if
            else if (nToken.equals("{")) {
              rule.append(nToken);
              iOpen++;
            } // end else if
            else {
              rule.append(nToken);
            } // end else

            if (iOpen == 0) {
              break;
            }
          } // end while

          list.add(selector + " {" + rule.toString() + "}");
        } // end if

        previousToken = null;
      } // end if
      else if (token.equals("{")) {
        if (previousToken != null) {
          String       selector = previousToken;
          CStringBuilder rule = new CStringBuilder();

          if (previousToken.lastIndexOf("\n") != -1) {
            selector = previousToken.substring(previousToken.lastIndexOf(
                  "\n") + 1).trim();
            resultContent.append(previousToken.substring(
                0,
                previousToken.lastIndexOf("\n")));
          } // end if

          int iOpen = 1;

          while (tokenizer.hasMoreTokens()) {
            String nToken = tokenizer.nextToken();

            if (nToken.equals("}")) {
              iOpen--;

              if (iOpen > 0) {
View Full Code Here

    } // end while
  } // end parse()

  private static void parseAttList(String in,final Map knownElement) {
    in = in.substring("!ATTLIST".length()).trim();
    String elementName = new CStringTokenizer(in," \n\r\t",false).nextToken();
    CElement elem = (CElement)knownElement.get(elementName);
    if (elem == null) {
      elem = new CElement(elementName,"*");
      knownElement.put(elementName,elem);
    }
    in = in.substring(in.indexOf(elementName)+elementName.length()).trim();
    while (in.length() > 0) {
      String attrName = new CStringTokenizer(in," \n\r\t",false).nextToken();
      in = in.substring(in.indexOf(attrName)+attrName.length()).trim();
      String type = null;
      if (in.startsWith("(")) {
        type = in.substring(0,in.indexOf(")")+1);
      } else {
        type = new CStringTokenizer(in," \n\r\t",false).nextToken();
      }
      in = in.substring(in.indexOf(type)+type.length()).trim();
      String defaultValue = null;
      if (in.startsWith("\"") ||
        in.startsWith("'")) {
        in = in.substring(1);
        int index = in.indexOf("\"");
        if (index == -1 || (in.indexOf("'") > -1 && in.indexOf("'") < index))
          index = in.indexOf("'");
        defaultValue = in.substring(0,index);
        in = in.substring(index+1);
      } else {
        defaultValue = new CStringTokenizer(in," \n\r\t",false).nextToken();
        in = in.substring(in.indexOf(defaultValue)+defaultValue.length()).trim();
      }
      if (defaultValue.startsWith("#FIXED")) {
        if (in.startsWith("\"") ||
          in.startsWith("'")) {
          in = in.substring(1);
          int index = in.indexOf("\"");
          if (index == -1 || (in.indexOf("'") > -1 && in.indexOf("'") < index))
            index = in.indexOf("'");
          defaultValue = in.substring(0,index);
          in = in.substring(index+1);
        } else {
          defaultValue = new CStringTokenizer(in," \n\r\t",false).nextToken();
          in = in.substring(in.indexOf(defaultValue)+defaultValue.length()).trim();
        }
      }
      if ("CDATA".equals(type)) {
        elem.addAttribute(attrName,CElement.CDATA,defaultValue,null);
View Full Code Here

   * @param cpBuffer DOCUMENT ME!
   *
   * @return DOCUMENT ME!
   */
  private boolean isSequence(final CStringBuilder cpBuffer) {
    CStringTokenizer tokenizer  = new CStringTokenizer(cpBuffer.toString(),
        "()", true);
    boolean       isSequence = false;
    int         iOpen      = 0;

    while (tokenizer.hasMoreTokens()) {
      String token = tokenizer.nextToken();

      if (token.equals("(")) {
        iOpen++;
      } else if (token.equals(")")) {
        iOpen--;
View Full Code Here

TOP

Related Classes of org.allcolor.xml.parser.CStringTokenizer$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.