Package com.google.collide.codemirror2

Examples of com.google.collide.codemirror2.Parser


    Document document = Document.createFromString(text);
    Line line = document.getFirstLine();
    TaggableLine previousLine;

    JsonArray<Token> tokens1 = JsonCollections.createArray();
    tokens1.add(new Token(mode, TokenType.KEYWORD, "function"));
    tokens1.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens1.add(new Token(mode, TokenType.VARIABLE, "a"));
    tokens1.add(new Token(mode, TokenType.NULL, "("));
    tokens1.add(new Token(mode, TokenType.VARIABLE, "b"));
    tokens1.add(new Token(mode, TokenType.NULL, ","));
    tokens1.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens1.add(new Token(mode, TokenType.VARIABLE, "c"));
    tokens1.add(new Token(mode, TokenType.NULL, ")"));
    tokens1.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens1.add(new Token(mode, TokenType.NULL, "{"));
    tokens1.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens2 = JsonCollections.createArray();
    tokens2.add(new Token(mode, TokenType.WHITESPACE, "  "));
    tokens2.add(new Token(mode, TokenType.VARIABLE, "d"));
    tokens2.add(new Token(mode, TokenType.NULL, "."));
    tokens2.add(new Token(mode, TokenType.VARIABLE, "prototype"));
    tokens2.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens2.add(new Token(mode, TokenType.NULL, "="));
    tokens2.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens2.add(new Token(mode, TokenType.KEYWORD, "function"));
    tokens2.add(new Token(mode, TokenType.NULL, "("));
    tokens2.add(new Token(mode, TokenType.NULL, ")"));
    tokens2.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens2.add(new Token(mode, TokenType.NULL, "{"));
    tokens2.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens3 = JsonCollections.createArray();
    tokens3.add(new Token(mode, TokenType.WHITESPACE, "  "));
    tokens3.add(new Token(mode, TokenType.NULL, "}"));
    tokens3.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens4 = JsonCollections.createArray();
    tokens4.add(new Token(mode, TokenType.NULL, "}"));
    tokens4.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens5 = JsonCollections.createArray();
    tokens5.add(new Token(mode, TokenType.KEYWORD, "var"));
    tokens5.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens5.add(new Token(mode, TokenType.DEF, "e"));
    tokens5.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens5.add(new Token(mode, TokenType.NULL, "="));
    tokens5.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens5.add(new Token(mode, TokenType.NULL, "{"));
    tokens5.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens6 = JsonCollections.createArray();
    tokens6.add(new Token(mode, TokenType.WHITESPACE, "  "));
    tokens6.add(new Token(mode, TokenType.PROPERTY, "f"));
    tokens6.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens6.add(new Token(mode, TokenType.NULL, ":"));
    tokens6.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens6.add(new Token(mode, TokenType.KEYWORD, "function"));
    tokens6.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens6.add(new Token(mode, TokenType.NULL, "("));
    tokens6.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens6.add(new Token(mode, TokenType.NULL, ")"));
    tokens6.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens6.add(new Token(mode, TokenType.NULL, "{"));
    tokens6.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens7 = JsonCollections.createArray();
    tokens7.add(new Token(mode, TokenType.WHITESPACE, "  "));
    tokens7.add(new Token(mode, TokenType.VARIABLE, "callMyFunctionWithCallback"));
    tokens7.add(new Token(mode, TokenType.NULL, "("));
    tokens7.add(new Token(mode, TokenType.KEYWORD, "function"));
    tokens7.add(new Token(mode, TokenType.NULL, "("));
    tokens7.add(new Token(mode, TokenType.COMMENT, "/* Knock-knock! */"));
    tokens7.add(new Token(mode, TokenType.NULL, ")"));
    tokens7.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens7.add(new Token(mode, TokenType.NULL, "{"));
    tokens7.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsIndexUpdater indexUpdater = new JsIndexUpdater();
    indexUpdater.onBeforeParse();

    previousLine = TaggableLineUtil.getPreviousLine(line);
View Full Code Here


        value = result.getGroup(4);
        type = WHITESPACE;
      } else {
        throw new IllegalArgumentException("Can't parse: " + result.getGroup(1));
      }
      tokens.add(new Token("test", type, value));
      text = text.substring(value.length());
    }
    ParseResult<State> parseResult = new ParseResult<State>(tokens, TestUtils.createMockState());
    return new ParseUtils.ExtendedParseResult<State>(parseResult, ParseUtils.Context.IN_CODE);
  }
View Full Code Here

    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

TOP

Related Classes of com.google.collide.codemirror2.Parser

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.