Package com.google.dart.engine.scanner

Examples of com.google.dart.engine.scanner.Token


  private boolean isFunctionExpression(Token startToken) {
    // Function expressions aren't allowed in initializer lists.
    if (inInitializer) {
      return false;
    }
    Token afterParameters = skipFormalParameterList(startToken);
    if (afterParameters == null) {
      return false;
    }
    if (afterParameters.matchesAny(TokenType.OPEN_CURLY_BRACKET, TokenType.FUNCTION)) {
      return true;
    }
    if (parseAsync) {
      String lexeme = afterParameters.getLexeme();
      return lexeme.equals(ASYNC) || lexeme.equals(SYNC);
    }
    return false;
  }
View Full Code Here


          TokenType.OPEN_CURLY_BRACKET,
          TokenType.OPEN_SQUARE_BRACKET,
          TokenType.INDEX);
    }
    // We know that we have an identifier, and need to see whether it might be a type name.
    Token token = skipTypeName(currentToken);
    if (token == null) {
      // There was no type name, so this can't be a declaration.
      return false;
    }
    token = skipSimpleIdentifier(token);
    if (token == null) {
      return false;
    }
    TokenType type = token.getType();
    return type == TokenType.EQ || type == TokenType.COMMA || type == TokenType.SEMICOLON
        || tokenMatchesKeyword(token, Keyword.IN);
  }
View Full Code Here

    // Token "=" means that it is actually field initializer.
    if (startToken.getType() == TokenType.EQ) {
      return false;
    }
    // Consume all operator tokens.
    Token token = startToken.getNext();
    while (token.isOperator()) {
      token = token.getNext();
    }
    // Formal parameter list is expect now.
    return tokenMatches(token, TokenType.OPEN_PAREN);
  }
View Full Code Here

   *
   * @param startToken the token at which parsing is to begin
   * @return the token following the string literal that was parsed
   */
  private Token skipStringLiteral(Token startToken) {
    Token token = startToken;
    while (token != null && tokenMatches(token, TokenType.STRING)) {
      token = token.getNext();
      TokenType type = token.getType();
      if (type == TokenType.STRING_INTERPOLATION_EXPRESSION
          || type == TokenType.STRING_INTERPOLATION_IDENTIFIER) {
        token = skipStringInterpolation(token);
      }
    }
View Full Code Here

         *
         * @param startToken the token at which parsing is to begin
         * @return the token following the type argument list that was parsed
         */
  private Token skipTypeArgumentList(Token startToken) {
    Token token = startToken;
    if (!tokenMatches(token, TokenType.LT)) {
      return null;
    }
    token = skipTypeName(token.getNext());
    if (token == null) {
      return null;
    }
    while (tokenMatches(token, TokenType.COMMA)) {
      token = skipTypeName(token.getNext());
      if (token == null) {
        return null;
      }
    }
    if (token.getType() == TokenType.GT) {
      return token.getNext();
    } else if (token.getType() == TokenType.GT_GT) {
      Token second = new Token(TokenType.GT, token.getOffset() + 1);
      second.setNextWithoutSettingPrevious(token.getNext());
      return second;
    }
    return null;
  }
View Full Code Here

   *
   * @param startToken the token at which parsing is to begin
   * @return the token following the type name that was parsed
   */
  private Token skipTypeName(Token startToken) {
    Token token = skipPrefixedIdentifier(startToken);
    if (token == null) {
      return null;
    }
    if (tokenMatches(token, TokenType.LT)) {
      token = skipTypeArgumentList(token);
View Full Code Here

    //
    // We can't skip a type parameter because it can be preceeded by metadata, so we just assume
    // that everything before the matching end token is valid.
    //
    int depth = 1;
    Token next = startToken.getNext();
    while (depth > 0) {
      if (tokenMatches(next, TokenType.EOF)) {
        return null;
      } else if (tokenMatches(next, TokenType.LT)) {
        depth++;
      } else if (tokenMatches(next, TokenType.GT)) {
        depth--;
      } else if (tokenMatches(next, TokenType.GT_EQ)) {
        if (depth == 1) {
          Token fakeEquals = new Token(TokenType.EQ, next.getOffset() + 2);
          fakeEquals.setNextWithoutSettingPrevious(next.getNext());
          return fakeEquals;
        }
        depth--;
      } else if (tokenMatches(next, TokenType.GT_GT)) {
        depth -= 2;
      } else if (tokenMatches(next, TokenType.GT_GT_EQ)) {
        if (depth < 2) {
          return null;
        } else if (depth == 2) {
          Token fakeEquals = new Token(TokenType.EQ, next.getOffset() + 2);
          fakeEquals.setNextWithoutSettingPrevious(next.getNext());
          return fakeEquals;
        }
        depth -= 2;
      }
      next = next.getNext();
View Full Code Here

      reportErrorForToken(ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.getStaticKeyword());
    }
    if (modifiers.getVarKeyword() != null) {
      reportErrorForToken(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, modifiers.getVarKeyword());
    }
    Token externalKeyword = modifiers.getExternalKeyword();
    Token constKeyword = modifiers.getConstKeyword();
    Token factoryKeyword = modifiers.getFactoryKeyword();
    if (externalKeyword != null && constKeyword != null
        && constKeyword.getOffset() < externalKeyword.getOffset()) {
      reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_CONST, externalKeyword);
    }
    if (externalKeyword != null && factoryKeyword != null
        && factoryKeyword.getOffset() < externalKeyword.getOffset()) {
      reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_FACTORY, externalKeyword);
    }
    return constKeyword;
  }
