Package com.google.collide.codemirror2

Examples of com.google.collide.codemirror2.Token


    return "com.google.collide.client.TestCode";
  }

  public void testCalculateClosingParens() {
    JsonArray<Token> tokens = JsonCollections.createArray();
    tokens.add(new Token("", TokenType.NULL, "{"));
    tokens.add(new Token("", TokenType.NULL, "foo"));
    tokens.add(new Token("", TokenType.NULL, "["));
    tokens.add(new Token("", TokenType.NULL, "]"));
    tokens.add(new Token("", TokenType.WHITESPACE, " "));
    tokens.add(new Token("", TokenType.NULL, ")"));
    tokens.add(new Token("", TokenType.NULL, "}"));
    tokens.add(new Token("", TokenType.NULL, "bar"));
    tokens.add(new Token("", TokenType.NULL, "]"));
    tokens.add(new Token("", TokenType.NULL, "bar"));

    //{foo[] )}bar]bar
    //0123456789

    assertEquals("", ExplicitAutocompleter.calculateClosingParens(tokens, 4));
View Full Code Here


    assertEquals(")}", ExplicitAutocompleter.calculateClosingParens(tokens, 6));
  }

  public void testCalculateOpenParens() {
    JsonArray<Token> tokens = JsonCollections.createArray();
    tokens.add(new Token("", TokenType.NULL, "{"));
    tokens.add(new Token("", TokenType.NULL, "foo"));
    tokens.add(new Token("", TokenType.NULL, "["));
    tokens.add(new Token("", TokenType.NULL, "moo"));
    tokens.add(new Token("", TokenType.NULL, "("));
    tokens.add(new Token("", TokenType.WHITESPACE, " "));
    tokens.add(new Token("", TokenType.NULL, ")"));
    tokens.add(new Token("", TokenType.WHITESPACE, " "));
    tokens.add(new Token("", TokenType.NULL, "{"));
    tokens.add(new Token("", TokenType.NULL, "]"));
    tokens.add(new Token("", TokenType.WHITESPACE, " "));
    tokens.add(new Token("", TokenType.NULL, ")"));
    tokens.add(new Token("", TokenType.NULL, "("));

    //{foo[moo( ) {] ](
    //012345678901234567

    assertEquals("", ExplicitAutocompleter.calculateOpenParens(tokens, 0));
View Full Code Here

      while (!stream.isEnd()) {
        codeMirrorParser.parseNext(stream, parserState, tokens);
      }

      if (tail != null) {
        tokens.add(new Token(codeMirrorParser.getName(parserState), TokenType.ERROR, tail));
      }

      if (endsWithNewline) {
        tokens.add(Token.NEWLINE);
      }
View Full Code Here

    this.editorCss = editorCss;
  }

  @Override
  public void renderNextChunk(Target target) {
    Token token = tokens.get(tokenPos++);
    Preconditions.checkNotNull(token, "Token was null");
   
    String tokenValue = token.getValue();
   
    String style = "";
    switch (token.getType()) {
      case NEWLINE:
        // we special case the NEWLINE token and do not append the default style.
        style = null;
        break;
       
      case ERROR:
        style = editorCss.lineRendererError() + " ";
        // Fall through to add the external stable class name too (unofficial color API)
       
      default:
        style += token.getStyle();
    }
   
    target.render(tokenValue.length(), style);
  }
