| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.generated.parser; | 5 library analyzer.src.generated.parser; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import "dart:math" as math; | 8 import "dart:math" as math; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 5351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5362 /** | 5362 /** |
| 5363 * Parse a const expression. Return the const expression that was parsed. | 5363 * Parse a const expression. Return the const expression that was parsed. |
| 5364 * | 5364 * |
| 5365 * constExpression ::= | 5365 * constExpression ::= |
| 5366 * instanceCreationExpression | 5366 * instanceCreationExpression |
| 5367 * | listLiteral | 5367 * | listLiteral |
| 5368 * | mapLiteral | 5368 * | mapLiteral |
| 5369 */ | 5369 */ |
| 5370 Expression _parseConstExpression() { | 5370 Expression _parseConstExpression() { |
| 5371 Token keyword = _expectKeyword(Keyword.CONST); | 5371 Token keyword = _expectKeyword(Keyword.CONST); |
| 5372 if (_matches(TokenType.OPEN_SQUARE_BRACKET) || _matches(TokenType.INDEX)) { | 5372 if (_matches(TokenType.LT) || _injectGenericCommentTypeList()) { |
| 5373 return _parseListOrMapLiteral(keyword); |
| 5374 } else if (_matches(TokenType.OPEN_SQUARE_BRACKET) || _matches(TokenType.IND
EX)) { |
| 5373 return _parseListLiteral(keyword, null); | 5375 return _parseListLiteral(keyword, null); |
| 5374 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) { | 5376 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) { |
| 5375 return _parseMapLiteral(keyword, null); | 5377 return _parseMapLiteral(keyword, null); |
| 5376 } else if (_matches(TokenType.LT)) { | |
| 5377 return _parseListOrMapLiteral(keyword); | |
| 5378 } | 5378 } |
| 5379 return _parseInstanceCreationExpression(keyword); | 5379 return _parseInstanceCreationExpression(keyword); |
| 5380 } | 5380 } |
| 5381 | 5381 |
| 5382 ConstructorDeclaration _parseConstructor( | 5382 ConstructorDeclaration _parseConstructor( |
| 5383 CommentAndMetadata commentAndMetadata, | 5383 CommentAndMetadata commentAndMetadata, |
| 5384 Token externalKeyword, | 5384 Token externalKeyword, |
| 5385 Token constKeyword, | 5385 Token constKeyword, |
| 5386 Token factoryKeyword, | 5386 Token factoryKeyword, |
| 5387 SimpleIdentifier returnType, | 5387 SimpleIdentifier returnType, |
| (...skipping 1999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7387 Token token = getAndAdvance(); | 7387 Token token = getAndAdvance(); |
| 7388 int value = null; | 7388 int value = null; |
| 7389 try { | 7389 try { |
| 7390 value = int.parse(token.lexeme); | 7390 value = int.parse(token.lexeme); |
| 7391 } on FormatException { | 7391 } on FormatException { |
| 7392 // The invalid format should have been reported by the scanner. | 7392 // The invalid format should have been reported by the scanner. |
| 7393 } | 7393 } |
| 7394 return new IntegerLiteral(token, value); | 7394 return new IntegerLiteral(token, value); |
| 7395 } else if (_matches(TokenType.STRING)) { | 7395 } else if (_matches(TokenType.STRING)) { |
| 7396 return parseStringLiteral(); | 7396 return parseStringLiteral(); |
| 7397 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) { | |
| 7398 return _parseMapLiteral(null, null); | |
| 7399 } else if (_matches(TokenType.OPEN_SQUARE_BRACKET) || | |
| 7400 _matches(TokenType.INDEX)) { | |
| 7401 return _parseListLiteral(null, null); | |
| 7402 } else if (_matchesIdentifier()) { | 7397 } else if (_matchesIdentifier()) { |
| 7403 // TODO(brianwilkerson) The code below was an attempt to recover from an | 7398 // TODO(brianwilkerson) The code below was an attempt to recover from an |
| 7404 // error case, but it needs to be applied as a recovery only after we | 7399 // error case, but it needs to be applied as a recovery only after we |
| 7405 // know that parsing it as an identifier doesn't work. Leaving the code as | 7400 // know that parsing it as an identifier doesn't work. Leaving the code as |
| 7406 // a reminder of how to recover. | 7401 // a reminder of how to recover. |
| 7407 // if (isFunctionExpression(peek())) { | 7402 // if (isFunctionExpression(peek())) { |
| 7408 // // | 7403 // // |
| 7409 // // Function expressions were allowed to have names at one point,
but this is now illegal. | 7404 // // Function expressions were allowed to have names at one point,
but this is now illegal. |
| 7410 // // | 7405 // // |
| 7411 // reportError(ParserErrorCode.NAMED_FUNCTION_EXPRESSION, getAndAdv
ance()); | 7406 // reportError(ParserErrorCode.NAMED_FUNCTION_EXPRESSION, getAndAdv
ance()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 7424 bool wasInInitializer = _inInitializer; | 7419 bool wasInInitializer = _inInitializer; |
| 7425 _inInitializer = false; | 7420 _inInitializer = false; |
| 7426 try { | 7421 try { |
| 7427 Expression expression = parseExpression2(); | 7422 Expression expression = parseExpression2(); |
| 7428 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); | 7423 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 7429 return new ParenthesizedExpression( | 7424 return new ParenthesizedExpression( |
| 7430 leftParenthesis, expression, rightParenthesis); | 7425 leftParenthesis, expression, rightParenthesis); |
| 7431 } finally { | 7426 } finally { |
| 7432 _inInitializer = wasInInitializer; | 7427 _inInitializer = wasInInitializer; |
| 7433 } | 7428 } |
| 7434 } else if (_matches(TokenType.LT)) { | 7429 } else if (_matches(TokenType.LT) || _injectGenericCommentTypeList()) { |
| 7435 return _parseListOrMapLiteral(null); | 7430 return _parseListOrMapLiteral(null); |
| 7431 } else if (_matches(TokenType.OPEN_CURLY_BRACKET)) { |
| 7432 return _parseMapLiteral(null, null); |
| 7433 } else if (_matches(TokenType.OPEN_SQUARE_BRACKET) || |
| 7434 _matches(TokenType.INDEX)) { |
| 7435 return _parseListLiteral(null, null); |
| 7436 } else if (_matches(TokenType.QUESTION) && | 7436 } else if (_matches(TokenType.QUESTION) && |
| 7437 _tokenMatches(_peek(), TokenType.IDENTIFIER)) { | 7437 _tokenMatches(_peek(), TokenType.IDENTIFIER)) { |
| 7438 _reportErrorForCurrentToken( | 7438 _reportErrorForCurrentToken( |
| 7439 ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]); | 7439 ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]); |
| 7440 _advance(); | 7440 _advance(); |
| 7441 return _parsePrimaryExpression(); | 7441 return _parsePrimaryExpression(); |
| 7442 } else if (_matchesKeyword(Keyword.VOID)) { | 7442 } else if (_matchesKeyword(Keyword.VOID)) { |
| 7443 // | 7443 // |
| 7444 // Recover from having a return type of "void" where a return type is not | 7444 // Recover from having a return type of "void" where a return type is not |
| 7445 // expected. | 7445 // expected. |
| (...skipping 3910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11356 } | 11356 } |
| 11357 | 11357 |
| 11358 /** | 11358 /** |
| 11359 * Copy resolution data from the [fromNode] to the [toNode]. | 11359 * Copy resolution data from the [fromNode] to the [toNode]. |
| 11360 */ | 11360 */ |
| 11361 static void copyResolutionData(AstNode fromNode, AstNode toNode) { | 11361 static void copyResolutionData(AstNode fromNode, AstNode toNode) { |
| 11362 ResolutionCopier copier = new ResolutionCopier(); | 11362 ResolutionCopier copier = new ResolutionCopier(); |
| 11363 copier._isEqualNodes(fromNode, toNode); | 11363 copier._isEqualNodes(fromNode, toNode); |
| 11364 } | 11364 } |
| 11365 } | 11365 } |
| OLD | NEW |