Package com.google.dart.engine.scanner

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


        cloneNode(node.getIdentifier()));
  }

  @Override
  public SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) {
    Token mappedToken = mapToken(node.getToken());
    if (mappedToken == null) {
      // This only happens for SimpleIdentifiers created by the parser as part of scanning
      // documentation comments (the tokens for those identifiers are not in the original token
      // stream and hence do not get copied). This extra check can be removed if the scanner is
      // changed to scan documentation comments for the parser.
View Full Code Here


   * </pre>
   *
   * @return the annotation that was parsed
   */
  protected Annotation parseAnnotation() {
    Token atSign = expect(TokenType.AT);
    Identifier name = parsePrefixedIdentifier();
    Token period = null;
    SimpleIdentifier constructorName = null;
    if (matches(TokenType.PERIOD)) {
      period = getAndAdvance();
      constructorName = parseSimpleIdentifier();
    }
View Full Code Here

   * </pre>
   *
   * @return the argument list that was parsed
   */
  protected ArgumentList parseArgumentList() {
    Token leftParenthesis = expect(TokenType.OPEN_PAREN);
    List<Expression> arguments = new ArrayList<Expression>();
    if (matches(TokenType.CLOSE_PAREN)) {
      return new ArgumentList(leftParenthesis, arguments, getAndAdvance());
    }
    //
    // Even though unnamed arguments must all appear before any named arguments, we allow them to
    // appear in any order so that we can recover faster.
    //
    boolean wasInInitializer = inInitializer;
    inInitializer = false;
    try {
      Expression argument = parseArgument();
      arguments.add(argument);
      boolean foundNamedArgument = argument instanceof NamedExpression;
      boolean generatedError = false;
      while (optional(TokenType.COMMA)) {
        argument = parseArgument();
        arguments.add(argument);
        if (foundNamedArgument) {
          boolean blankArgument = argument instanceof SimpleIdentifier
              && ((SimpleIdentifier) argument).getName().isEmpty();
          if (!generatedError && !(argument instanceof NamedExpression && !blankArgument)) {
            // Report the error, once, but allow the arguments to be in any order in the AST.
            reportErrorForCurrentToken(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT);
            generatedError = true;
          }
        } else if (argument instanceof NamedExpression) {
          foundNamedArgument = true;
        }
      }
      // TODO(brianwilkerson) Recovery: Look at the left parenthesis to see whether there is a
      // matching right parenthesis. If there is, then we're more likely missing a comma and should
      // go back to parsing arguments.
      Token rightParenthesis = expect(TokenType.CLOSE_PAREN);
      return new ArgumentList(leftParenthesis, arguments, rightParenthesis);
    } finally {
      inInitializer = wasInInitializer;
    }
  }
View Full Code Here

      expression = new SuperExpression(getAndAdvance());
    } else {
      expression = parseBitwiseXorExpression();
    }
    while (matches(TokenType.BAR)) {
      Token operator = getAndAdvance();
      expression = new BinaryExpression(expression, operator, parseBitwiseXorExpression());
    }
    return expression;
  }
View Full Code Here

   * </pre>
   *
   * @return the block that was parsed
   */
  protected Block parseBlock() {
    Token leftBracket = expect(TokenType.OPEN_CURLY_BRACKET);
    List<Statement> statements = new ArrayList<Statement>();
    Token statementStart = currentToken;
    while (!matches(TokenType.EOF) && !matches(TokenType.CLOSE_CURLY_BRACKET)) {
      Statement statement = parseStatement();
      if (statement != null) {
        statements.add(statement);
      }
      if (currentToken == statementStart) {
        // Ensure that we are making progress and report an error if we're not.
        reportErrorForToken(
            ParserErrorCode.UNEXPECTED_TOKEN,
            currentToken,
            currentToken.getLexeme());
        advance();
      }
      statementStart = currentToken;
    }
    Token rightBracket = expect(TokenType.CLOSE_CURLY_BRACKET);
    return new Block(leftBracket, statements, rightBracket);
  }
View Full Code Here

        // We appear to have found an operator declaration without the 'operator' keyword.
        //
        validateModifiersForOperator(modifiers);
        return parseOperator(commentAndMetadata, modifiers.getExternalKeyword(), null);
      }
      Token keyword = modifiers.getVarKeyword();
      if (keyword == null) {
        keyword = modifiers.getFinalKeyword();
      }
      if (keyword == null) {
        keyword = modifiers.getConstKeyword();
View Full Code Here

   * </pre>
   *
   * @return the compilation unit that was parsed
   */
  protected CompilationUnit parseCompilationUnit() {
    Token firstToken = currentToken;
    ScriptTag scriptTag = null;
    if (matches(TokenType.SCRIPT_TAG)) {
      scriptTag = new ScriptTag(getAndAdvance());
    }
    //
    // Even though all directives must appear before declarations and must occur in a given order,
    // we allow directives and declarations to occur in any order so that we can recover better.
    //
    boolean libraryDirectiveFound = false;
    boolean partOfDirectiveFound = false;
    boolean partDirectiveFound = false;
    boolean directiveFoundAfterDeclaration = false;
    List<Directive> directives = new ArrayList<Directive>();
    List<CompilationUnitMember> declarations = new ArrayList<CompilationUnitMember>();
    Token memberStart = currentToken;
    while (!matches(TokenType.EOF)) {
      CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
      if ((matchesKeyword(Keyword.IMPORT) || matchesKeyword(Keyword.EXPORT)
          || matchesKeyword(Keyword.LIBRARY) || matchesKeyword(Keyword.PART))
          && !tokenMatches(peek(), TokenType.PERIOD)
View Full Code Here

  protected Expression parseConditionalExpression() {
    Expression condition = parseLogicalOrExpression();
    if (!matches(TokenType.QUESTION)) {
      return condition;
    }
    Token question = getAndAdvance();
    Expression thenExpression = parseExpressionWithoutCascade();
    Token colon = expect(TokenType.COLON);
    Expression elseExpression = parseExpressionWithoutCascade();
    return new ConditionalExpression(condition, question, thenExpression, colon, elseExpression);
  }
View Full Code Here

   *
   * @return the constructor name that was parsed
   */
  protected ConstructorName parseConstructorName() {
    TypeName type = parseTypeName();
    Token period = null;
    SimpleIdentifier name = null;
    if (matches(TokenType.PERIOD)) {
      period = getAndAdvance();
      name = parseSimpleIdentifier();
    }
View Full Code Here

        }
        tokenType = currentToken.getType();
      }
      return new CascadeExpression(expression, cascadeSections);
    } else if (tokenType.isAssignmentOperator()) {
      Token operator = getAndAdvance();
      ensureAssignable(expression);
      return new AssignmentExpression(expression, operator, parseExpression());
    }
    return expression;
  }
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.