View Full Code Here

    // Index of next token.
    int index = 0;

    while (index < size) {
      Token token = tokens.get(index);
      colCount += token.getValue().length();
      TokenType type = token.getType();
      index++;
      if (TokenType.TAG == type) {
        // Toggle "inTag" flag and update tag bounds.
        if (result.inTag) {
          // Refer to XmlCodeAnalyzer parsing code notes.
          if (">".equals(token.getValue()) || "/>".equals(token.getValue())) {
            result.endTagIndex = index - 1;
            // Exit the loop if cursor is inside a closed tag.
            if (result.inToken != null) {
              return result;
            }
            result.inTag = false;
          }
        } else {
          if (CodeMirror2.HTML.equals(token.getMode())) {
            result.startTagIndex = index - 1;
            result.endTagIndex = -1;
            result.inTag = true;
          }
        }
View Full Code Here

   * <p>Scanning is similar to scanning in {@link XmlCodeAnalyzer}.
   */
  private static HtmlTagWithAttributes buildTag(
      FindTagResult findTagResult, JsonArray<Token> tokens) {
    int index = findTagResult.startTagIndex;
    Token token = tokens.get(index);
    index++;
    String tagName = token.getValue().substring(1).trim();

    HtmlTagWithAttributes result = new HtmlTagWithAttributes(tagName);

    StringMultiset tagAttributes = result.getAttributes();
    while (index < findTagResult.endTagIndex) {
      token = tokens.get(index);
      index++;
      TokenType tokenType = token.getType();
      if (TokenType.ATTRIBUTE == tokenType) {
        tagAttributes.add(token.getValue().toLowerCase());
      }
    }

    result.setDirty(false);
    return result;
View Full Code Here

    if (parseResult == null) {
      return result;
    }

    JsonArray<Token> tokens = parseResult.getTokens();
    Token lastToken = tokens.isEmpty() ? null : tokens.get(tokens.size() - 1);

    if (lastToken != null) {
      switch (lastToken.getType()) {
        case ATOM:
        case COMMENT:
        case KEYWORD:
        case NUMBER:
        case STRING:
View Full Code Here

    idsToRelease.addAll(lineIds);
    lineIds.clear();

    for (int i = 0, l = tokens.size(); i < l; i++) {
      Token token = tokens.get(i);
      TokenType type = token.getType();
      if (type == VARIABLE || type == VARIABLE2 || type == PROPERTY || type == DEF) {
        String value = token.getValue();
        if (value.length() > 2) {
          lineIds.add(value);
        }
      }
      // TODO: Process strings that look like ID.
View Full Code Here

//  @Override
  protected void processLine(int lineNumber, JsonArray<Token> tokens) {
    JsParsingContext context = new JsParsingContext();
    for (int i = 0; i < tokens.size(); i++) {
      Token token = tokens.get(i);
      if (isVariable(token.getType())) {
//        getResultScope().addToken(
//            lineNumber, 0, new CodeToken(token.getValue().trim(), token.getType()));
      }
      Token functionToken = context.getFunctionToken(token);
      if (functionToken != null) {
//        getResultScope().addToken(lineNumber, 0,
//            new CodeToken(functionToken.getValue().trim(), functionToken.getType(), true));
      }
      context.nextToken(token);
View Full Code Here

    int fakeTokenColumn = 0;

    // Last token in always newline, see DocumentParserWorker.
    final int l = tokens.size() - 1;
    for (int i = 0; i < l; i++) {
      Token token = tokens.get(i);
      assert token != null;

      // Ignore whitespaces
      if (WHITESPACE == token.getType()) {
        continue;
      }

      // Common precondition: context is not too short
      if (context.predPred == null) {
        context.push(token);
        continue;
      }

      PyToken predPred = context.predPred;
      PyToken pred = context.pred;

      // In case we get ":" or "(" it may be a function definition
      if (LITERAL_COLON.equals(token.getValue())
          || LITERAL_LEFT_PARANTHESIS.equals(token.getValue())) {
        if ((KEYWORD == predPred.getType()) && "def".equals(predPred.getContent())) {
//          getResultScope().addToken(lineNumber, fakeTokenColumn,
//              new CodeToken(pred.getContent(), pred.getType(), true));
        }
        fakeTokenColumn++;
        context.push(token);
        continue;
      }

      // When we get ", id," construction,
      // then do not reset accumulator (ids before first comma)
      if (LITERAL_COMMA.equals(token.getValue())) {
        if (LITERAL_COMMA.equals(predPred.getContent())) {
          if (VARIABLE == pred.getType()) {
            context.pushSavingAccumulator(token);
            continue;
          }
        }
        context.push(token);
        continue;
      }

      // When we got "id =" then register all remembered ids as variables
      if (LITERAL_EQUALS.equals(token.getValue())) {
        if (VARIABLE == context.pred.getType()) {
          context.accumulator.add(context.pred);
          while (!context.accumulator.isEmpty()) {
            PyToken nextVar = context.accumulator.pop();
//            getResultScope().addToken(lineNumber, fakeTokenColumn,
//                new CodeToken(nextVar.getContent(), nextVar.getType()));
            fakeTokenColumn++;
          }
        }
        context.push(token);
        continue;
      }

      // When we get "id1, id2" construction
      // then remember id1, because it is going to be pushed out of context.
      if (VARIABLE == token.getType()) {
        if (VARIABLE == context.predPred.getType()) {
          if (LITERAL_COMMA.equals(context.pred.getContent())) {
            context.pushAndAddToAccumulator(token);
            continue;
          }
View Full Code Here

TOP

Related Classes of com.google.collide.codemirror2.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.