View Full Code Here

      reportErrorForToken(ParserErrorCode.EXTERNAL_FIELD, modifiers.getExternalKeyword());
    }
    if (modifiers.getFactoryKeyword() != null) {
      reportErrorForToken(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.getFactoryKeyword());
    }
    Token staticKeyword = modifiers.getStaticKeyword();
    Token constKeyword = modifiers.getConstKeyword();
    Token finalKeyword = modifiers.getFinalKeyword();
    Token varKeyword = modifiers.getVarKeyword();
    if (constKeyword != null) {
      if (finalKeyword != null) {
        reportErrorForToken(ParserErrorCode.CONST_AND_FINAL, finalKeyword);
      }
      if (varKeyword != null) {
        reportErrorForToken(ParserErrorCode.CONST_AND_VAR, varKeyword);
      }
      if (staticKeyword != null && constKeyword.getOffset() < staticKeyword.getOffset()) {
        reportErrorForToken(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword);
      }
    } else if (finalKeyword != null) {
      if (varKeyword != null) {
        reportErrorForToken(ParserErrorCode.FINAL_AND_VAR, varKeyword);
      }
      if (staticKeyword != null && finalKeyword.getOffset() < staticKeyword.getOffset()) {
        reportErrorForToken(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword);
      }
    } else if (varKeyword != null && staticKeyword != null
        && varKeyword.getOffset() < staticKeyword.getOffset()) {
      reportErrorForToken(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword);
    }
    return lexicallyFirst(constKeyword, finalKeyword, varKeyword);
  }
View Full Code Here

      reportErrorForToken(ParserErrorCode.FINAL_METHOD, modifiers.getFinalKeyword());
    }
    if (modifiers.getVarKeyword() != null) {
      reportErrorForToken(ParserErrorCode.VAR_RETURN_TYPE, modifiers.getVarKeyword());
    }
    Token externalKeyword = modifiers.getExternalKeyword();
    Token staticKeyword = modifiers.getStaticKeyword();
    if (externalKeyword != null && staticKeyword != null
        && staticKeyword.getOffset() < externalKeyword.getOffset()) {
      reportErrorForToken(ParserErrorCode.EXTERNAL_AFTER_STATIC, externalKeyword);
    }
  }
View Full Code Here

TOP

Related Classes of com.google.dart.engine.scanner.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.