| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 fasta.parser.parser; | 5 library fasta.parser.parser; |
| 6 | 6 |
| 7 import '../scanner.dart' show ErrorToken; | 7 import '../scanner.dart' show ErrorToken; |
| 8 | 8 |
| 9 import '../scanner/recover.dart' show closeBraceFor, skipToEof; | 9 import '../scanner/recover.dart' show closeBraceFor, skipToEof; |
| 10 | 10 |
| (...skipping 2672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2683 | 2683 |
| 2684 Token parseParenthesizedExpressionOrFunctionLiteral(Token token) { | 2684 Token parseParenthesizedExpressionOrFunctionLiteral(Token token) { |
| 2685 BeginGroupToken beginGroup = token; | 2685 BeginGroupToken beginGroup = token; |
| 2686 // TODO(eernst): Check for NPE as described in issue 26252. | 2686 // TODO(eernst): Check for NPE as described in issue 26252. |
| 2687 Token nextToken = beginGroup.endGroup.next; | 2687 Token nextToken = beginGroup.endGroup.next; |
| 2688 int kind = nextToken.kind; | 2688 int kind = nextToken.kind; |
| 2689 if (mayParseFunctionExpressions && | 2689 if (mayParseFunctionExpressions && |
| 2690 (identical(kind, FUNCTION_TOKEN) || | 2690 (identical(kind, FUNCTION_TOKEN) || |
| 2691 identical(kind, OPEN_CURLY_BRACKET_TOKEN) || | 2691 identical(kind, OPEN_CURLY_BRACKET_TOKEN) || |
| 2692 (identical(kind, KEYWORD_TOKEN) && | 2692 (identical(kind, KEYWORD_TOKEN) && |
| 2693 (nextToken.value == 'async' || nextToken.value == 'sync')))) { | 2693 (nextToken.lexeme == 'async' || nextToken.lexeme == 'sync')))) { |
| 2694 listener.handleNoTypeVariables(token); | 2694 listener.handleNoTypeVariables(token); |
| 2695 return parseUnnamedFunction(token); | 2695 return parseUnnamedFunction(token); |
| 2696 } else { | 2696 } else { |
| 2697 bool old = mayParseFunctionExpressions; | 2697 bool old = mayParseFunctionExpressions; |
| 2698 mayParseFunctionExpressions = true; | 2698 mayParseFunctionExpressions = true; |
| 2699 token = parseParenthesizedExpression(token); | 2699 token = parseParenthesizedExpression(token); |
| 2700 mayParseFunctionExpressions = old; | 2700 mayParseFunctionExpressions = old; |
| 2701 return token; | 2701 return token; |
| 2702 } | 2702 } |
| 2703 } | 2703 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2802 /// been parsed, or `listener.handleNoTypeArguments(..)` has been executed. | 2802 /// been parsed, or `listener.handleNoTypeArguments(..)` has been executed. |
| 2803 Token parseLiteralFunctionSuffix(Token token) { | 2803 Token parseLiteralFunctionSuffix(Token token) { |
| 2804 assert(optional('(', token)); | 2804 assert(optional('(', token)); |
| 2805 BeginGroupToken beginGroup = token; | 2805 BeginGroupToken beginGroup = token; |
| 2806 if (beginGroup.endGroup != null) { | 2806 if (beginGroup.endGroup != null) { |
| 2807 Token nextToken = beginGroup.endGroup.next; | 2807 Token nextToken = beginGroup.endGroup.next; |
| 2808 int kind = nextToken.kind; | 2808 int kind = nextToken.kind; |
| 2809 if (identical(kind, FUNCTION_TOKEN) || | 2809 if (identical(kind, FUNCTION_TOKEN) || |
| 2810 identical(kind, OPEN_CURLY_BRACKET_TOKEN) || | 2810 identical(kind, OPEN_CURLY_BRACKET_TOKEN) || |
| 2811 (identical(kind, KEYWORD_TOKEN) && | 2811 (identical(kind, KEYWORD_TOKEN) && |
| 2812 (nextToken.value == 'async' || nextToken.value == 'sync'))) { | 2812 (nextToken.lexeme == 'async' || nextToken.lexeme == 'sync'))) { |
| 2813 return parseUnnamedFunction(token); | 2813 return parseUnnamedFunction(token); |
| 2814 } | 2814 } |
| 2815 // Fall through. | 2815 // Fall through. |
| 2816 } | 2816 } |
| 2817 reportUnrecoverableError(token, ErrorKind.UnexpectedToken); | 2817 reportUnrecoverableError(token, ErrorKind.UnexpectedToken); |
| 2818 return null; | 2818 return null; |
| 2819 } | 2819 } |
| 2820 | 2820 |
| 2821 /// genericListLiteral | genericMapLiteral | genericFunctionLiteral. | 2821 /// genericListLiteral | genericMapLiteral | genericFunctionLiteral. |
| 2822 /// | 2822 /// |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3522 } | 3522 } |
| 3523 | 3523 |
| 3524 /// Don't call this method. Should only be used as a last resort when there | 3524 /// Don't call this method. Should only be used as a last resort when there |
| 3525 /// is no feasible way to recover from a parser error. | 3525 /// is no feasible way to recover from a parser error. |
| 3526 Token reportUnrecoverableError(Token token, ErrorKind kind, [Map arguments]) { | 3526 Token reportUnrecoverableError(Token token, ErrorKind kind, [Map arguments]) { |
| 3527 Token next; | 3527 Token next; |
| 3528 if (token is ErrorToken) { | 3528 if (token is ErrorToken) { |
| 3529 next = reportErrorToken(token, false); | 3529 next = reportErrorToken(token, false); |
| 3530 } else { | 3530 } else { |
| 3531 arguments ??= {}; | 3531 arguments ??= {}; |
| 3532 arguments.putIfAbsent("actual", () => token.value); | 3532 arguments.putIfAbsent("actual", () => token.lexeme); |
| 3533 next = listener.handleUnrecoverableError(token, kind, arguments)?.next; | 3533 next = listener.handleUnrecoverableError(token, kind, arguments)?.next; |
| 3534 } | 3534 } |
| 3535 return next ?? skipToEof(token); | 3535 return next ?? skipToEof(token); |
| 3536 } | 3536 } |
| 3537 | 3537 |
| 3538 void reportRecoverableError(Token token, ErrorKind kind, [Map arguments]) { | 3538 void reportRecoverableError(Token token, ErrorKind kind, [Map arguments]) { |
| 3539 if (token is ErrorToken) { | 3539 if (token is ErrorToken) { |
| 3540 reportErrorToken(token, true); | 3540 reportErrorToken(token, true); |
| 3541 } else { | 3541 } else { |
| 3542 arguments ??= {}; | 3542 arguments ??= {}; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3558 hex = "$padding$hex"; | 3558 hex = "$padding$hex"; |
| 3559 } | 3559 } |
| 3560 arguments = {'characterHex': hex}; | 3560 arguments = {'characterHex': hex}; |
| 3561 break; | 3561 break; |
| 3562 | 3562 |
| 3563 case ErrorKind.UnterminatedString: | 3563 case ErrorKind.UnterminatedString: |
| 3564 arguments = {'quote': token.start}; | 3564 arguments = {'quote': token.start}; |
| 3565 break; | 3565 break; |
| 3566 | 3566 |
| 3567 case ErrorKind.UnmatchedToken: | 3567 case ErrorKind.UnmatchedToken: |
| 3568 String begin = token.begin.value; | 3568 String begin = token.begin.lexeme; |
| 3569 String end = closeBraceFor(begin); | 3569 String end = closeBraceFor(begin); |
| 3570 arguments = {'begin': begin, 'end': end}; | 3570 arguments = {'begin': begin, 'end': end}; |
| 3571 break; | 3571 break; |
| 3572 | 3572 |
| 3573 case ErrorKind.Unspecified: | 3573 case ErrorKind.Unspecified: |
| 3574 arguments = {"text": token.assertionMessage}; | 3574 arguments = {"text": token.assertionMessage}; |
| 3575 break; | 3575 break; |
| 3576 | 3576 |
| 3577 default: | 3577 default: |
| 3578 break; | 3578 break; |
| 3579 } | 3579 } |
| 3580 if (isRecoverable) { | 3580 if (isRecoverable) { |
| 3581 listener.handleRecoverableError(token, kind, arguments); | 3581 listener.handleRecoverableError(token, kind, arguments); |
| 3582 return null; | 3582 return null; |
| 3583 } else { | 3583 } else { |
| 3584 return listener.handleUnrecoverableError(token, kind, arguments)?.next; | 3584 return listener.handleUnrecoverableError(token, kind, arguments)?.next; |
| 3585 } | 3585 } |
| 3586 } | 3586 } |
| 3587 } | 3587 } |
| OLD | NEW |