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 import 'dart:collection'; | 5 import 'dart:collection'; |
6 import "dart:math" as math; | 6 import "dart:math" as math; |
7 | 7 |
8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
9 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1268 Token next = _peek(); | 1268 Token next = _peek(); |
1269 bool isFollowedByIdentifier = _tokenMatchesIdentifier(next); | 1269 bool isFollowedByIdentifier = _tokenMatchesIdentifier(next); |
1270 if (keyword == Keyword.GET && isFollowedByIdentifier) { | 1270 if (keyword == Keyword.GET && isFollowedByIdentifier) { |
1271 _validateModifiersForGetterOrSetterOrMethod(modifiers); | 1271 _validateModifiersForGetterOrSetterOrMethod(modifiers); |
1272 return parseGetter(commentAndMetadata, modifiers.externalKeyword, | 1272 return parseGetter(commentAndMetadata, modifiers.externalKeyword, |
1273 modifiers.staticKeyword, returnType); | 1273 modifiers.staticKeyword, returnType); |
1274 } else if (keyword == Keyword.SET && isFollowedByIdentifier) { | 1274 } else if (keyword == Keyword.SET && isFollowedByIdentifier) { |
1275 _validateModifiersForGetterOrSetterOrMethod(modifiers); | 1275 _validateModifiersForGetterOrSetterOrMethod(modifiers); |
1276 return parseSetter(commentAndMetadata, modifiers.externalKeyword, | 1276 return parseSetter(commentAndMetadata, modifiers.externalKeyword, |
1277 modifiers.staticKeyword, returnType); | 1277 modifiers.staticKeyword, returnType); |
1278 } else if (keyword == Keyword.OPERATOR && _isOperator(next)) { | 1278 } else if (keyword == Keyword.OPERATOR && |
1279 (_isOperator(next) || next.type == TokenType.EQ_EQ_EQ)) { | |
Brian Wilkerson
2017/06/06 14:00:17
What is "==="?
That operator hasn't been part of
danrubel
2017/06/07 15:03:46
Good question. It exists for the purpose of better
| |
1279 _validateModifiersForOperator(modifiers); | 1280 _validateModifiersForOperator(modifiers); |
1280 return _parseOperatorAfterKeyword(commentAndMetadata, | 1281 return _parseOperatorAfterKeyword(commentAndMetadata, |
1281 modifiers.externalKeyword, returnType, getAndAdvance()); | 1282 modifiers.externalKeyword, returnType, getAndAdvance()); |
1282 } else if (_matchesIdentifier() && | 1283 } else if (_matchesIdentifier() && |
1283 _peek().matchesAny(const <TokenType>[ | 1284 _peek().matchesAny(const <TokenType>[ |
1284 TokenType.OPEN_PAREN, | 1285 TokenType.OPEN_PAREN, |
1285 TokenType.OPEN_CURLY_BRACKET, | 1286 TokenType.OPEN_CURLY_BRACKET, |
1286 TokenType.FUNCTION, | 1287 TokenType.FUNCTION, |
1287 TokenType.LT | 1288 TokenType.LT |
1288 ])) { | 1289 ])) { |
(...skipping 5913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7202 * operatorSignature ::= | 7203 * operatorSignature ::= |
7203 * 'external'? returnType? 'operator' operator formalParameterList | 7204 * 'external'? returnType? 'operator' operator formalParameterList |
7204 */ | 7205 */ |
7205 MethodDeclaration _parseOperatorAfterKeyword( | 7206 MethodDeclaration _parseOperatorAfterKeyword( |
7206 CommentAndMetadata commentAndMetadata, | 7207 CommentAndMetadata commentAndMetadata, |
7207 Token externalKeyword, | 7208 Token externalKeyword, |
7208 TypeAnnotation returnType, | 7209 TypeAnnotation returnType, |
7209 Token operatorKeyword) { | 7210 Token operatorKeyword) { |
7210 if (!_currentToken.isUserDefinableOperator) { | 7211 if (!_currentToken.isUserDefinableOperator) { |
7211 _reportErrorForCurrentToken( | 7212 _reportErrorForCurrentToken( |
7212 ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken.lexeme]); | 7213 _currentToken.type == TokenType.EQ_EQ_EQ |
7214 ? ParserErrorCode.INVALID_OPERATOR | |
7215 : ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, | |
7216 [_currentToken.lexeme]); | |
7213 } | 7217 } |
7214 SimpleIdentifier name = | 7218 SimpleIdentifier name = |
7215 astFactory.simpleIdentifier(getAndAdvance(), isDeclaration: true); | 7219 astFactory.simpleIdentifier(getAndAdvance(), isDeclaration: true); |
7216 if (_matches(TokenType.EQ)) { | 7220 if (_matches(TokenType.EQ)) { |
7217 Token previous = _currentToken.previous; | 7221 Token previous = _currentToken.previous; |
7218 if ((_tokenMatches(previous, TokenType.EQ_EQ) || | 7222 if ((_tokenMatches(previous, TokenType.EQ_EQ) || |
7219 _tokenMatches(previous, TokenType.BANG_EQ)) && | 7223 _tokenMatches(previous, TokenType.BANG_EQ)) && |
7220 _currentToken.offset == previous.offset + 2) { | 7224 _currentToken.offset == previous.offset + 2) { |
7221 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR, | 7225 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR, |
7222 ["${previous.lexeme}${_currentToken.lexeme}"]); | 7226 ["${previous.lexeme}${_currentToken.lexeme}"]); |
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8598 } | 8602 } |
8599 } | 8603 } |
8600 } | 8604 } |
8601 | 8605 |
8602 /** | 8606 /** |
8603 * Instances of this class are thrown when the parser detects that AST has | 8607 * Instances of this class are thrown when the parser detects that AST has |
8604 * too many nested expressions to be parsed safely and avoid possibility of | 8608 * too many nested expressions to be parsed safely and avoid possibility of |
8605 * [StackOverflowError] in the parser or during later analysis. | 8609 * [StackOverflowError] in the parser or during later analysis. |
8606 */ | 8610 */ |
8607 class _TooDeepTreeError {} | 8611 class _TooDeepTreeError {} |
OLD | NEW |