| 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/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 _createSyntheticToken(TokenType.OPEN_PAREN), | 1372 _createSyntheticToken(TokenType.OPEN_PAREN), |
| 1373 <FormalParameter>[], | 1373 <FormalParameter>[], |
| 1374 null, | 1374 null, |
| 1375 null, | 1375 null, |
| 1376 _createSyntheticToken(TokenType.CLOSE_PAREN)), | 1376 _createSyntheticToken(TokenType.CLOSE_PAREN)), |
| 1377 astFactory | 1377 astFactory |
| 1378 .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON))); | 1378 .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON))); |
| 1379 } | 1379 } |
| 1380 return null; | 1380 return null; |
| 1381 } else if (_tokenMatches(next, TokenType.PERIOD) && | 1381 } else if (_tokenMatches(next, TokenType.PERIOD) && |
| 1382 _tokenMatchesIdentifier(_peekAt(2)) && | 1382 _tokenMatchesIdentifierOrKeyword(_peekAt(2)) && |
| 1383 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) { | 1383 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) { |
| 1384 if (!_tokenMatchesIdentifier(_peekAt(2))) { |
| 1385 _reportErrorForToken(ParserErrorCode.INVALID_CONSTRUCTOR_NAME, |
| 1386 _peekAt(2), [_peekAt(2).lexeme]); |
| 1387 } |
| 1384 return _parseConstructor( | 1388 return _parseConstructor( |
| 1385 commentAndMetadata, | 1389 commentAndMetadata, |
| 1386 modifiers.externalKeyword, | 1390 modifiers.externalKeyword, |
| 1387 _validateModifiersForConstructor(modifiers), | 1391 _validateModifiersForConstructor(modifiers), |
| 1388 modifiers.factoryKeyword, | 1392 modifiers.factoryKeyword, |
| 1389 parseSimpleIdentifier(), | 1393 parseSimpleIdentifier(), |
| 1390 getAndAdvance(), | 1394 getAndAdvance(), |
| 1391 parseSimpleIdentifier(isDeclaration: true), | 1395 parseSimpleIdentifier(allowKeyword: true, isDeclaration: true), |
| 1392 parseFormalParameterList()); | 1396 parseFormalParameterList()); |
| 1393 } else if (_tokenMatches(next, TokenType.OPEN_PAREN)) { | 1397 } else if (_tokenMatches(next, TokenType.OPEN_PAREN)) { |
| 1394 TypeName returnType = _parseOptionalTypeNameComment(); | 1398 TypeName returnType = _parseOptionalTypeNameComment(); |
| 1395 SimpleIdentifier methodName = parseSimpleIdentifier(isDeclaration: true); | 1399 SimpleIdentifier methodName = parseSimpleIdentifier(isDeclaration: true); |
| 1396 TypeParameterList typeParameters = _parseGenericCommentTypeParameters(); | 1400 TypeParameterList typeParameters = _parseGenericCommentTypeParameters(); |
| 1397 FormalParameterList parameters = parseFormalParameterList(); | 1401 FormalParameterList parameters = parseFormalParameterList(); |
| 1398 if (_matches(TokenType.COLON) || | 1402 if (_matches(TokenType.COLON) || |
| 1399 modifiers.factoryKeyword != null || | 1403 modifiers.factoryKeyword != null || |
| 1400 methodName.name == className) { | 1404 methodName.name == className) { |
| 1401 return _parseConstructor( | 1405 return _parseConstructor( |
| (...skipping 3273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4675 } | 4679 } |
| 4676 return expression; | 4680 return expression; |
| 4677 } | 4681 } |
| 4678 | 4682 |
| 4679 /** | 4683 /** |
| 4680 * Parse a simple identifier. Return the simple identifier that was parsed. | 4684 * Parse a simple identifier. Return the simple identifier that was parsed. |
| 4681 * | 4685 * |
| 4682 * identifier ::= | 4686 * identifier ::= |
| 4683 * IDENTIFIER | 4687 * IDENTIFIER |
| 4684 */ | 4688 */ |
| 4685 SimpleIdentifier parseSimpleIdentifier({bool isDeclaration: false}) { | 4689 SimpleIdentifier parseSimpleIdentifier( |
| 4686 if (_matchesIdentifier()) { | 4690 {bool allowKeyword: false, bool isDeclaration: false}) { |
| 4691 if (_matchesIdentifier() || |
| 4692 (allowKeyword && _tokenMatchesIdentifierOrKeyword(_currentToken))) { |
| 4687 return _parseSimpleIdentifierUnchecked(isDeclaration: isDeclaration); | 4693 return _parseSimpleIdentifierUnchecked(isDeclaration: isDeclaration); |
| 4688 } | 4694 } |
| 4689 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); | 4695 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); |
| 4690 return createSyntheticIdentifier(isDeclaration: isDeclaration); | 4696 return createSyntheticIdentifier(isDeclaration: isDeclaration); |
| 4691 } | 4697 } |
| 4692 | 4698 |
| 4693 /** | 4699 /** |
| 4694 * Parse a statement, starting with the given [token]. Return the statement | 4700 * Parse a statement, starting with the given [token]. Return the statement |
| 4695 * that was parsed, or `null` if the tokens do not represent a recognizable | 4701 * that was parsed, or `null` if the tokens do not represent a recognizable |
| 4696 * statement. | 4702 * statement. |
| (...skipping 3258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7955 | 7961 |
| 7956 /** | 7962 /** |
| 7957 * Return `true` if the given [token] is a valid identifier. Valid identifiers | 7963 * Return `true` if the given [token] is a valid identifier. Valid identifiers |
| 7958 * include built-in identifiers (pseudo-keywords). | 7964 * include built-in identifiers (pseudo-keywords). |
| 7959 */ | 7965 */ |
| 7960 bool _tokenMatchesIdentifier(Token token) => | 7966 bool _tokenMatchesIdentifier(Token token) => |
| 7961 _tokenMatches(token, TokenType.IDENTIFIER) || | 7967 _tokenMatches(token, TokenType.IDENTIFIER) || |
| 7962 _tokenMatchesPseudoKeyword(token); | 7968 _tokenMatchesPseudoKeyword(token); |
| 7963 | 7969 |
| 7964 /** | 7970 /** |
| 7971 * Return `true` if the given [token] is either an identifier or a keyword. |
| 7972 */ |
| 7973 bool _tokenMatchesIdentifierOrKeyword(Token token) => |
| 7974 _tokenMatches(token, TokenType.IDENTIFIER) || |
| 7975 _tokenMatches(token, TokenType.KEYWORD); |
| 7976 |
| 7977 /** |
| 7965 * Return `true` if the given [token] matches the given [keyword]. | 7978 * Return `true` if the given [token] matches the given [keyword]. |
| 7966 */ | 7979 */ |
| 7967 bool _tokenMatchesKeyword(Token token, Keyword keyword) => | 7980 bool _tokenMatchesKeyword(Token token, Keyword keyword) => |
| 7968 token.keyword == keyword; | 7981 token.keyword == keyword; |
| 7969 | 7982 |
| 7970 /** | 7983 /** |
| 7971 * Return `true` if the given [token] matches a pseudo keyword. | 7984 * Return `true` if the given [token] matches a pseudo keyword. |
| 7972 */ | 7985 */ |
| 7973 bool _tokenMatchesPseudoKeyword(Token token) => | 7986 bool _tokenMatchesPseudoKeyword(Token token) => |
| 7974 token.keyword?.isPseudoKeyword ?? false; | 7987 token.keyword?.isPseudoKeyword ?? false; |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8493 */ | 8506 */ |
| 8494 Parser_SyntheticKeywordToken(Keyword keyword, int offset) | 8507 Parser_SyntheticKeywordToken(Keyword keyword, int offset) |
| 8495 : super(keyword, offset); | 8508 : super(keyword, offset); |
| 8496 | 8509 |
| 8497 @override | 8510 @override |
| 8498 int get length => 0; | 8511 int get length => 0; |
| 8499 | 8512 |
| 8500 @override | 8513 @override |
| 8501 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); | 8514 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); |
| 8502 } | 8515 } |
| OLD | NEW |