| 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'; |
| 11 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | |
| 12 import 'package:analyzer/dart/ast/token.dart'; | 11 import 'package:analyzer/dart/ast/token.dart'; |
| 13 import 'package:analyzer/error/error.dart'; | 12 import 'package:analyzer/error/error.dart'; |
| 14 import 'package:analyzer/error/listener.dart'; | 13 import 'package:analyzer/error/listener.dart'; |
| 15 import 'package:analyzer/src/dart/ast/ast.dart'; | 14 import 'package:analyzer/src/dart/ast/ast.dart'; |
| 16 import 'package:analyzer/src/dart/ast/token.dart'; | 15 import 'package:analyzer/src/dart/ast/token.dart'; |
| 17 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; | 16 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; |
| 18 import 'package:analyzer/src/dart/scanner/reader.dart'; | 17 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 19 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 18 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 20 import 'package:analyzer/src/error/codes.dart'; | 19 import 'package:analyzer/src/error/codes.dart'; |
| 21 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; | 20 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 // Consider current keyword token as an identifier. | 386 // Consider current keyword token as an identifier. |
| 388 // It is not always true, e.g. "^is T" where "^" is place the place for | 387 // It is not always true, e.g. "^is T" where "^" is place the place for |
| 389 // synthetic identifier. By creating SyntheticStringToken we can | 388 // synthetic identifier. By creating SyntheticStringToken we can |
| 390 // distinguish a real identifier from synthetic. In the code completion | 389 // distinguish a real identifier from synthetic. In the code completion |
| 391 // behavior will depend on a cursor position - before or on "is". | 390 // behavior will depend on a cursor position - before or on "is". |
| 392 syntheticToken = _injectToken(new SyntheticStringToken( | 391 syntheticToken = _injectToken(new SyntheticStringToken( |
| 393 TokenType.IDENTIFIER, _currentToken.lexeme, _currentToken.offset)); | 392 TokenType.IDENTIFIER, _currentToken.lexeme, _currentToken.offset)); |
| 394 } else { | 393 } else { |
| 395 syntheticToken = _createSyntheticToken(TokenType.IDENTIFIER); | 394 syntheticToken = _createSyntheticToken(TokenType.IDENTIFIER); |
| 396 } | 395 } |
| 397 return astFactory.simpleIdentifier(syntheticToken, | 396 return new SimpleIdentifier(syntheticToken, isDeclaration: isDeclaration); |
| 398 isDeclaration: isDeclaration); | |
| 399 } | 397 } |
| 400 | 398 |
| 401 /** | 399 /** |
| 402 * Return a synthetic string literal. | 400 * Return a synthetic string literal. |
| 403 */ | 401 */ |
| 404 SimpleStringLiteral createSyntheticStringLiteral() => astFactory | 402 SimpleStringLiteral createSyntheticStringLiteral() => |
| 405 .simpleStringLiteral(_createSyntheticToken(TokenType.STRING), ""); | 403 new SimpleStringLiteral(_createSyntheticToken(TokenType.STRING), ""); |
| 406 | 404 |
| 407 /** | 405 /** |
| 408 * Advance to the next token in the token stream, making it the new current | 406 * Advance to the next token in the token stream, making it the new current |
| 409 * token and return the token that was current before this method was invoked. | 407 * token and return the token that was current before this method was invoked. |
| 410 */ | 408 */ |
| 411 Token getAndAdvance() { | 409 Token getAndAdvance() { |
| 412 Token token = _currentToken; | 410 Token token = _currentToken; |
| 413 _currentToken = _currentToken.next; | 411 _currentToken = _currentToken.next; |
| 414 return token; | 412 return token; |
| 415 } | 413 } |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 * parsed. | 592 * parsed. |
| 595 * | 593 * |
| 596 * additiveExpression ::= | 594 * additiveExpression ::= |
| 597 * multiplicativeExpression (additiveOperator multiplicativeExpression
)* | 595 * multiplicativeExpression (additiveOperator multiplicativeExpression
)* |
| 598 * | 'super' (additiveOperator multiplicativeExpression)+ | 596 * | 'super' (additiveOperator multiplicativeExpression)+ |
| 599 */ | 597 */ |
| 600 Expression parseAdditiveExpression() { | 598 Expression parseAdditiveExpression() { |
| 601 Expression expression; | 599 Expression expression; |
| 602 if (_currentToken.keyword == Keyword.SUPER && | 600 if (_currentToken.keyword == Keyword.SUPER && |
| 603 _currentToken.next.type.isAdditiveOperator) { | 601 _currentToken.next.type.isAdditiveOperator) { |
| 604 expression = astFactory.superExpression(getAndAdvance()); | 602 expression = new SuperExpression(getAndAdvance()); |
| 605 } else { | 603 } else { |
| 606 expression = parseMultiplicativeExpression(); | 604 expression = parseMultiplicativeExpression(); |
| 607 } | 605 } |
| 608 while (_currentToken.type.isAdditiveOperator) { | 606 while (_currentToken.type.isAdditiveOperator) { |
| 609 expression = astFactory.binaryExpression( | 607 expression = new BinaryExpression( |
| 610 expression, getAndAdvance(), parseMultiplicativeExpression()); | 608 expression, getAndAdvance(), parseMultiplicativeExpression()); |
| 611 } | 609 } |
| 612 return expression; | 610 return expression; |
| 613 } | 611 } |
| 614 | 612 |
| 615 /** | 613 /** |
| 616 * Parse an annotation. Return the annotation that was parsed. | 614 * Parse an annotation. Return the annotation that was parsed. |
| 617 * | 615 * |
| 618 * This method assumes that the current token matches [TokenType.AT]. | 616 * This method assumes that the current token matches [TokenType.AT]. |
| 619 * | 617 * |
| 620 * annotation ::= | 618 * annotation ::= |
| 621 * '@' qualified ('.' identifier)? arguments? | 619 * '@' qualified ('.' identifier)? arguments? |
| 622 */ | 620 */ |
| 623 Annotation parseAnnotation() { | 621 Annotation parseAnnotation() { |
| 624 Token atSign = getAndAdvance(); | 622 Token atSign = getAndAdvance(); |
| 625 Identifier name = parsePrefixedIdentifier(); | 623 Identifier name = parsePrefixedIdentifier(); |
| 626 Token period = null; | 624 Token period = null; |
| 627 SimpleIdentifier constructorName = null; | 625 SimpleIdentifier constructorName = null; |
| 628 if (_matches(TokenType.PERIOD)) { | 626 if (_matches(TokenType.PERIOD)) { |
| 629 period = getAndAdvance(); | 627 period = getAndAdvance(); |
| 630 constructorName = parseSimpleIdentifier(); | 628 constructorName = parseSimpleIdentifier(); |
| 631 } | 629 } |
| 632 ArgumentList arguments = null; | 630 ArgumentList arguments = null; |
| 633 if (_matches(TokenType.OPEN_PAREN)) { | 631 if (_matches(TokenType.OPEN_PAREN)) { |
| 634 arguments = parseArgumentList(); | 632 arguments = parseArgumentList(); |
| 635 } | 633 } |
| 636 return astFactory.annotation( | 634 return new Annotation(atSign, name, period, constructorName, arguments); |
| 637 atSign, name, period, constructorName, arguments); | |
| 638 } | 635 } |
| 639 | 636 |
| 640 /** | 637 /** |
| 641 * Parse an argument. Return the argument that was parsed. | 638 * Parse an argument. Return the argument that was parsed. |
| 642 * | 639 * |
| 643 * argument ::= | 640 * argument ::= |
| 644 * namedArgument | 641 * namedArgument |
| 645 * | expression | 642 * | expression |
| 646 * | 643 * |
| 647 * namedArgument ::= | 644 * namedArgument ::= |
| 648 * label expression | 645 * label expression |
| 649 */ | 646 */ |
| 650 Expression parseArgument() { | 647 Expression parseArgument() { |
| 651 // TODO(brianwilkerson) Consider returning a wrapper indicating whether the | 648 // TODO(brianwilkerson) Consider returning a wrapper indicating whether the |
| 652 // expression is a named expression in order to remove the 'is' check in | 649 // expression is a named expression in order to remove the 'is' check in |
| 653 // 'parseArgumentList'. | 650 // 'parseArgumentList'. |
| 654 // | 651 // |
| 655 // Both namedArgument and expression can start with an identifier, but only | 652 // Both namedArgument and expression can start with an identifier, but only |
| 656 // namedArgument can have an identifier followed by a colon. | 653 // namedArgument can have an identifier followed by a colon. |
| 657 // | 654 // |
| 658 if (_matchesIdentifier() && _tokenMatches(_peek(), TokenType.COLON)) { | 655 if (_matchesIdentifier() && _tokenMatches(_peek(), TokenType.COLON)) { |
| 659 return astFactory.namedExpression(parseLabel(), parseExpression2()); | 656 return new NamedExpression(parseLabel(), parseExpression2()); |
| 660 } else { | 657 } else { |
| 661 return parseExpression2(); | 658 return parseExpression2(); |
| 662 } | 659 } |
| 663 } | 660 } |
| 664 | 661 |
| 665 /** | 662 /** |
| 666 * Parse a list of arguments. Return the argument list that was parsed. | 663 * Parse a list of arguments. Return the argument list that was parsed. |
| 667 * | 664 * |
| 668 * This method assumes that the current token matches [TokenType.OPEN_PAREN]. | 665 * This method assumes that the current token matches [TokenType.OPEN_PAREN]. |
| 669 * | 666 * |
| 670 * arguments ::= | 667 * arguments ::= |
| 671 * '(' argumentList? ')' | 668 * '(' argumentList? ')' |
| 672 * | 669 * |
| 673 * argumentList ::= | 670 * argumentList ::= |
| 674 * namedArgument (',' namedArgument)* | 671 * namedArgument (',' namedArgument)* |
| 675 * | expressionList (',' namedArgument)* | 672 * | expressionList (',' namedArgument)* |
| 676 */ | 673 */ |
| 677 ArgumentList parseArgumentList() { | 674 ArgumentList parseArgumentList() { |
| 678 Token leftParenthesis = getAndAdvance(); | 675 Token leftParenthesis = getAndAdvance(); |
| 679 if (_matches(TokenType.CLOSE_PAREN)) { | 676 if (_matches(TokenType.CLOSE_PAREN)) { |
| 680 return astFactory.argumentList(leftParenthesis, null, getAndAdvance()); | 677 return new ArgumentList(leftParenthesis, null, getAndAdvance()); |
| 681 } | 678 } |
| 682 // | 679 // |
| 683 // Even though unnamed arguments must all appear before any named arguments, | 680 // Even though unnamed arguments must all appear before any named arguments, |
| 684 // we allow them to appear in any order so that we can recover faster. | 681 // we allow them to appear in any order so that we can recover faster. |
| 685 // | 682 // |
| 686 bool wasInInitializer = _inInitializer; | 683 bool wasInInitializer = _inInitializer; |
| 687 _inInitializer = false; | 684 _inInitializer = false; |
| 688 try { | 685 try { |
| 689 Expression argument = parseArgument(); | 686 Expression argument = parseArgument(); |
| 690 List<Expression> arguments = <Expression>[argument]; | 687 List<Expression> arguments = <Expression>[argument]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 708 generatedError = true; | 705 generatedError = true; |
| 709 } | 706 } |
| 710 } | 707 } |
| 711 } | 708 } |
| 712 } | 709 } |
| 713 // Recovery: If the next token is not a right parenthesis, look at the | 710 // Recovery: If the next token is not a right parenthesis, look at the |
| 714 // left parenthesis to see whether there is a matching right parenthesis. | 711 // left parenthesis to see whether there is a matching right parenthesis. |
| 715 // If there is, then we're more likely missing a comma and should go back | 712 // If there is, then we're more likely missing a comma and should go back |
| 716 // to parsing arguments. | 713 // to parsing arguments. |
| 717 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); | 714 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 718 return astFactory.argumentList( | 715 return new ArgumentList(leftParenthesis, arguments, rightParenthesis); |
| 719 leftParenthesis, arguments, rightParenthesis); | |
| 720 } finally { | 716 } finally { |
| 721 _inInitializer = wasInInitializer; | 717 _inInitializer = wasInInitializer; |
| 722 } | 718 } |
| 723 } | 719 } |
| 724 | 720 |
| 725 /** | 721 /** |
| 726 * Parse an assert statement. Return the assert statement. | 722 * Parse an assert statement. Return the assert statement. |
| 727 * | 723 * |
| 728 * This method assumes that the current token matches `Keyword.ASSERT`. | 724 * This method assumes that the current token matches `Keyword.ASSERT`. |
| 729 * | 725 * |
| 730 * assertStatement ::= | 726 * assertStatement ::= |
| 731 * 'assert' '(' expression [',' expression] ')' ';' | 727 * 'assert' '(' expression [',' expression] ')' ';' |
| 732 */ | 728 */ |
| 733 AssertStatement parseAssertStatement() { | 729 AssertStatement parseAssertStatement() { |
| 734 Token keyword = getAndAdvance(); | 730 Token keyword = getAndAdvance(); |
| 735 Token leftParen = _expect(TokenType.OPEN_PAREN); | 731 Token leftParen = _expect(TokenType.OPEN_PAREN); |
| 736 Expression expression = parseExpression2(); | 732 Expression expression = parseExpression2(); |
| 737 Token comma; | 733 Token comma; |
| 738 Expression message; | 734 Expression message; |
| 739 if (_matches(TokenType.COMMA)) { | 735 if (_matches(TokenType.COMMA)) { |
| 740 comma = getAndAdvance(); | 736 comma = getAndAdvance(); |
| 741 message = parseExpression2(); | 737 message = parseExpression2(); |
| 742 } | 738 } |
| 743 Token rightParen = _expect(TokenType.CLOSE_PAREN); | 739 Token rightParen = _expect(TokenType.CLOSE_PAREN); |
| 744 Token semicolon = _expect(TokenType.SEMICOLON); | 740 Token semicolon = _expect(TokenType.SEMICOLON); |
| 745 return astFactory.assertStatement( | 741 return new AssertStatement( |
| 746 keyword, leftParen, expression, comma, message, rightParen, semicolon); | 742 keyword, leftParen, expression, comma, message, rightParen, semicolon); |
| 747 } | 743 } |
| 748 | 744 |
| 749 /** | 745 /** |
| 750 * Parse an assignable expression. The [primaryAllowed] is `true` if the | 746 * Parse an assignable expression. The [primaryAllowed] is `true` if the |
| 751 * expression is allowed to be a primary without any assignable selector. | 747 * expression is allowed to be a primary without any assignable selector. |
| 752 * Return the assignable expression that was parsed. | 748 * Return the assignable expression that was parsed. |
| 753 * | 749 * |
| 754 * assignableExpression ::= | 750 * assignableExpression ::= |
| 755 * primary (arguments* assignableSelector)+ | 751 * primary (arguments* assignableSelector)+ |
| 756 * | 'super' unconditionalAssignableSelector | 752 * | 'super' unconditionalAssignableSelector |
| 757 * | identifier | 753 * | identifier |
| 758 */ | 754 */ |
| 759 Expression parseAssignableExpression(bool primaryAllowed) { | 755 Expression parseAssignableExpression(bool primaryAllowed) { |
| 760 if (_matchesKeyword(Keyword.SUPER)) { | 756 if (_matchesKeyword(Keyword.SUPER)) { |
| 761 return parseAssignableSelector( | 757 return parseAssignableSelector( |
| 762 astFactory.superExpression(getAndAdvance()), false, | 758 new SuperExpression(getAndAdvance()), false, |
| 763 allowConditional: false); | 759 allowConditional: false); |
| 764 } | 760 } |
| 765 return _parseAssignableExpressionNotStartingWithSuper(primaryAllowed); | 761 return _parseAssignableExpressionNotStartingWithSuper(primaryAllowed); |
| 766 } | 762 } |
| 767 | 763 |
| 768 /** | 764 /** |
| 769 * Parse an assignable selector. The [prefix] is the expression preceding the | 765 * Parse an assignable selector. The [prefix] is the expression preceding the |
| 770 * selector. The [optional] is `true` if the selector is optional. Return the | 766 * selector. The [optional] is `true` if the selector is optional. Return the |
| 771 * assignable selector that was parsed, or the original prefix if there was no | 767 * assignable selector that was parsed, or the original prefix if there was no |
| 772 * assignable selector. If [allowConditional] is false, then the '?.' | 768 * assignable selector. If [allowConditional] is false, then the '?.' |
| (...skipping 10 matching lines...) Expand all Loading... |
| 783 Expression parseAssignableSelector(Expression prefix, bool optional, | 779 Expression parseAssignableSelector(Expression prefix, bool optional, |
| 784 {bool allowConditional: true}) { | 780 {bool allowConditional: true}) { |
| 785 TokenType type = _currentToken.type; | 781 TokenType type = _currentToken.type; |
| 786 if (type == TokenType.OPEN_SQUARE_BRACKET) { | 782 if (type == TokenType.OPEN_SQUARE_BRACKET) { |
| 787 Token leftBracket = getAndAdvance(); | 783 Token leftBracket = getAndAdvance(); |
| 788 bool wasInInitializer = _inInitializer; | 784 bool wasInInitializer = _inInitializer; |
| 789 _inInitializer = false; | 785 _inInitializer = false; |
| 790 try { | 786 try { |
| 791 Expression index = parseExpression2(); | 787 Expression index = parseExpression2(); |
| 792 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); | 788 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); |
| 793 return astFactory.indexExpressionForTarget( | 789 return new IndexExpression.forTarget( |
| 794 prefix, leftBracket, index, rightBracket); | 790 prefix, leftBracket, index, rightBracket); |
| 795 } finally { | 791 } finally { |
| 796 _inInitializer = wasInInitializer; | 792 _inInitializer = wasInInitializer; |
| 797 } | 793 } |
| 798 } else { | 794 } else { |
| 799 bool isQuestionPeriod = type == TokenType.QUESTION_PERIOD; | 795 bool isQuestionPeriod = type == TokenType.QUESTION_PERIOD; |
| 800 if (type == TokenType.PERIOD || isQuestionPeriod) { | 796 if (type == TokenType.PERIOD || isQuestionPeriod) { |
| 801 if (isQuestionPeriod && !allowConditional) { | 797 if (isQuestionPeriod && !allowConditional) { |
| 802 _reportErrorForCurrentToken( | 798 _reportErrorForCurrentToken( |
| 803 ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, | 799 ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, |
| 804 [_currentToken.lexeme]); | 800 [_currentToken.lexeme]); |
| 805 } | 801 } |
| 806 Token operator = getAndAdvance(); | 802 Token operator = getAndAdvance(); |
| 807 return astFactory.propertyAccess( | 803 return new PropertyAccess(prefix, operator, parseSimpleIdentifier()); |
| 808 prefix, operator, parseSimpleIdentifier()); | |
| 809 } else if (type == TokenType.INDEX) { | 804 } else if (type == TokenType.INDEX) { |
| 810 _splitIndex(); | 805 _splitIndex(); |
| 811 Token leftBracket = getAndAdvance(); | 806 Token leftBracket = getAndAdvance(); |
| 812 Expression index = parseSimpleIdentifier(); | 807 Expression index = parseSimpleIdentifier(); |
| 813 Token rightBracket = getAndAdvance(); | 808 Token rightBracket = getAndAdvance(); |
| 814 return astFactory.indexExpressionForTarget( | 809 return new IndexExpression.forTarget( |
| 815 prefix, leftBracket, index, rightBracket); | 810 prefix, leftBracket, index, rightBracket); |
| 816 } else { | 811 } else { |
| 817 if (!optional) { | 812 if (!optional) { |
| 818 // Report the missing selector. | 813 // Report the missing selector. |
| 819 _reportErrorForCurrentToken( | 814 _reportErrorForCurrentToken( |
| 820 ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR); | 815 ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR); |
| 821 } | 816 } |
| 822 return prefix; | 817 return prefix; |
| 823 } | 818 } |
| 824 } | 819 } |
| 825 } | 820 } |
| 826 | 821 |
| 827 /** | 822 /** |
| 828 * Parse a await expression. Return the await expression that was parsed. | 823 * Parse a await expression. Return the await expression that was parsed. |
| 829 * | 824 * |
| 830 * This method assumes that the current token matches `_AWAIT`. | 825 * This method assumes that the current token matches `_AWAIT`. |
| 831 * | 826 * |
| 832 * awaitExpression ::= | 827 * awaitExpression ::= |
| 833 * 'await' unaryExpression | 828 * 'await' unaryExpression |
| 834 */ | 829 */ |
| 835 AwaitExpression parseAwaitExpression() { | 830 AwaitExpression parseAwaitExpression() { |
| 836 Token awaitToken = getAndAdvance(); | 831 Token awaitToken = getAndAdvance(); |
| 837 Expression expression = parseUnaryExpression(); | 832 Expression expression = parseUnaryExpression(); |
| 838 return astFactory.awaitExpression(awaitToken, expression); | 833 return new AwaitExpression(awaitToken, expression); |
| 839 } | 834 } |
| 840 | 835 |
| 841 /** | 836 /** |
| 842 * Parse a bitwise and expression. Return the bitwise and expression that was | 837 * Parse a bitwise and expression. Return the bitwise and expression that was |
| 843 * parsed. | 838 * parsed. |
| 844 * | 839 * |
| 845 * bitwiseAndExpression ::= | 840 * bitwiseAndExpression ::= |
| 846 * shiftExpression ('&' shiftExpression)* | 841 * shiftExpression ('&' shiftExpression)* |
| 847 * | 'super' ('&' shiftExpression)+ | 842 * | 'super' ('&' shiftExpression)+ |
| 848 */ | 843 */ |
| 849 Expression parseBitwiseAndExpression() { | 844 Expression parseBitwiseAndExpression() { |
| 850 Expression expression; | 845 Expression expression; |
| 851 if (_currentToken.keyword == Keyword.SUPER && | 846 if (_currentToken.keyword == Keyword.SUPER && |
| 852 _currentToken.next.type == TokenType.AMPERSAND) { | 847 _currentToken.next.type == TokenType.AMPERSAND) { |
| 853 expression = astFactory.superExpression(getAndAdvance()); | 848 expression = new SuperExpression(getAndAdvance()); |
| 854 } else { | 849 } else { |
| 855 expression = parseShiftExpression(); | 850 expression = parseShiftExpression(); |
| 856 } | 851 } |
| 857 while (_currentToken.type == TokenType.AMPERSAND) { | 852 while (_currentToken.type == TokenType.AMPERSAND) { |
| 858 expression = astFactory.binaryExpression( | 853 expression = new BinaryExpression( |
| 859 expression, getAndAdvance(), parseShiftExpression()); | 854 expression, getAndAdvance(), parseShiftExpression()); |
| 860 } | 855 } |
| 861 return expression; | 856 return expression; |
| 862 } | 857 } |
| 863 | 858 |
| 864 /** | 859 /** |
| 865 * Parse a bitwise or expression. Return the bitwise or expression that was | 860 * Parse a bitwise or expression. Return the bitwise or expression that was |
| 866 * parsed. | 861 * parsed. |
| 867 * | 862 * |
| 868 * bitwiseOrExpression ::= | 863 * bitwiseOrExpression ::= |
| 869 * bitwiseXorExpression ('|' bitwiseXorExpression)* | 864 * bitwiseXorExpression ('|' bitwiseXorExpression)* |
| 870 * | 'super' ('|' bitwiseXorExpression)+ | 865 * | 'super' ('|' bitwiseXorExpression)+ |
| 871 */ | 866 */ |
| 872 Expression parseBitwiseOrExpression() { | 867 Expression parseBitwiseOrExpression() { |
| 873 Expression expression; | 868 Expression expression; |
| 874 if (_currentToken.keyword == Keyword.SUPER && | 869 if (_currentToken.keyword == Keyword.SUPER && |
| 875 _currentToken.next.type == TokenType.BAR) { | 870 _currentToken.next.type == TokenType.BAR) { |
| 876 expression = astFactory.superExpression(getAndAdvance()); | 871 expression = new SuperExpression(getAndAdvance()); |
| 877 } else { | 872 } else { |
| 878 expression = parseBitwiseXorExpression(); | 873 expression = parseBitwiseXorExpression(); |
| 879 } | 874 } |
| 880 while (_currentToken.type == TokenType.BAR) { | 875 while (_currentToken.type == TokenType.BAR) { |
| 881 expression = astFactory.binaryExpression( | 876 expression = new BinaryExpression( |
| 882 expression, getAndAdvance(), parseBitwiseXorExpression()); | 877 expression, getAndAdvance(), parseBitwiseXorExpression()); |
| 883 } | 878 } |
| 884 return expression; | 879 return expression; |
| 885 } | 880 } |
| 886 | 881 |
| 887 /** | 882 /** |
| 888 * Parse a bitwise exclusive-or expression. Return the bitwise exclusive-or | 883 * Parse a bitwise exclusive-or expression. Return the bitwise exclusive-or |
| 889 * expression that was parsed. | 884 * expression that was parsed. |
| 890 * | 885 * |
| 891 * bitwiseXorExpression ::= | 886 * bitwiseXorExpression ::= |
| 892 * bitwiseAndExpression ('^' bitwiseAndExpression)* | 887 * bitwiseAndExpression ('^' bitwiseAndExpression)* |
| 893 * | 'super' ('^' bitwiseAndExpression)+ | 888 * | 'super' ('^' bitwiseAndExpression)+ |
| 894 */ | 889 */ |
| 895 Expression parseBitwiseXorExpression() { | 890 Expression parseBitwiseXorExpression() { |
| 896 Expression expression; | 891 Expression expression; |
| 897 if (_currentToken.keyword == Keyword.SUPER && | 892 if (_currentToken.keyword == Keyword.SUPER && |
| 898 _currentToken.next.type == TokenType.CARET) { | 893 _currentToken.next.type == TokenType.CARET) { |
| 899 expression = astFactory.superExpression(getAndAdvance()); | 894 expression = new SuperExpression(getAndAdvance()); |
| 900 } else { | 895 } else { |
| 901 expression = parseBitwiseAndExpression(); | 896 expression = parseBitwiseAndExpression(); |
| 902 } | 897 } |
| 903 while (_currentToken.type == TokenType.CARET) { | 898 while (_currentToken.type == TokenType.CARET) { |
| 904 expression = astFactory.binaryExpression( | 899 expression = new BinaryExpression( |
| 905 expression, getAndAdvance(), parseBitwiseAndExpression()); | 900 expression, getAndAdvance(), parseBitwiseAndExpression()); |
| 906 } | 901 } |
| 907 return expression; | 902 return expression; |
| 908 } | 903 } |
| 909 | 904 |
| 910 /** | 905 /** |
| 911 * Parse a block. Return the block that was parsed. | 906 * Parse a block. Return the block that was parsed. |
| 912 * | 907 * |
| 913 * This method assumes that the current token matches | 908 * This method assumes that the current token matches |
| 914 * [TokenType.OPEN_CURLY_BRACKET]. | 909 * [TokenType.OPEN_CURLY_BRACKET]. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 935 } else if (statement != null) { | 930 } else if (statement != null) { |
| 936 statements.add(statement); | 931 statements.add(statement); |
| 937 } | 932 } |
| 938 statementStart = _currentToken; | 933 statementStart = _currentToken; |
| 939 } | 934 } |
| 940 // Recovery: If the next token is not a right curly bracket, look at the | 935 // Recovery: If the next token is not a right curly bracket, look at the |
| 941 // left curly bracket to see whether there is a matching right bracket. If | 936 // left curly bracket to see whether there is a matching right bracket. If |
| 942 // there is, then we're more likely missing a semi-colon and should go back | 937 // there is, then we're more likely missing a semi-colon and should go back |
| 943 // to parsing statements. | 938 // to parsing statements. |
| 944 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); | 939 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); |
| 945 return astFactory.block(leftBracket, statements, rightBracket); | 940 return new Block(leftBracket, statements, rightBracket); |
| 946 } | 941 } |
| 947 | 942 |
| 948 /** | 943 /** |
| 949 * Parse a break statement. Return the break statement that was parsed. | 944 * Parse a break statement. Return the break statement that was parsed. |
| 950 * | 945 * |
| 951 * This method assumes that the current token matches `Keyword.BREAK`. | 946 * This method assumes that the current token matches `Keyword.BREAK`. |
| 952 * | 947 * |
| 953 * breakStatement ::= | 948 * breakStatement ::= |
| 954 * 'break' identifier? ';' | 949 * 'break' identifier? ';' |
| 955 */ | 950 */ |
| 956 Statement parseBreakStatement() { | 951 Statement parseBreakStatement() { |
| 957 Token breakKeyword = getAndAdvance(); | 952 Token breakKeyword = getAndAdvance(); |
| 958 SimpleIdentifier label = null; | 953 SimpleIdentifier label = null; |
| 959 if (_matchesIdentifier()) { | 954 if (_matchesIdentifier()) { |
| 960 label = _parseSimpleIdentifierUnchecked(); | 955 label = _parseSimpleIdentifierUnchecked(); |
| 961 } | 956 } |
| 962 if (!_inLoop && !_inSwitch && label == null) { | 957 if (!_inLoop && !_inSwitch && label == null) { |
| 963 _reportErrorForToken(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword); | 958 _reportErrorForToken(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword); |
| 964 } | 959 } |
| 965 Token semicolon = _expect(TokenType.SEMICOLON); | 960 Token semicolon = _expect(TokenType.SEMICOLON); |
| 966 return astFactory.breakStatement(breakKeyword, label, semicolon); | 961 return new BreakStatement(breakKeyword, label, semicolon); |
| 967 } | 962 } |
| 968 | 963 |
| 969 /** | 964 /** |
| 970 * Parse a cascade section. Return the expression representing the cascaded | 965 * Parse a cascade section. Return the expression representing the cascaded |
| 971 * method invocation. | 966 * method invocation. |
| 972 * | 967 * |
| 973 * This method assumes that the current token matches | 968 * This method assumes that the current token matches |
| 974 * `TokenType.PERIOD_PERIOD`. | 969 * `TokenType.PERIOD_PERIOD`. |
| 975 * | 970 * |
| 976 * cascadeSection ::= | 971 * cascadeSection ::= |
| (...skipping 13 matching lines...) Expand all Loading... |
| 990 SimpleIdentifier functionName = null; | 985 SimpleIdentifier functionName = null; |
| 991 if (_matchesIdentifier()) { | 986 if (_matchesIdentifier()) { |
| 992 functionName = _parseSimpleIdentifierUnchecked(); | 987 functionName = _parseSimpleIdentifierUnchecked(); |
| 993 } else if (_currentToken.type == TokenType.OPEN_SQUARE_BRACKET) { | 988 } else if (_currentToken.type == TokenType.OPEN_SQUARE_BRACKET) { |
| 994 Token leftBracket = getAndAdvance(); | 989 Token leftBracket = getAndAdvance(); |
| 995 bool wasInInitializer = _inInitializer; | 990 bool wasInInitializer = _inInitializer; |
| 996 _inInitializer = false; | 991 _inInitializer = false; |
| 997 try { | 992 try { |
| 998 Expression index = parseExpression2(); | 993 Expression index = parseExpression2(); |
| 999 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); | 994 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); |
| 1000 expression = astFactory.indexExpressionForCascade( | 995 expression = new IndexExpression.forCascade( |
| 1001 period, leftBracket, index, rightBracket); | 996 period, leftBracket, index, rightBracket); |
| 1002 period = null; | 997 period = null; |
| 1003 } finally { | 998 } finally { |
| 1004 _inInitializer = wasInInitializer; | 999 _inInitializer = wasInInitializer; |
| 1005 } | 1000 } |
| 1006 } else { | 1001 } else { |
| 1007 _reportErrorForToken(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, | 1002 _reportErrorForToken(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, |
| 1008 [_currentToken.lexeme]); | 1003 [_currentToken.lexeme]); |
| 1009 functionName = createSyntheticIdentifier(); | 1004 functionName = createSyntheticIdentifier(); |
| 1010 } | 1005 } |
| 1011 assert((expression == null && functionName != null) || | 1006 assert((expression == null && functionName != null) || |
| 1012 (expression != null && functionName == null)); | 1007 (expression != null && functionName == null)); |
| 1013 if (_isLikelyArgumentList()) { | 1008 if (_isLikelyArgumentList()) { |
| 1014 do { | 1009 do { |
| 1015 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); | 1010 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); |
| 1016 if (functionName != null) { | 1011 if (functionName != null) { |
| 1017 expression = astFactory.methodInvocation(expression, period, | 1012 expression = new MethodInvocation(expression, period, functionName, |
| 1018 functionName, typeArguments, parseArgumentList()); | 1013 typeArguments, parseArgumentList()); |
| 1019 period = null; | 1014 period = null; |
| 1020 functionName = null; | 1015 functionName = null; |
| 1021 } else if (expression == null) { | 1016 } else if (expression == null) { |
| 1022 // It should not be possible to get here. | 1017 // It should not be possible to get here. |
| 1023 expression = astFactory.methodInvocation(expression, period, | 1018 expression = new MethodInvocation(expression, period, |
| 1024 createSyntheticIdentifier(), typeArguments, parseArgumentList()); | 1019 createSyntheticIdentifier(), typeArguments, parseArgumentList()); |
| 1025 } else { | 1020 } else { |
| 1026 expression = astFactory.functionExpressionInvocation( | 1021 expression = new FunctionExpressionInvocation( |
| 1027 expression, typeArguments, parseArgumentList()); | 1022 expression, typeArguments, parseArgumentList()); |
| 1028 } | 1023 } |
| 1029 } while (_isLikelyArgumentList()); | 1024 } while (_isLikelyArgumentList()); |
| 1030 } else if (functionName != null) { | 1025 } else if (functionName != null) { |
| 1031 expression = astFactory.propertyAccess(expression, period, functionName); | 1026 expression = new PropertyAccess(expression, period, functionName); |
| 1032 period = null; | 1027 period = null; |
| 1033 } | 1028 } |
| 1034 assert(expression != null); | 1029 assert(expression != null); |
| 1035 bool progress = true; | 1030 bool progress = true; |
| 1036 while (progress) { | 1031 while (progress) { |
| 1037 progress = false; | 1032 progress = false; |
| 1038 Expression selector = parseAssignableSelector(expression, true); | 1033 Expression selector = parseAssignableSelector(expression, true); |
| 1039 if (!identical(selector, expression)) { | 1034 if (!identical(selector, expression)) { |
| 1040 expression = selector; | 1035 expression = selector; |
| 1041 progress = true; | 1036 progress = true; |
| 1042 while (_isLikelyArgumentList()) { | 1037 while (_isLikelyArgumentList()) { |
| 1043 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); | 1038 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); |
| 1044 Expression currentExpression = expression; | 1039 Expression currentExpression = expression; |
| 1045 if (currentExpression is PropertyAccess) { | 1040 if (currentExpression is PropertyAccess) { |
| 1046 expression = astFactory.methodInvocation( | 1041 expression = new MethodInvocation( |
| 1047 currentExpression.target, | 1042 currentExpression.target, |
| 1048 currentExpression.operator, | 1043 currentExpression.operator, |
| 1049 currentExpression.propertyName, | 1044 currentExpression.propertyName, |
| 1050 typeArguments, | 1045 typeArguments, |
| 1051 parseArgumentList()); | 1046 parseArgumentList()); |
| 1052 } else { | 1047 } else { |
| 1053 expression = astFactory.functionExpressionInvocation( | 1048 expression = new FunctionExpressionInvocation( |
| 1054 expression, typeArguments, parseArgumentList()); | 1049 expression, typeArguments, parseArgumentList()); |
| 1055 } | 1050 } |
| 1056 } | 1051 } |
| 1057 } | 1052 } |
| 1058 } | 1053 } |
| 1059 if (_currentToken.type.isAssignmentOperator) { | 1054 if (_currentToken.type.isAssignmentOperator) { |
| 1060 Token operator = getAndAdvance(); | 1055 Token operator = getAndAdvance(); |
| 1061 _ensureAssignable(expression); | 1056 _ensureAssignable(expression); |
| 1062 expression = astFactory.assignmentExpression( | 1057 expression = new AssignmentExpression( |
| 1063 expression, operator, parseExpressionWithoutCascade()); | 1058 expression, operator, parseExpressionWithoutCascade()); |
| 1064 } | 1059 } |
| 1065 return expression; | 1060 return expression; |
| 1066 } | 1061 } |
| 1067 | 1062 |
| 1068 /** | 1063 /** |
| 1069 * Parse a class declaration. The [commentAndMetadata] is the metadata to be | 1064 * Parse a class declaration. The [commentAndMetadata] is the metadata to be |
| 1070 * associated with the member. The [abstractKeyword] is the token for the | 1065 * associated with the member. The [abstractKeyword] is the token for the |
| 1071 * keyword 'abstract', or `null` if the keyword was not given. Return the | 1066 * keyword 'abstract', or `null` if the keyword was not given. Return the |
| 1072 * class declaration that was parsed. | 1067 * class declaration that was parsed. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 leftBracket = getAndAdvance(); | 1169 leftBracket = getAndAdvance(); |
| 1175 members = _parseClassMembers(className, _getEndToken(leftBracket)); | 1170 members = _parseClassMembers(className, _getEndToken(leftBracket)); |
| 1176 rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); | 1171 rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); |
| 1177 } else { | 1172 } else { |
| 1178 // Recovery: Check for an unmatched closing curly bracket and parse | 1173 // Recovery: Check for an unmatched closing curly bracket and parse |
| 1179 // members until it is reached. | 1174 // members until it is reached. |
| 1180 leftBracket = _createSyntheticToken(TokenType.OPEN_CURLY_BRACKET); | 1175 leftBracket = _createSyntheticToken(TokenType.OPEN_CURLY_BRACKET); |
| 1181 rightBracket = _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET); | 1176 rightBracket = _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET); |
| 1182 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CLASS_BODY); | 1177 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CLASS_BODY); |
| 1183 } | 1178 } |
| 1184 ClassDeclaration classDeclaration = astFactory.classDeclaration( | 1179 ClassDeclaration classDeclaration = new ClassDeclaration( |
| 1185 commentAndMetadata.comment, | 1180 commentAndMetadata.comment, |
| 1186 commentAndMetadata.metadata, | 1181 commentAndMetadata.metadata, |
| 1187 abstractKeyword, | 1182 abstractKeyword, |
| 1188 keyword, | 1183 keyword, |
| 1189 name, | 1184 name, |
| 1190 typeParameters, | 1185 typeParameters, |
| 1191 extendsClause, | 1186 extendsClause, |
| 1192 withClause, | 1187 withClause, |
| 1193 implementsClause, | 1188 implementsClause, |
| 1194 leftBracket, | 1189 leftBracket, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1205 * | 1200 * |
| 1206 * classMemberDefinition ::= | 1201 * classMemberDefinition ::= |
| 1207 * declaration ';' | 1202 * declaration ';' |
| 1208 * | methodSignature functionBody | 1203 * | methodSignature functionBody |
| 1209 */ | 1204 */ |
| 1210 ClassMember parseClassMember(String className) { | 1205 ClassMember parseClassMember(String className) { |
| 1211 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); | 1206 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); |
| 1212 Modifiers modifiers = parseModifiers(); | 1207 Modifiers modifiers = parseModifiers(); |
| 1213 Keyword keyword = _currentToken.keyword; | 1208 Keyword keyword = _currentToken.keyword; |
| 1214 if (keyword == Keyword.VOID) { | 1209 if (keyword == Keyword.VOID) { |
| 1215 TypeName returnType = astFactory.typeName( | 1210 TypeName returnType = |
| 1216 astFactory.simpleIdentifier(getAndAdvance()), null); | 1211 new TypeName(new SimpleIdentifier(getAndAdvance()), null); |
| 1217 keyword = _currentToken.keyword; | 1212 keyword = _currentToken.keyword; |
| 1218 Token next = _peek(); | 1213 Token next = _peek(); |
| 1219 bool isFollowedByIdentifier = _tokenMatchesIdentifier(next); | 1214 bool isFollowedByIdentifier = _tokenMatchesIdentifier(next); |
| 1220 if (keyword == Keyword.GET && isFollowedByIdentifier) { | 1215 if (keyword == Keyword.GET && isFollowedByIdentifier) { |
| 1221 _validateModifiersForGetterOrSetterOrMethod(modifiers); | 1216 _validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1222 return parseGetter(commentAndMetadata, modifiers.externalKeyword, | 1217 return parseGetter(commentAndMetadata, modifiers.externalKeyword, |
| 1223 modifiers.staticKeyword, returnType); | 1218 modifiers.staticKeyword, returnType); |
| 1224 } else if (keyword == Keyword.SET && isFollowedByIdentifier) { | 1219 } else if (keyword == Keyword.SET && isFollowedByIdentifier) { |
| 1225 _validateModifiersForGetterOrSetterOrMethod(modifiers); | 1220 _validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1226 return parseSetter(commentAndMetadata, modifiers.externalKeyword, | 1221 return parseSetter(commentAndMetadata, modifiers.externalKeyword, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 keyword = modifiers.finalKeyword; | 1320 keyword = modifiers.finalKeyword; |
| 1326 } | 1321 } |
| 1327 if (keyword == null) { | 1322 if (keyword == null) { |
| 1328 keyword = modifiers.constKeyword; | 1323 keyword = modifiers.constKeyword; |
| 1329 } | 1324 } |
| 1330 if (keyword != null) { | 1325 if (keyword != null) { |
| 1331 // | 1326 // |
| 1332 // We appear to have found an incomplete field declaration. | 1327 // We appear to have found an incomplete field declaration. |
| 1333 // | 1328 // |
| 1334 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); | 1329 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); |
| 1335 VariableDeclaration variable = astFactory.variableDeclaration( | 1330 VariableDeclaration variable = |
| 1336 createSyntheticIdentifier(), null, null); | 1331 new VariableDeclaration(createSyntheticIdentifier(), null, null); |
| 1337 List<VariableDeclaration> variables = <VariableDeclaration>[variable]; | 1332 List<VariableDeclaration> variables = <VariableDeclaration>[variable]; |
| 1338 return astFactory.fieldDeclaration( | 1333 return new FieldDeclaration( |
| 1339 commentAndMetadata.comment, | 1334 commentAndMetadata.comment, |
| 1340 commentAndMetadata.metadata, | 1335 commentAndMetadata.metadata, |
| 1341 null, | 1336 null, |
| 1342 astFactory.variableDeclarationList( | 1337 new VariableDeclarationList(null, null, keyword, null, variables), |
| 1343 null, null, keyword, null, variables), | |
| 1344 _expect(TokenType.SEMICOLON)); | 1338 _expect(TokenType.SEMICOLON)); |
| 1345 } | 1339 } |
| 1346 _reportErrorForToken( | 1340 _reportErrorForToken( |
| 1347 ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken); | 1341 ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken); |
| 1348 if (commentAndMetadata.comment != null || | 1342 if (commentAndMetadata.comment != null || |
| 1349 commentAndMetadata.hasMetadata) { | 1343 commentAndMetadata.hasMetadata) { |
| 1350 // | 1344 // |
| 1351 // We appear to have found an incomplete declaration at the end of the | 1345 // We appear to have found an incomplete declaration at the end of the |
| 1352 // class. At this point it consists of a metadata, which we don't want | 1346 // class. At this point it consists of a metadata, which we don't want |
| 1353 // to loose, so we'll treat it as a method declaration with a missing | 1347 // to loose, so we'll treat it as a method declaration with a missing |
| 1354 // name, parameters and empty body. | 1348 // name, parameters and empty body. |
| 1355 // | 1349 // |
| 1356 return astFactory.methodDeclaration( | 1350 return new MethodDeclaration( |
| 1357 commentAndMetadata.comment, | 1351 commentAndMetadata.comment, |
| 1358 commentAndMetadata.metadata, | 1352 commentAndMetadata.metadata, |
| 1359 null, | 1353 null, |
| 1360 null, | 1354 null, |
| 1361 null, | 1355 null, |
| 1362 null, | 1356 null, |
| 1363 null, | 1357 null, |
| 1364 createSyntheticIdentifier(isDeclaration: true), | 1358 createSyntheticIdentifier(isDeclaration: true), |
| 1365 null, | 1359 null, |
| 1366 astFactory.formalParameterList( | 1360 new FormalParameterList( |
| 1367 null, <FormalParameter>[], null, null, null), | 1361 null, <FormalParameter>[], null, null, null), |
| 1368 astFactory | 1362 new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON))); |
| 1369 .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON))); | |
| 1370 } | 1363 } |
| 1371 return null; | 1364 return null; |
| 1372 } else if (_tokenMatches(next, TokenType.PERIOD) && | 1365 } else if (_tokenMatches(next, TokenType.PERIOD) && |
| 1373 _tokenMatchesIdentifier(_peekAt(2)) && | 1366 _tokenMatchesIdentifier(_peekAt(2)) && |
| 1374 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) { | 1367 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) { |
| 1375 return _parseConstructor( | 1368 return _parseConstructor( |
| 1376 commentAndMetadata, | 1369 commentAndMetadata, |
| 1377 modifiers.externalKeyword, | 1370 modifiers.externalKeyword, |
| 1378 _validateModifiersForConstructor(modifiers), | 1371 _validateModifiersForConstructor(modifiers), |
| 1379 modifiers.factoryKeyword, | 1372 modifiers.factoryKeyword, |
| 1380 parseSimpleIdentifier(), | 1373 parseSimpleIdentifier(), |
| 1381 getAndAdvance(), | 1374 getAndAdvance(), |
| 1382 parseSimpleIdentifier(isDeclaration: true), | 1375 parseSimpleIdentifier(isDeclaration: true), |
| 1383 parseFormalParameterList()); | 1376 parseFormalParameterList()); |
| 1384 } else if (_tokenMatches(next, TokenType.OPEN_PAREN)) { | 1377 } else if (_tokenMatches(next, TokenType.OPEN_PAREN)) { |
| 1385 TypeName returnType = _parseOptionalTypeNameComment(); | 1378 TypeName returnType = _parseOptionalTypeNameComment(); |
| 1386 SimpleIdentifier methodName = parseSimpleIdentifier(isDeclaration: true); | 1379 SimpleIdentifier methodName = parseSimpleIdentifier(isDeclaration: true); |
| 1387 TypeParameterList typeParameters = _parseGenericCommentTypeParameters(); | 1380 TypeParameterList typeParameters = _parseGenericCommentTypeParameters(); |
| 1388 FormalParameterList parameters = parseFormalParameterList(); | 1381 FormalParameterList parameters = parseFormalParameterList(); |
| 1389 if (_matches(TokenType.COLON) || | 1382 if (_matches(TokenType.COLON) || |
| 1390 modifiers.factoryKeyword != null || | 1383 modifiers.factoryKeyword != null || |
| 1391 methodName.name == className) { | 1384 methodName.name == className) { |
| 1392 return _parseConstructor( | 1385 return _parseConstructor( |
| 1393 commentAndMetadata, | 1386 commentAndMetadata, |
| 1394 modifiers.externalKeyword, | 1387 modifiers.externalKeyword, |
| 1395 _validateModifiersForConstructor(modifiers), | 1388 _validateModifiersForConstructor(modifiers), |
| 1396 modifiers.factoryKeyword, | 1389 modifiers.factoryKeyword, |
| 1397 astFactory.simpleIdentifier(methodName.token, isDeclaration: false), | 1390 new SimpleIdentifier(methodName.token, isDeclaration: false), |
| 1398 null, | 1391 null, |
| 1399 null, | 1392 null, |
| 1400 parameters); | 1393 parameters); |
| 1401 } | 1394 } |
| 1402 _validateModifiersForGetterOrSetterOrMethod(modifiers); | 1395 _validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1403 _validateFormalParameterList(parameters); | 1396 _validateFormalParameterList(parameters); |
| 1404 return _parseMethodDeclarationAfterParameters( | 1397 return _parseMethodDeclarationAfterParameters( |
| 1405 commentAndMetadata, | 1398 commentAndMetadata, |
| 1406 modifiers.externalKeyword, | 1399 modifiers.externalKeyword, |
| 1407 modifiers.staticKeyword, | 1400 modifiers.staticKeyword, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 _parseSimpleIdentifierUnchecked(isDeclaration: true); | 1488 _parseSimpleIdentifierUnchecked(isDeclaration: true); |
| 1496 TypeParameterList typeParameters = _parseGenericCommentTypeParameters(); | 1489 TypeParameterList typeParameters = _parseGenericCommentTypeParameters(); |
| 1497 FormalParameterList parameters = parseFormalParameterList(); | 1490 FormalParameterList parameters = parseFormalParameterList(); |
| 1498 if (methodName.name == className) { | 1491 if (methodName.name == className) { |
| 1499 _reportErrorForNode(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type); | 1492 _reportErrorForNode(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type); |
| 1500 return _parseConstructor( | 1493 return _parseConstructor( |
| 1501 commentAndMetadata, | 1494 commentAndMetadata, |
| 1502 modifiers.externalKeyword, | 1495 modifiers.externalKeyword, |
| 1503 _validateModifiersForConstructor(modifiers), | 1496 _validateModifiersForConstructor(modifiers), |
| 1504 modifiers.factoryKeyword, | 1497 modifiers.factoryKeyword, |
| 1505 astFactory.simpleIdentifier(methodName.token, isDeclaration: true), | 1498 new SimpleIdentifier(methodName.token, isDeclaration: true), |
| 1506 null, | 1499 null, |
| 1507 null, | 1500 null, |
| 1508 parameters); | 1501 parameters); |
| 1509 } | 1502 } |
| 1510 _validateModifiersForGetterOrSetterOrMethod(modifiers); | 1503 _validateModifiersForGetterOrSetterOrMethod(modifiers); |
| 1511 _validateFormalParameterList(parameters); | 1504 _validateFormalParameterList(parameters); |
| 1512 return _parseMethodDeclarationAfterParameters( | 1505 return _parseMethodDeclarationAfterParameters( |
| 1513 commentAndMetadata, | 1506 commentAndMetadata, |
| 1514 modifiers.externalKeyword, | 1507 modifiers.externalKeyword, |
| 1515 modifiers.staticKeyword, | 1508 modifiers.staticKeyword, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1563 /** | 1556 /** |
| 1564 * Parse a single combinator. Return the combinator that was parsed, or `null` | 1557 * Parse a single combinator. Return the combinator that was parsed, or `null` |
| 1565 * if no combinator is found. | 1558 * if no combinator is found. |
| 1566 * | 1559 * |
| 1567 * combinator ::= | 1560 * combinator ::= |
| 1568 * 'show' identifier (',' identifier)* | 1561 * 'show' identifier (',' identifier)* |
| 1569 * | 'hide' identifier (',' identifier)* | 1562 * | 'hide' identifier (',' identifier)* |
| 1570 */ | 1563 */ |
| 1571 Combinator parseCombinator() { | 1564 Combinator parseCombinator() { |
| 1572 if (_matchesString(_SHOW)) { | 1565 if (_matchesString(_SHOW)) { |
| 1573 return astFactory.showCombinator(getAndAdvance(), parseIdentifierList()); | 1566 return new ShowCombinator(getAndAdvance(), parseIdentifierList()); |
| 1574 } else if (_matchesString(_HIDE)) { | 1567 } else if (_matchesString(_HIDE)) { |
| 1575 return astFactory.hideCombinator(getAndAdvance(), parseIdentifierList()); | 1568 return new HideCombinator(getAndAdvance(), parseIdentifierList()); |
| 1576 } | 1569 } |
| 1577 return null; | 1570 return null; |
| 1578 } | 1571 } |
| 1579 | 1572 |
| 1580 /** | 1573 /** |
| 1581 * Parse a list of combinators in a directive. Return the combinators that | 1574 * Parse a list of combinators in a directive. Return the combinators that |
| 1582 * were parsed, or `null` if there are no combinators. | 1575 * were parsed, or `null` if there are no combinators. |
| 1583 * | 1576 * |
| 1584 * combinator ::= | 1577 * combinator ::= |
| 1585 * 'show' identifier (',' identifier)* | 1578 * 'show' identifier (',' identifier)* |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1645 null, new SubSequenceReader(referenceSource, sourceOffset), listener); | 1638 null, new SubSequenceReader(referenceSource, sourceOffset), listener); |
| 1646 scanner.setSourceStart(1, 1); | 1639 scanner.setSourceStart(1, 1); |
| 1647 Token firstToken = scanner.tokenize(); | 1640 Token firstToken = scanner.tokenize(); |
| 1648 if (listener.errorReported) { | 1641 if (listener.errorReported) { |
| 1649 return null; | 1642 return null; |
| 1650 } | 1643 } |
| 1651 if (firstToken.type == TokenType.EOF) { | 1644 if (firstToken.type == TokenType.EOF) { |
| 1652 Token syntheticToken = | 1645 Token syntheticToken = |
| 1653 new SyntheticStringToken(TokenType.IDENTIFIER, "", sourceOffset); | 1646 new SyntheticStringToken(TokenType.IDENTIFIER, "", sourceOffset); |
| 1654 syntheticToken.setNext(firstToken); | 1647 syntheticToken.setNext(firstToken); |
| 1655 return astFactory.commentReference( | 1648 return new CommentReference(null, new SimpleIdentifier(syntheticToken)); |
| 1656 null, astFactory.simpleIdentifier(syntheticToken)); | |
| 1657 } | 1649 } |
| 1658 Token newKeyword = null; | 1650 Token newKeyword = null; |
| 1659 if (_tokenMatchesKeyword(firstToken, Keyword.NEW)) { | 1651 if (_tokenMatchesKeyword(firstToken, Keyword.NEW)) { |
| 1660 newKeyword = firstToken; | 1652 newKeyword = firstToken; |
| 1661 firstToken = firstToken.next; | 1653 firstToken = firstToken.next; |
| 1662 } | 1654 } |
| 1663 if (firstToken.isUserDefinableOperator) { | 1655 if (firstToken.isUserDefinableOperator) { |
| 1664 if (firstToken.next.type != TokenType.EOF) { | 1656 if (firstToken.next.type != TokenType.EOF) { |
| 1665 return null; | 1657 return null; |
| 1666 } | 1658 } |
| 1667 Identifier identifier = astFactory.simpleIdentifier(firstToken); | 1659 Identifier identifier = new SimpleIdentifier(firstToken); |
| 1668 return astFactory.commentReference(null, identifier); | 1660 return new CommentReference(null, identifier); |
| 1669 } else if (_tokenMatchesKeyword(firstToken, Keyword.OPERATOR)) { | 1661 } else if (_tokenMatchesKeyword(firstToken, Keyword.OPERATOR)) { |
| 1670 Token secondToken = firstToken.next; | 1662 Token secondToken = firstToken.next; |
| 1671 if (secondToken.isUserDefinableOperator) { | 1663 if (secondToken.isUserDefinableOperator) { |
| 1672 if (secondToken.next.type != TokenType.EOF) { | 1664 if (secondToken.next.type != TokenType.EOF) { |
| 1673 return null; | 1665 return null; |
| 1674 } | 1666 } |
| 1675 Identifier identifier = astFactory.simpleIdentifier(secondToken); | 1667 Identifier identifier = new SimpleIdentifier(secondToken); |
| 1676 return astFactory.commentReference(null, identifier); | 1668 return new CommentReference(null, identifier); |
| 1677 } | 1669 } |
| 1678 return null; | 1670 return null; |
| 1679 } else if (_tokenMatchesIdentifier(firstToken)) { | 1671 } else if (_tokenMatchesIdentifier(firstToken)) { |
| 1680 Token secondToken = firstToken.next; | 1672 Token secondToken = firstToken.next; |
| 1681 Token thirdToken = secondToken.next; | 1673 Token thirdToken = secondToken.next; |
| 1682 Token nextToken; | 1674 Token nextToken; |
| 1683 Identifier identifier; | 1675 Identifier identifier; |
| 1684 if (_tokenMatches(secondToken, TokenType.PERIOD)) { | 1676 if (_tokenMatches(secondToken, TokenType.PERIOD)) { |
| 1685 if (thirdToken.isUserDefinableOperator) { | 1677 if (thirdToken.isUserDefinableOperator) { |
| 1686 identifier = astFactory.prefixedIdentifier( | 1678 identifier = new PrefixedIdentifier( |
| 1687 astFactory.simpleIdentifier(firstToken), | 1679 new SimpleIdentifier(firstToken), |
| 1688 secondToken, | 1680 secondToken, |
| 1689 astFactory.simpleIdentifier(thirdToken)); | 1681 new SimpleIdentifier(thirdToken)); |
| 1690 nextToken = thirdToken.next; | 1682 nextToken = thirdToken.next; |
| 1691 } else if (_tokenMatchesKeyword(thirdToken, Keyword.OPERATOR)) { | 1683 } else if (_tokenMatchesKeyword(thirdToken, Keyword.OPERATOR)) { |
| 1692 Token fourthToken = thirdToken.next; | 1684 Token fourthToken = thirdToken.next; |
| 1693 if (fourthToken.isUserDefinableOperator) { | 1685 if (fourthToken.isUserDefinableOperator) { |
| 1694 identifier = astFactory.prefixedIdentifier( | 1686 identifier = new PrefixedIdentifier( |
| 1695 astFactory.simpleIdentifier(firstToken), | 1687 new SimpleIdentifier(firstToken), |
| 1696 secondToken, | 1688 secondToken, |
| 1697 astFactory.simpleIdentifier(fourthToken)); | 1689 new SimpleIdentifier(fourthToken)); |
| 1698 nextToken = fourthToken.next; | 1690 nextToken = fourthToken.next; |
| 1699 } else { | 1691 } else { |
| 1700 return null; | 1692 return null; |
| 1701 } | 1693 } |
| 1702 } else if (_tokenMatchesIdentifier(thirdToken)) { | 1694 } else if (_tokenMatchesIdentifier(thirdToken)) { |
| 1703 identifier = astFactory.prefixedIdentifier( | 1695 identifier = new PrefixedIdentifier( |
| 1704 astFactory.simpleIdentifier(firstToken), | 1696 new SimpleIdentifier(firstToken), |
| 1705 secondToken, | 1697 secondToken, |
| 1706 astFactory.simpleIdentifier(thirdToken)); | 1698 new SimpleIdentifier(thirdToken)); |
| 1707 nextToken = thirdToken.next; | 1699 nextToken = thirdToken.next; |
| 1708 } | 1700 } |
| 1709 } else { | 1701 } else { |
| 1710 identifier = astFactory.simpleIdentifier(firstToken); | 1702 identifier = new SimpleIdentifier(firstToken); |
| 1711 nextToken = firstToken.next; | 1703 nextToken = firstToken.next; |
| 1712 } | 1704 } |
| 1713 if (nextToken.type != TokenType.EOF) { | 1705 if (nextToken.type != TokenType.EOF) { |
| 1714 return null; | 1706 return null; |
| 1715 } | 1707 } |
| 1716 return astFactory.commentReference(newKeyword, identifier); | 1708 return new CommentReference(newKeyword, identifier); |
| 1717 } else { | 1709 } else { |
| 1718 Keyword keyword = firstToken.keyword; | 1710 Keyword keyword = firstToken.keyword; |
| 1719 if (keyword == Keyword.THIS || | 1711 if (keyword == Keyword.THIS || |
| 1720 keyword == Keyword.NULL || | 1712 keyword == Keyword.NULL || |
| 1721 keyword == Keyword.TRUE || | 1713 keyword == Keyword.TRUE || |
| 1722 keyword == Keyword.FALSE) { | 1714 keyword == Keyword.FALSE) { |
| 1723 // TODO(brianwilkerson) If we want to support this we will need to | 1715 // TODO(brianwilkerson) If we want to support this we will need to |
| 1724 // extend the definition of CommentReference to take an expression | 1716 // extend the definition of CommentReference to take an expression |
| 1725 // rather than an identifier. For now we just ignore it to reduce the | 1717 // rather than an identifier. For now we just ignore it to reduce the |
| 1726 // number of errors produced, but that's probably not a valid long ter
m | 1718 // number of errors produced, but that's probably not a valid long ter
m |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1796 int nameEnd = StringUtilities.indexOfFirstNotLetterDigit( | 1788 int nameEnd = StringUtilities.indexOfFirstNotLetterDigit( |
| 1797 comment, leftIndex + 1); | 1789 comment, leftIndex + 1); |
| 1798 String name = comment.substring(leftIndex + 1, nameEnd); | 1790 String name = comment.substring(leftIndex + 1, nameEnd); |
| 1799 nameToken = | 1791 nameToken = |
| 1800 new StringToken(TokenType.IDENTIFIER, name, nameOffset); | 1792 new StringToken(TokenType.IDENTIFIER, name, nameOffset); |
| 1801 } else { | 1793 } else { |
| 1802 nameToken = new SyntheticStringToken( | 1794 nameToken = new SyntheticStringToken( |
| 1803 TokenType.IDENTIFIER, '', nameOffset); | 1795 TokenType.IDENTIFIER, '', nameOffset); |
| 1804 } | 1796 } |
| 1805 nameToken.setNext(new SimpleToken(TokenType.EOF, nameToken.end)); | 1797 nameToken.setNext(new SimpleToken(TokenType.EOF, nameToken.end)); |
| 1806 references.add(astFactory.commentReference( | 1798 references.add( |
| 1807 null, astFactory.simpleIdentifier(nameToken))); | 1799 new CommentReference(null, new SimpleIdentifier(nameToken))); |
| 1808 token.references.add(nameToken); | 1800 token.references.add(nameToken); |
| 1809 // next character | 1801 // next character |
| 1810 rightIndex = leftIndex + 1; | 1802 rightIndex = leftIndex + 1; |
| 1811 } | 1803 } |
| 1812 leftIndex = comment.indexOf('[', rightIndex); | 1804 leftIndex = comment.indexOf('[', rightIndex); |
| 1813 } else { | 1805 } else { |
| 1814 leftIndex = comment.indexOf('[', range[1]); | 1806 leftIndex = comment.indexOf('[', range[1]); |
| 1815 } | 1807 } |
| 1816 } | 1808 } |
| 1817 } | 1809 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1841 * scriptTag? topLevelElement* | 1833 * scriptTag? topLevelElement* |
| 1842 * | 1834 * |
| 1843 * topLevelElement ::= | 1835 * topLevelElement ::= |
| 1844 * directive | 1836 * directive |
| 1845 * | topLevelDeclaration | 1837 * | topLevelDeclaration |
| 1846 */ | 1838 */ |
| 1847 CompilationUnit parseCompilationUnit2() { | 1839 CompilationUnit parseCompilationUnit2() { |
| 1848 Token firstToken = _currentToken; | 1840 Token firstToken = _currentToken; |
| 1849 ScriptTag scriptTag = null; | 1841 ScriptTag scriptTag = null; |
| 1850 if (_matches(TokenType.SCRIPT_TAG)) { | 1842 if (_matches(TokenType.SCRIPT_TAG)) { |
| 1851 scriptTag = astFactory.scriptTag(getAndAdvance()); | 1843 scriptTag = new ScriptTag(getAndAdvance()); |
| 1852 } | 1844 } |
| 1853 // | 1845 // |
| 1854 // Even though all directives must appear before declarations and must occur | 1846 // Even though all directives must appear before declarations and must occur |
| 1855 // in a given order, we allow directives and declarations to occur in any | 1847 // in a given order, we allow directives and declarations to occur in any |
| 1856 // order so that we can recover better. | 1848 // order so that we can recover better. |
| 1857 // | 1849 // |
| 1858 bool libraryDirectiveFound = false; | 1850 bool libraryDirectiveFound = false; |
| 1859 bool partOfDirectiveFound = false; | 1851 bool partOfDirectiveFound = false; |
| 1860 bool partDirectiveFound = false; | 1852 bool partDirectiveFound = false; |
| 1861 bool directiveFoundAfterDeclaration = false; | 1853 bool directiveFoundAfterDeclaration = false; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1972 _reportErrorForToken(ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES, | 1964 _reportErrorForToken(ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES, |
| 1973 directive.partKeyword); | 1965 directive.partKeyword); |
| 1974 } | 1966 } |
| 1975 } else { | 1967 } else { |
| 1976 _reportErrorForToken(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, | 1968 _reportErrorForToken(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, |
| 1977 directives[i].keyword); | 1969 directives[i].keyword); |
| 1978 } | 1970 } |
| 1979 // } | 1971 // } |
| 1980 } | 1972 } |
| 1981 } | 1973 } |
| 1982 return astFactory.compilationUnit( | 1974 return new CompilationUnit( |
| 1983 firstToken, scriptTag, directives, declarations, _currentToken); | 1975 firstToken, scriptTag, directives, declarations, _currentToken); |
| 1984 } | 1976 } |
| 1985 | 1977 |
| 1986 /** | 1978 /** |
| 1987 * Parse a compilation unit member. The [commentAndMetadata] is the metadata | 1979 * Parse a compilation unit member. The [commentAndMetadata] is the metadata |
| 1988 * to be associated with the member. Return the compilation unit member that | 1980 * to be associated with the member. Return the compilation unit member that |
| 1989 * was parsed, or `null` if what was parsed could not be represented as a | 1981 * was parsed, or `null` if what was parsed could not be represented as a |
| 1990 * compilation unit member. | 1982 * compilation unit member. |
| 1991 * | 1983 * |
| 1992 * compilationUnitMember ::= | 1984 * compilationUnitMember ::= |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2013 if (keyword == Keyword.TYPEDEF && | 2005 if (keyword == Keyword.TYPEDEF && |
| 2014 nextType != TokenType.PERIOD && | 2006 nextType != TokenType.PERIOD && |
| 2015 nextType != TokenType.LT && | 2007 nextType != TokenType.LT && |
| 2016 nextType != TokenType.OPEN_PAREN) { | 2008 nextType != TokenType.OPEN_PAREN) { |
| 2017 _validateModifiersForTypedef(modifiers); | 2009 _validateModifiersForTypedef(modifiers); |
| 2018 return parseTypeAlias(commentAndMetadata); | 2010 return parseTypeAlias(commentAndMetadata); |
| 2019 } else if (keyword == Keyword.ENUM) { | 2011 } else if (keyword == Keyword.ENUM) { |
| 2020 _validateModifiersForEnum(modifiers); | 2012 _validateModifiersForEnum(modifiers); |
| 2021 return parseEnumDeclaration(commentAndMetadata); | 2013 return parseEnumDeclaration(commentAndMetadata); |
| 2022 } else if (keyword == Keyword.VOID) { | 2014 } else if (keyword == Keyword.VOID) { |
| 2023 TypeName returnType = astFactory.typeName( | 2015 TypeName returnType = |
| 2024 astFactory.simpleIdentifier(getAndAdvance()), null); | 2016 new TypeName(new SimpleIdentifier(getAndAdvance()), null); |
| 2025 keyword = _currentToken.keyword; | 2017 keyword = _currentToken.keyword; |
| 2026 next = _peek(); | 2018 next = _peek(); |
| 2027 if ((keyword == Keyword.GET || keyword == Keyword.SET) && | 2019 if ((keyword == Keyword.GET || keyword == Keyword.SET) && |
| 2028 _tokenMatchesIdentifier(next)) { | 2020 _tokenMatchesIdentifier(next)) { |
| 2029 _validateModifiersForTopLevelFunction(modifiers); | 2021 _validateModifiersForTopLevelFunction(modifiers); |
| 2030 return parseFunctionDeclaration( | 2022 return parseFunctionDeclaration( |
| 2031 commentAndMetadata, modifiers.externalKeyword, returnType); | 2023 commentAndMetadata, modifiers.externalKeyword, returnType); |
| 2032 } else if (keyword == Keyword.OPERATOR && _isOperator(next)) { | 2024 } else if (keyword == Keyword.OPERATOR && _isOperator(next)) { |
| 2033 _reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken); | 2025 _reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken); |
| 2034 return _convertToFunctionDeclaration(_parseOperatorAfterKeyword( | 2026 return _convertToFunctionDeclaration(_parseOperatorAfterKeyword( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2053 if (_matchesIdentifier()) { | 2045 if (_matchesIdentifier()) { |
| 2054 if (next.matchesAny(const <TokenType>[ | 2046 if (next.matchesAny(const <TokenType>[ |
| 2055 TokenType.EQ, | 2047 TokenType.EQ, |
| 2056 TokenType.COMMA, | 2048 TokenType.COMMA, |
| 2057 TokenType.SEMICOLON | 2049 TokenType.SEMICOLON |
| 2058 ])) { | 2050 ])) { |
| 2059 // | 2051 // |
| 2060 // We appear to have a variable declaration with a type of "void". | 2052 // We appear to have a variable declaration with a type of "void". |
| 2061 // | 2053 // |
| 2062 _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType); | 2054 _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType); |
| 2063 return astFactory.topLevelVariableDeclaration( | 2055 return new TopLevelVariableDeclaration( |
| 2064 commentAndMetadata.comment, | 2056 commentAndMetadata.comment, |
| 2065 commentAndMetadata.metadata, | 2057 commentAndMetadata.metadata, |
| 2066 parseVariableDeclarationListAfterType(null, | 2058 parseVariableDeclarationListAfterType(null, |
| 2067 _validateModifiersForTopLevelVariable(modifiers), null), | 2059 _validateModifiersForTopLevelVariable(modifiers), null), |
| 2068 _expect(TokenType.SEMICOLON)); | 2060 _expect(TokenType.SEMICOLON)); |
| 2069 } | 2061 } |
| 2070 } | 2062 } |
| 2071 _reportErrorForToken( | 2063 _reportErrorForToken( |
| 2072 ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken); | 2064 ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken); |
| 2073 return null; | 2065 return null; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2090 keyword = modifiers.finalKeyword; | 2082 keyword = modifiers.finalKeyword; |
| 2091 } | 2083 } |
| 2092 if (keyword == null) { | 2084 if (keyword == null) { |
| 2093 keyword = modifiers.constKeyword; | 2085 keyword = modifiers.constKeyword; |
| 2094 } | 2086 } |
| 2095 if (keyword != null) { | 2087 if (keyword != null) { |
| 2096 // | 2088 // |
| 2097 // We appear to have found an incomplete top-level variable declaration. | 2089 // We appear to have found an incomplete top-level variable declaration. |
| 2098 // | 2090 // |
| 2099 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); | 2091 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); |
| 2100 VariableDeclaration variable = astFactory.variableDeclaration( | 2092 VariableDeclaration variable = |
| 2101 createSyntheticIdentifier(), null, null); | 2093 new VariableDeclaration(createSyntheticIdentifier(), null, null); |
| 2102 List<VariableDeclaration> variables = <VariableDeclaration>[variable]; | 2094 List<VariableDeclaration> variables = <VariableDeclaration>[variable]; |
| 2103 return astFactory.topLevelVariableDeclaration( | 2095 return new TopLevelVariableDeclaration( |
| 2104 commentAndMetadata.comment, | 2096 commentAndMetadata.comment, |
| 2105 commentAndMetadata.metadata, | 2097 commentAndMetadata.metadata, |
| 2106 astFactory.variableDeclarationList( | 2098 new VariableDeclarationList(null, null, keyword, null, variables), |
| 2107 null, null, keyword, null, variables), | |
| 2108 _expect(TokenType.SEMICOLON)); | 2099 _expect(TokenType.SEMICOLON)); |
| 2109 } | 2100 } |
| 2110 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken); | 2101 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken); |
| 2111 return null; | 2102 return null; |
| 2112 } else if (_isPeekGenericTypeParametersAndOpenParen()) { | 2103 } else if (_isPeekGenericTypeParametersAndOpenParen()) { |
| 2113 return parseFunctionDeclaration( | 2104 return parseFunctionDeclaration( |
| 2114 commentAndMetadata, modifiers.externalKeyword, null); | 2105 commentAndMetadata, modifiers.externalKeyword, null); |
| 2115 } else if (_tokenMatches(next, TokenType.OPEN_PAREN)) { | 2106 } else if (_tokenMatches(next, TokenType.OPEN_PAREN)) { |
| 2116 TypeName returnType = _parseOptionalTypeNameComment(); | 2107 TypeName returnType = _parseOptionalTypeNameComment(); |
| 2117 _validateModifiersForTopLevelFunction(modifiers); | 2108 _validateModifiersForTopLevelFunction(modifiers); |
| 2118 return parseFunctionDeclaration( | 2109 return parseFunctionDeclaration( |
| 2119 commentAndMetadata, modifiers.externalKeyword, returnType); | 2110 commentAndMetadata, modifiers.externalKeyword, returnType); |
| 2120 } else if (next.matchesAny(const <TokenType>[ | 2111 } else if (next.matchesAny(const <TokenType>[ |
| 2121 TokenType.EQ, | 2112 TokenType.EQ, |
| 2122 TokenType.COMMA, | 2113 TokenType.COMMA, |
| 2123 TokenType.SEMICOLON | 2114 TokenType.SEMICOLON |
| 2124 ])) { | 2115 ])) { |
| 2125 if (modifiers.constKeyword == null && | 2116 if (modifiers.constKeyword == null && |
| 2126 modifiers.finalKeyword == null && | 2117 modifiers.finalKeyword == null && |
| 2127 modifiers.varKeyword == null) { | 2118 modifiers.varKeyword == null) { |
| 2128 _reportErrorForCurrentToken( | 2119 _reportErrorForCurrentToken( |
| 2129 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE); | 2120 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE); |
| 2130 } | 2121 } |
| 2131 return astFactory.topLevelVariableDeclaration( | 2122 return new TopLevelVariableDeclaration( |
| 2132 commentAndMetadata.comment, | 2123 commentAndMetadata.comment, |
| 2133 commentAndMetadata.metadata, | 2124 commentAndMetadata.metadata, |
| 2134 parseVariableDeclarationListAfterType( | 2125 parseVariableDeclarationListAfterType( |
| 2135 null, _validateModifiersForTopLevelVariable(modifiers), null), | 2126 null, _validateModifiersForTopLevelVariable(modifiers), null), |
| 2136 _expect(TokenType.SEMICOLON)); | 2127 _expect(TokenType.SEMICOLON)); |
| 2137 } | 2128 } |
| 2138 TypeName returnType = parseReturnType(); | 2129 TypeName returnType = parseReturnType(); |
| 2139 keyword = _currentToken.keyword; | 2130 keyword = _currentToken.keyword; |
| 2140 next = _peek(); | 2131 next = _peek(); |
| 2141 if ((keyword == Keyword.GET || keyword == Keyword.SET) && | 2132 if ((keyword == Keyword.GET || keyword == Keyword.SET) && |
| 2142 _tokenMatchesIdentifier(next)) { | 2133 _tokenMatchesIdentifier(next)) { |
| 2143 _validateModifiersForTopLevelFunction(modifiers); | 2134 _validateModifiersForTopLevelFunction(modifiers); |
| 2144 return parseFunctionDeclaration( | 2135 return parseFunctionDeclaration( |
| 2145 commentAndMetadata, modifiers.externalKeyword, returnType); | 2136 commentAndMetadata, modifiers.externalKeyword, returnType); |
| 2146 } else if (keyword == Keyword.OPERATOR && _isOperator(next)) { | 2137 } else if (keyword == Keyword.OPERATOR && _isOperator(next)) { |
| 2147 _reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken); | 2138 _reportErrorForToken(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken); |
| 2148 return _convertToFunctionDeclaration(_parseOperatorAfterKeyword( | 2139 return _convertToFunctionDeclaration(_parseOperatorAfterKeyword( |
| 2149 commentAndMetadata, | 2140 commentAndMetadata, |
| 2150 modifiers.externalKeyword, | 2141 modifiers.externalKeyword, |
| 2151 returnType, | 2142 returnType, |
| 2152 getAndAdvance())); | 2143 getAndAdvance())); |
| 2153 } else if (_matches(TokenType.AT)) { | 2144 } else if (_matches(TokenType.AT)) { |
| 2154 return astFactory.topLevelVariableDeclaration( | 2145 return new TopLevelVariableDeclaration( |
| 2155 commentAndMetadata.comment, | 2146 commentAndMetadata.comment, |
| 2156 commentAndMetadata.metadata, | 2147 commentAndMetadata.metadata, |
| 2157 parseVariableDeclarationListAfterType(null, | 2148 parseVariableDeclarationListAfterType(null, |
| 2158 _validateModifiersForTopLevelVariable(modifiers), returnType), | 2149 _validateModifiersForTopLevelVariable(modifiers), returnType), |
| 2159 _expect(TokenType.SEMICOLON)); | 2150 _expect(TokenType.SEMICOLON)); |
| 2160 } else if (!_matchesIdentifier()) { | 2151 } else if (!_matchesIdentifier()) { |
| 2161 // TODO(brianwilkerson) Generalize this error. We could also be parsing a | 2152 // TODO(brianwilkerson) Generalize this error. We could also be parsing a |
| 2162 // top-level variable at this point. | 2153 // top-level variable at this point. |
| 2163 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken); | 2154 _reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken); |
| 2164 Token semicolon; | 2155 Token semicolon; |
| 2165 if (_matches(TokenType.SEMICOLON)) { | 2156 if (_matches(TokenType.SEMICOLON)) { |
| 2166 semicolon = getAndAdvance(); | 2157 semicolon = getAndAdvance(); |
| 2167 } else { | 2158 } else { |
| 2168 semicolon = _createSyntheticToken(TokenType.SEMICOLON); | 2159 semicolon = _createSyntheticToken(TokenType.SEMICOLON); |
| 2169 } | 2160 } |
| 2170 VariableDeclaration variable = astFactory.variableDeclaration( | 2161 VariableDeclaration variable = |
| 2171 createSyntheticIdentifier(), null, null); | 2162 new VariableDeclaration(createSyntheticIdentifier(), null, null); |
| 2172 List<VariableDeclaration> variables = <VariableDeclaration>[variable]; | 2163 List<VariableDeclaration> variables = <VariableDeclaration>[variable]; |
| 2173 return astFactory.topLevelVariableDeclaration( | 2164 return new TopLevelVariableDeclaration( |
| 2174 commentAndMetadata.comment, | 2165 commentAndMetadata.comment, |
| 2175 commentAndMetadata.metadata, | 2166 commentAndMetadata.metadata, |
| 2176 astFactory.variableDeclarationList( | 2167 new VariableDeclarationList(null, null, null, returnType, variables), |
| 2177 null, null, null, returnType, variables), | |
| 2178 semicolon); | 2168 semicolon); |
| 2179 } else if (next.matchesAny(const <TokenType>[ | 2169 } else if (next.matchesAny(const <TokenType>[ |
| 2180 TokenType.OPEN_PAREN, | 2170 TokenType.OPEN_PAREN, |
| 2181 TokenType.FUNCTION, | 2171 TokenType.FUNCTION, |
| 2182 TokenType.OPEN_CURLY_BRACKET, | 2172 TokenType.OPEN_CURLY_BRACKET, |
| 2183 TokenType.LT | 2173 TokenType.LT |
| 2184 ])) { | 2174 ])) { |
| 2185 _validateModifiersForTopLevelFunction(modifiers); | 2175 _validateModifiersForTopLevelFunction(modifiers); |
| 2186 return parseFunctionDeclaration( | 2176 return parseFunctionDeclaration( |
| 2187 commentAndMetadata, modifiers.externalKeyword, returnType); | 2177 commentAndMetadata, modifiers.externalKeyword, returnType); |
| 2188 } | 2178 } |
| 2189 return astFactory.topLevelVariableDeclaration( | 2179 return new TopLevelVariableDeclaration( |
| 2190 commentAndMetadata.comment, | 2180 commentAndMetadata.comment, |
| 2191 commentAndMetadata.metadata, | 2181 commentAndMetadata.metadata, |
| 2192 parseVariableDeclarationListAfterType( | 2182 parseVariableDeclarationListAfterType( |
| 2193 null, _validateModifiersForTopLevelVariable(modifiers), returnType), | 2183 null, _validateModifiersForTopLevelVariable(modifiers), returnType), |
| 2194 _expect(TokenType.SEMICOLON)); | 2184 _expect(TokenType.SEMICOLON)); |
| 2195 } | 2185 } |
| 2196 | 2186 |
| 2197 /** | 2187 /** |
| 2198 * Parse a conditional expression. Return the conditional expression that was | 2188 * Parse a conditional expression. Return the conditional expression that was |
| 2199 * parsed. | 2189 * parsed. |
| 2200 * | 2190 * |
| 2201 * conditionalExpression ::= | 2191 * conditionalExpression ::= |
| 2202 * ifNullExpression ('?' expressionWithoutCascade ':' expressionWithou
tCascade)? | 2192 * ifNullExpression ('?' expressionWithoutCascade ':' expressionWithou
tCascade)? |
| 2203 */ | 2193 */ |
| 2204 Expression parseConditionalExpression() { | 2194 Expression parseConditionalExpression() { |
| 2205 Expression condition = parseIfNullExpression(); | 2195 Expression condition = parseIfNullExpression(); |
| 2206 if (_currentToken.type != TokenType.QUESTION) { | 2196 if (_currentToken.type != TokenType.QUESTION) { |
| 2207 return condition; | 2197 return condition; |
| 2208 } | 2198 } |
| 2209 Token question = getAndAdvance(); | 2199 Token question = getAndAdvance(); |
| 2210 Expression thenExpression = parseExpressionWithoutCascade(); | 2200 Expression thenExpression = parseExpressionWithoutCascade(); |
| 2211 Token colon = _expect(TokenType.COLON); | 2201 Token colon = _expect(TokenType.COLON); |
| 2212 Expression elseExpression = parseExpressionWithoutCascade(); | 2202 Expression elseExpression = parseExpressionWithoutCascade(); |
| 2213 return astFactory.conditionalExpression( | 2203 return new ConditionalExpression( |
| 2214 condition, question, thenExpression, colon, elseExpression); | 2204 condition, question, thenExpression, colon, elseExpression); |
| 2215 } | 2205 } |
| 2216 | 2206 |
| 2217 /** | 2207 /** |
| 2218 * Parse a configuration in either an import or export directive. | 2208 * Parse a configuration in either an import or export directive. |
| 2219 * | 2209 * |
| 2220 * This method assumes that the current token matches `Keyword.IF`. | 2210 * This method assumes that the current token matches `Keyword.IF`. |
| 2221 * | 2211 * |
| 2222 * configuration ::= | 2212 * configuration ::= |
| 2223 * 'if' '(' test ')' uri | 2213 * 'if' '(' test ')' uri |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2237 if (_matches(TokenType.EQ_EQ)) { | 2227 if (_matches(TokenType.EQ_EQ)) { |
| 2238 equalToken = getAndAdvance(); | 2228 equalToken = getAndAdvance(); |
| 2239 value = parseStringLiteral(); | 2229 value = parseStringLiteral(); |
| 2240 if (value is StringInterpolation) { | 2230 if (value is StringInterpolation) { |
| 2241 _reportErrorForNode( | 2231 _reportErrorForNode( |
| 2242 ParserErrorCode.INVALID_LITERAL_IN_CONFIGURATION, value); | 2232 ParserErrorCode.INVALID_LITERAL_IN_CONFIGURATION, value); |
| 2243 } | 2233 } |
| 2244 } | 2234 } |
| 2245 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); | 2235 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 2246 StringLiteral libraryUri = _parseUri(); | 2236 StringLiteral libraryUri = _parseUri(); |
| 2247 return astFactory.configuration(ifKeyword, leftParenthesis, name, | 2237 return new Configuration(ifKeyword, leftParenthesis, name, equalToken, |
| 2248 equalToken, value, rightParenthesis, libraryUri); | 2238 value, rightParenthesis, libraryUri); |
| 2249 } | 2239 } |
| 2250 | 2240 |
| 2251 /** | 2241 /** |
| 2252 * Parse a const expression. Return the const expression that was parsed. | 2242 * Parse a const expression. Return the const expression that was parsed. |
| 2253 * | 2243 * |
| 2254 * This method assumes that the current token matches `Keyword.CONST`. | 2244 * This method assumes that the current token matches `Keyword.CONST`. |
| 2255 * | 2245 * |
| 2256 * constExpression ::= | 2246 * constExpression ::= |
| 2257 * instanceCreationExpression | 2247 * instanceCreationExpression |
| 2258 * | listLiteral | 2248 * | listLiteral |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2295 } else { | 2285 } else { |
| 2296 _reportErrorForCurrentToken( | 2286 _reportErrorForCurrentToken( |
| 2297 ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER); | 2287 ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER); |
| 2298 Keyword keyword = _currentToken.keyword; | 2288 Keyword keyword = _currentToken.keyword; |
| 2299 if (keyword != Keyword.THIS && | 2289 if (keyword != Keyword.THIS && |
| 2300 keyword != Keyword.SUPER && | 2290 keyword != Keyword.SUPER && |
| 2301 type != TokenType.OPEN_CURLY_BRACKET && | 2291 type != TokenType.OPEN_CURLY_BRACKET && |
| 2302 type != TokenType.FUNCTION) { | 2292 type != TokenType.FUNCTION) { |
| 2303 equals = _createSyntheticToken(TokenType.EQ); | 2293 equals = _createSyntheticToken(TokenType.EQ); |
| 2304 } else { | 2294 } else { |
| 2305 return astFactory.constructorFieldInitializer( | 2295 return new ConstructorFieldInitializer(keywordToken, period, fieldName, |
| 2306 keywordToken, | 2296 _createSyntheticToken(TokenType.EQ), createSyntheticIdentifier()); |
| 2307 period, | |
| 2308 fieldName, | |
| 2309 _createSyntheticToken(TokenType.EQ), | |
| 2310 createSyntheticIdentifier()); | |
| 2311 } | 2297 } |
| 2312 } | 2298 } |
| 2313 bool wasInInitializer = _inInitializer; | 2299 bool wasInInitializer = _inInitializer; |
| 2314 _inInitializer = true; | 2300 _inInitializer = true; |
| 2315 try { | 2301 try { |
| 2316 Expression expression = parseConditionalExpression(); | 2302 Expression expression = parseConditionalExpression(); |
| 2317 if (_matches(TokenType.PERIOD_PERIOD)) { | 2303 if (_matches(TokenType.PERIOD_PERIOD)) { |
| 2318 List<Expression> cascadeSections = <Expression>[]; | 2304 List<Expression> cascadeSections = <Expression>[]; |
| 2319 do { | 2305 do { |
| 2320 Expression section = parseCascadeSection(); | 2306 Expression section = parseCascadeSection(); |
| 2321 if (section != null) { | 2307 if (section != null) { |
| 2322 cascadeSections.add(section); | 2308 cascadeSections.add(section); |
| 2323 } | 2309 } |
| 2324 } while (_matches(TokenType.PERIOD_PERIOD)); | 2310 } while (_matches(TokenType.PERIOD_PERIOD)); |
| 2325 expression = astFactory.cascadeExpression(expression, cascadeSections); | 2311 expression = new CascadeExpression(expression, cascadeSections); |
| 2326 } | 2312 } |
| 2327 return astFactory.constructorFieldInitializer( | 2313 return new ConstructorFieldInitializer( |
| 2328 keywordToken, period, fieldName, equals, expression); | 2314 keywordToken, period, fieldName, equals, expression); |
| 2329 } finally { | 2315 } finally { |
| 2330 _inInitializer = wasInInitializer; | 2316 _inInitializer = wasInInitializer; |
| 2331 } | 2317 } |
| 2332 } | 2318 } |
| 2333 | 2319 |
| 2334 /** | 2320 /** |
| 2335 * Parse the name of a constructor. Return the constructor name that was | 2321 * Parse the name of a constructor. Return the constructor name that was |
| 2336 * parsed. | 2322 * parsed. |
| 2337 * | 2323 * |
| 2338 * constructorName: | 2324 * constructorName: |
| 2339 * type ('.' identifier)? | 2325 * type ('.' identifier)? |
| 2340 */ | 2326 */ |
| 2341 ConstructorName parseConstructorName() { | 2327 ConstructorName parseConstructorName() { |
| 2342 TypeName type = parseTypeName(false); | 2328 TypeName type = parseTypeName(false); |
| 2343 Token period = null; | 2329 Token period = null; |
| 2344 SimpleIdentifier name = null; | 2330 SimpleIdentifier name = null; |
| 2345 if (_matches(TokenType.PERIOD)) { | 2331 if (_matches(TokenType.PERIOD)) { |
| 2346 period = getAndAdvance(); | 2332 period = getAndAdvance(); |
| 2347 name = parseSimpleIdentifier(); | 2333 name = parseSimpleIdentifier(); |
| 2348 } | 2334 } |
| 2349 return astFactory.constructorName(type, period, name); | 2335 return new ConstructorName(type, period, name); |
| 2350 } | 2336 } |
| 2351 | 2337 |
| 2352 /** | 2338 /** |
| 2353 * Parse a continue statement. Return the continue statement that was parsed. | 2339 * Parse a continue statement. Return the continue statement that was parsed. |
| 2354 * | 2340 * |
| 2355 * This method assumes that the current token matches `Keyword.CONTINUE`. | 2341 * This method assumes that the current token matches `Keyword.CONTINUE`. |
| 2356 * | 2342 * |
| 2357 * continueStatement ::= | 2343 * continueStatement ::= |
| 2358 * 'continue' identifier? ';' | 2344 * 'continue' identifier? ';' |
| 2359 */ | 2345 */ |
| 2360 Statement parseContinueStatement() { | 2346 Statement parseContinueStatement() { |
| 2361 Token continueKeyword = getAndAdvance(); | 2347 Token continueKeyword = getAndAdvance(); |
| 2362 if (!_inLoop && !_inSwitch) { | 2348 if (!_inLoop && !_inSwitch) { |
| 2363 _reportErrorForToken( | 2349 _reportErrorForToken( |
| 2364 ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword); | 2350 ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword); |
| 2365 } | 2351 } |
| 2366 SimpleIdentifier label = null; | 2352 SimpleIdentifier label = null; |
| 2367 if (_matchesIdentifier()) { | 2353 if (_matchesIdentifier()) { |
| 2368 label = _parseSimpleIdentifierUnchecked(); | 2354 label = _parseSimpleIdentifierUnchecked(); |
| 2369 } | 2355 } |
| 2370 if (_inSwitch && !_inLoop && label == null) { | 2356 if (_inSwitch && !_inLoop && label == null) { |
| 2371 _reportErrorForToken( | 2357 _reportErrorForToken( |
| 2372 ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeyword); | 2358 ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeyword); |
| 2373 } | 2359 } |
| 2374 Token semicolon = _expect(TokenType.SEMICOLON); | 2360 Token semicolon = _expect(TokenType.SEMICOLON); |
| 2375 return astFactory.continueStatement(continueKeyword, label, semicolon); | 2361 return new ContinueStatement(continueKeyword, label, semicolon); |
| 2376 } | 2362 } |
| 2377 | 2363 |
| 2378 /** | 2364 /** |
| 2379 * Parse a directive. The [commentAndMetadata] is the metadata to be | 2365 * Parse a directive. The [commentAndMetadata] is the metadata to be |
| 2380 * associated with the directive. Return the directive that was parsed. | 2366 * associated with the directive. Return the directive that was parsed. |
| 2381 * | 2367 * |
| 2382 * directive ::= | 2368 * directive ::= |
| 2383 * exportDirective | 2369 * exportDirective |
| 2384 * | libraryDirective | 2370 * | libraryDirective |
| 2385 * | importDirective | 2371 * | importDirective |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2418 * Parse the script tag and directives in a compilation unit until the first | 2404 * Parse the script tag and directives in a compilation unit until the first |
| 2419 * non-directive is encountered. Return the compilation unit that was parsed. | 2405 * non-directive is encountered. Return the compilation unit that was parsed. |
| 2420 * | 2406 * |
| 2421 * compilationUnit ::= | 2407 * compilationUnit ::= |
| 2422 * scriptTag? directive* | 2408 * scriptTag? directive* |
| 2423 */ | 2409 */ |
| 2424 CompilationUnit parseDirectives2() { | 2410 CompilationUnit parseDirectives2() { |
| 2425 Token firstToken = _currentToken; | 2411 Token firstToken = _currentToken; |
| 2426 ScriptTag scriptTag = null; | 2412 ScriptTag scriptTag = null; |
| 2427 if (_matches(TokenType.SCRIPT_TAG)) { | 2413 if (_matches(TokenType.SCRIPT_TAG)) { |
| 2428 scriptTag = astFactory.scriptTag(getAndAdvance()); | 2414 scriptTag = new ScriptTag(getAndAdvance()); |
| 2429 } | 2415 } |
| 2430 List<Directive> directives = <Directive>[]; | 2416 List<Directive> directives = <Directive>[]; |
| 2431 while (!_matches(TokenType.EOF)) { | 2417 while (!_matches(TokenType.EOF)) { |
| 2432 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); | 2418 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); |
| 2433 Keyword keyword = _currentToken.keyword; | 2419 Keyword keyword = _currentToken.keyword; |
| 2434 TokenType type = _peek().type; | 2420 TokenType type = _peek().type; |
| 2435 if ((keyword == Keyword.IMPORT || | 2421 if ((keyword == Keyword.IMPORT || |
| 2436 keyword == Keyword.EXPORT || | 2422 keyword == Keyword.EXPORT || |
| 2437 keyword == Keyword.LIBRARY || | 2423 keyword == Keyword.LIBRARY || |
| 2438 keyword == Keyword.PART) && | 2424 keyword == Keyword.PART) && |
| 2439 type != TokenType.PERIOD && | 2425 type != TokenType.PERIOD && |
| 2440 type != TokenType.LT && | 2426 type != TokenType.LT && |
| 2441 type != TokenType.OPEN_PAREN) { | 2427 type != TokenType.OPEN_PAREN) { |
| 2442 directives.add(parseDirective(commentAndMetadata)); | 2428 directives.add(parseDirective(commentAndMetadata)); |
| 2443 } else if (_matches(TokenType.SEMICOLON)) { | 2429 } else if (_matches(TokenType.SEMICOLON)) { |
| 2444 _advance(); | 2430 _advance(); |
| 2445 } else { | 2431 } else { |
| 2446 while (!_matches(TokenType.EOF)) { | 2432 while (!_matches(TokenType.EOF)) { |
| 2447 _advance(); | 2433 _advance(); |
| 2448 } | 2434 } |
| 2449 return astFactory.compilationUnit( | 2435 return new CompilationUnit( |
| 2450 firstToken, scriptTag, directives, null, _currentToken); | 2436 firstToken, scriptTag, directives, null, _currentToken); |
| 2451 } | 2437 } |
| 2452 } | 2438 } |
| 2453 return astFactory.compilationUnit( | 2439 return new CompilationUnit( |
| 2454 firstToken, scriptTag, directives, null, _currentToken); | 2440 firstToken, scriptTag, directives, null, _currentToken); |
| 2455 } | 2441 } |
| 2456 | 2442 |
| 2457 /** | 2443 /** |
| 2458 * Parse a documentation comment based on the given list of documentation | 2444 * Parse a documentation comment based on the given list of documentation |
| 2459 * comment tokens. Return the documentation comment that was parsed, or `null` | 2445 * comment tokens. Return the documentation comment that was parsed, or `null` |
| 2460 * if there was no comment. | 2446 * if there was no comment. |
| 2461 * | 2447 * |
| 2462 * documentationComment ::= | 2448 * documentationComment ::= |
| 2463 * multiLineComment? | 2449 * multiLineComment? |
| 2464 * | singleLineComment* | 2450 * | singleLineComment* |
| 2465 */ | 2451 */ |
| 2466 Comment parseDocumentationComment(List<DocumentationCommentToken> tokens) { | 2452 Comment parseDocumentationComment(List<DocumentationCommentToken> tokens) { |
| 2467 if (tokens == null) { | 2453 if (tokens == null) { |
| 2468 return null; | 2454 return null; |
| 2469 } | 2455 } |
| 2470 List<CommentReference> references = parseCommentReferences(tokens); | 2456 List<CommentReference> references = parseCommentReferences(tokens); |
| 2471 return astFactory.documentationComment(tokens, references); | 2457 return Comment.createDocumentationCommentWithReferences(tokens, references); |
| 2472 } | 2458 } |
| 2473 | 2459 |
| 2474 /** | 2460 /** |
| 2475 * Parse a documentation comment. Return the documentation comment that was | 2461 * Parse a documentation comment. Return the documentation comment that was |
| 2476 * parsed, or `null` if there was no comment. | 2462 * parsed, or `null` if there was no comment. |
| 2477 * | 2463 * |
| 2478 * documentationComment ::= | 2464 * documentationComment ::= |
| 2479 * multiLineComment? | 2465 * multiLineComment? |
| 2480 * | singleLineComment* | 2466 * | singleLineComment* |
| 2481 */ | 2467 */ |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2512 bool wasInLoop = _inLoop; | 2498 bool wasInLoop = _inLoop; |
| 2513 _inLoop = true; | 2499 _inLoop = true; |
| 2514 try { | 2500 try { |
| 2515 Token doKeyword = getAndAdvance(); | 2501 Token doKeyword = getAndAdvance(); |
| 2516 Statement body = parseStatement2(); | 2502 Statement body = parseStatement2(); |
| 2517 Token whileKeyword = _expectKeyword(Keyword.WHILE); | 2503 Token whileKeyword = _expectKeyword(Keyword.WHILE); |
| 2518 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); | 2504 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); |
| 2519 Expression condition = parseExpression2(); | 2505 Expression condition = parseExpression2(); |
| 2520 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); | 2506 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 2521 Token semicolon = _expect(TokenType.SEMICOLON); | 2507 Token semicolon = _expect(TokenType.SEMICOLON); |
| 2522 return astFactory.doStatement(doKeyword, body, whileKeyword, | 2508 return new DoStatement(doKeyword, body, whileKeyword, leftParenthesis, |
| 2523 leftParenthesis, condition, rightParenthesis, semicolon); | 2509 condition, rightParenthesis, semicolon); |
| 2524 } finally { | 2510 } finally { |
| 2525 _inLoop = wasInLoop; | 2511 _inLoop = wasInLoop; |
| 2526 } | 2512 } |
| 2527 } | 2513 } |
| 2528 | 2514 |
| 2529 /** | 2515 /** |
| 2530 * Parse a dotted name. Return the dotted name that was parsed. | 2516 * Parse a dotted name. Return the dotted name that was parsed. |
| 2531 * | 2517 * |
| 2532 * dottedName ::= | 2518 * dottedName ::= |
| 2533 * identifier ('.' identifier)* | 2519 * identifier ('.' identifier)* |
| 2534 */ | 2520 */ |
| 2535 DottedName parseDottedName() { | 2521 DottedName parseDottedName() { |
| 2536 List<SimpleIdentifier> components = <SimpleIdentifier>[ | 2522 List<SimpleIdentifier> components = <SimpleIdentifier>[ |
| 2537 parseSimpleIdentifier() | 2523 parseSimpleIdentifier() |
| 2538 ]; | 2524 ]; |
| 2539 while (_optional(TokenType.PERIOD)) { | 2525 while (_optional(TokenType.PERIOD)) { |
| 2540 components.add(parseSimpleIdentifier()); | 2526 components.add(parseSimpleIdentifier()); |
| 2541 } | 2527 } |
| 2542 return astFactory.dottedName(components); | 2528 return new DottedName(components); |
| 2543 } | 2529 } |
| 2544 | 2530 |
| 2545 /** | 2531 /** |
| 2546 * Parse an empty statement. Return the empty statement that was parsed. | 2532 * Parse an empty statement. Return the empty statement that was parsed. |
| 2547 * | 2533 * |
| 2548 * This method assumes that the current token matches `TokenType.SEMICOLON`. | 2534 * This method assumes that the current token matches `TokenType.SEMICOLON`. |
| 2549 * | 2535 * |
| 2550 * emptyStatement ::= | 2536 * emptyStatement ::= |
| 2551 * ';' | 2537 * ';' |
| 2552 */ | 2538 */ |
| 2553 Statement parseEmptyStatement() => astFactory.emptyStatement(getAndAdvance()); | 2539 Statement parseEmptyStatement() => new EmptyStatement(getAndAdvance()); |
| 2554 | 2540 |
| 2555 /** | 2541 /** |
| 2556 * Parse an enum declaration. The [commentAndMetadata] is the metadata to be | 2542 * Parse an enum declaration. The [commentAndMetadata] is the metadata to be |
| 2557 * associated with the member. Return the enum declaration that was parsed. | 2543 * associated with the member. Return the enum declaration that was parsed. |
| 2558 * | 2544 * |
| 2559 * This method assumes that the current token matches `Keyword.ENUM`. | 2545 * This method assumes that the current token matches `Keyword.ENUM`. |
| 2560 * | 2546 * |
| 2561 * enumType ::= | 2547 * enumType ::= |
| 2562 * metadata 'enum' id '{' id (',' id)* (',')? '}' | 2548 * metadata 'enum' id '{' id (',' id)* (',')? '}' |
| 2563 */ | 2549 */ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2584 break; | 2570 break; |
| 2585 } | 2571 } |
| 2586 constants.add(_parseEnumConstantDeclaration()); | 2572 constants.add(_parseEnumConstantDeclaration()); |
| 2587 } | 2573 } |
| 2588 rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); | 2574 rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); |
| 2589 } else { | 2575 } else { |
| 2590 leftBracket = _createSyntheticToken(TokenType.OPEN_CURLY_BRACKET); | 2576 leftBracket = _createSyntheticToken(TokenType.OPEN_CURLY_BRACKET); |
| 2591 rightBracket = _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET); | 2577 rightBracket = _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET); |
| 2592 _reportErrorForCurrentToken(ParserErrorCode.MISSING_ENUM_BODY); | 2578 _reportErrorForCurrentToken(ParserErrorCode.MISSING_ENUM_BODY); |
| 2593 } | 2579 } |
| 2594 return astFactory.enumDeclaration( | 2580 return new EnumDeclaration( |
| 2595 commentAndMetadata.comment, | 2581 commentAndMetadata.comment, |
| 2596 commentAndMetadata.metadata, | 2582 commentAndMetadata.metadata, |
| 2597 keyword, | 2583 keyword, |
| 2598 name, | 2584 name, |
| 2599 leftBracket, | 2585 leftBracket, |
| 2600 constants, | 2586 constants, |
| 2601 rightBracket); | 2587 rightBracket); |
| 2602 } | 2588 } |
| 2603 | 2589 |
| 2604 /** | 2590 /** |
| 2605 * Parse an equality expression. Return the equality expression that was | 2591 * Parse an equality expression. Return the equality expression that was |
| 2606 * parsed. | 2592 * parsed. |
| 2607 * | 2593 * |
| 2608 * equalityExpression ::= | 2594 * equalityExpression ::= |
| 2609 * relationalExpression (equalityOperator relationalExpression)? | 2595 * relationalExpression (equalityOperator relationalExpression)? |
| 2610 * | 'super' equalityOperator relationalExpression | 2596 * | 'super' equalityOperator relationalExpression |
| 2611 */ | 2597 */ |
| 2612 Expression parseEqualityExpression() { | 2598 Expression parseEqualityExpression() { |
| 2613 Expression expression; | 2599 Expression expression; |
| 2614 if (_currentToken.keyword == Keyword.SUPER && | 2600 if (_currentToken.keyword == Keyword.SUPER && |
| 2615 _currentToken.next.type.isEqualityOperator) { | 2601 _currentToken.next.type.isEqualityOperator) { |
| 2616 expression = astFactory.superExpression(getAndAdvance()); | 2602 expression = new SuperExpression(getAndAdvance()); |
| 2617 } else { | 2603 } else { |
| 2618 expression = parseRelationalExpression(); | 2604 expression = parseRelationalExpression(); |
| 2619 } | 2605 } |
| 2620 bool leftEqualityExpression = false; | 2606 bool leftEqualityExpression = false; |
| 2621 while (_currentToken.type.isEqualityOperator) { | 2607 while (_currentToken.type.isEqualityOperator) { |
| 2622 if (leftEqualityExpression) { | 2608 if (leftEqualityExpression) { |
| 2623 _reportErrorForNode( | 2609 _reportErrorForNode( |
| 2624 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expression); | 2610 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expression); |
| 2625 } | 2611 } |
| 2626 expression = astFactory.binaryExpression( | 2612 expression = new BinaryExpression( |
| 2627 expression, getAndAdvance(), parseRelationalExpression()); | 2613 expression, getAndAdvance(), parseRelationalExpression()); |
| 2628 leftEqualityExpression = true; | 2614 leftEqualityExpression = true; |
| 2629 } | 2615 } |
| 2630 return expression; | 2616 return expression; |
| 2631 } | 2617 } |
| 2632 | 2618 |
| 2633 /** | 2619 /** |
| 2634 * Parse an export directive. The [commentAndMetadata] is the metadata to be | 2620 * Parse an export directive. The [commentAndMetadata] is the metadata to be |
| 2635 * associated with the directive. Return the export directive that was parsed. | 2621 * associated with the directive. Return the export directive that was parsed. |
| 2636 * | 2622 * |
| 2637 * This method assumes that the current token matches `Keyword.EXPORT`. | 2623 * This method assumes that the current token matches `Keyword.EXPORT`. |
| 2638 * | 2624 * |
| 2639 * exportDirective ::= | 2625 * exportDirective ::= |
| 2640 * metadata 'export' stringLiteral configuration* combinator*';' | 2626 * metadata 'export' stringLiteral configuration* combinator*';' |
| 2641 */ | 2627 */ |
| 2642 ExportDirective parseExportDirective(CommentAndMetadata commentAndMetadata) { | 2628 ExportDirective parseExportDirective(CommentAndMetadata commentAndMetadata) { |
| 2643 Token exportKeyword = getAndAdvance(); | 2629 Token exportKeyword = getAndAdvance(); |
| 2644 StringLiteral libraryUri = _parseUri(); | 2630 StringLiteral libraryUri = _parseUri(); |
| 2645 List<Configuration> configurations = _parseConfigurations(); | 2631 List<Configuration> configurations = _parseConfigurations(); |
| 2646 List<Combinator> combinators = parseCombinators(); | 2632 List<Combinator> combinators = parseCombinators(); |
| 2647 Token semicolon = _expect(TokenType.SEMICOLON); | 2633 Token semicolon = _expect(TokenType.SEMICOLON); |
| 2648 return astFactory.exportDirective( | 2634 return new ExportDirective( |
| 2649 commentAndMetadata.comment, | 2635 commentAndMetadata.comment, |
| 2650 commentAndMetadata.metadata, | 2636 commentAndMetadata.metadata, |
| 2651 exportKeyword, | 2637 exportKeyword, |
| 2652 libraryUri, | 2638 libraryUri, |
| 2653 configurations, | 2639 configurations, |
| 2654 combinators, | 2640 combinators, |
| 2655 semicolon); | 2641 semicolon); |
| 2656 } | 2642 } |
| 2657 | 2643 |
| 2658 /** | 2644 /** |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2691 Expression expression = parseConditionalExpression(); | 2677 Expression expression = parseConditionalExpression(); |
| 2692 TokenType type = _currentToken.type; | 2678 TokenType type = _currentToken.type; |
| 2693 if (type == TokenType.PERIOD_PERIOD) { | 2679 if (type == TokenType.PERIOD_PERIOD) { |
| 2694 List<Expression> cascadeSections = <Expression>[]; | 2680 List<Expression> cascadeSections = <Expression>[]; |
| 2695 do { | 2681 do { |
| 2696 Expression section = parseCascadeSection(); | 2682 Expression section = parseCascadeSection(); |
| 2697 if (section != null) { | 2683 if (section != null) { |
| 2698 cascadeSections.add(section); | 2684 cascadeSections.add(section); |
| 2699 } | 2685 } |
| 2700 } while (_currentToken.type == TokenType.PERIOD_PERIOD); | 2686 } while (_currentToken.type == TokenType.PERIOD_PERIOD); |
| 2701 return astFactory.cascadeExpression(expression, cascadeSections); | 2687 return new CascadeExpression(expression, cascadeSections); |
| 2702 } else if (type.isAssignmentOperator) { | 2688 } else if (type.isAssignmentOperator) { |
| 2703 Token operator = getAndAdvance(); | 2689 Token operator = getAndAdvance(); |
| 2704 _ensureAssignable(expression); | 2690 _ensureAssignable(expression); |
| 2705 return astFactory.assignmentExpression( | 2691 return new AssignmentExpression(expression, operator, parseExpression2()); |
| 2706 expression, operator, parseExpression2()); | |
| 2707 } | 2692 } |
| 2708 return expression; | 2693 return expression; |
| 2709 } | 2694 } |
| 2710 | 2695 |
| 2711 /** | 2696 /** |
| 2712 * Parse a list of expressions. Return the expression that was parsed. | 2697 * Parse a list of expressions. Return the expression that was parsed. |
| 2713 * | 2698 * |
| 2714 * expressionList ::= | 2699 * expressionList ::= |
| 2715 * expression (',' expression)* | 2700 * expression (',' expression)* |
| 2716 */ | 2701 */ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2740 // | 2725 // |
| 2741 // assignableExpression is a subset of conditionalExpression, so we can | 2726 // assignableExpression is a subset of conditionalExpression, so we can |
| 2742 // parse a conditional expression and then determine whether it is followed | 2727 // parse a conditional expression and then determine whether it is followed |
| 2743 // by an assignmentOperator, checking for conformance to the restricted | 2728 // by an assignmentOperator, checking for conformance to the restricted |
| 2744 // grammar after making that determination. | 2729 // grammar after making that determination. |
| 2745 // | 2730 // |
| 2746 Expression expression = parseConditionalExpression(); | 2731 Expression expression = parseConditionalExpression(); |
| 2747 if (_currentToken.type.isAssignmentOperator) { | 2732 if (_currentToken.type.isAssignmentOperator) { |
| 2748 Token operator = getAndAdvance(); | 2733 Token operator = getAndAdvance(); |
| 2749 _ensureAssignable(expression); | 2734 _ensureAssignable(expression); |
| 2750 expression = astFactory.assignmentExpression( | 2735 expression = new AssignmentExpression( |
| 2751 expression, operator, parseExpressionWithoutCascade()); | 2736 expression, operator, parseExpressionWithoutCascade()); |
| 2752 } | 2737 } |
| 2753 return expression; | 2738 return expression; |
| 2754 } | 2739 } |
| 2755 | 2740 |
| 2756 /** | 2741 /** |
| 2757 * Parse a class extends clause. Return the class extends clause that was | 2742 * Parse a class extends clause. Return the class extends clause that was |
| 2758 * parsed. | 2743 * parsed. |
| 2759 * | 2744 * |
| 2760 * This method assumes that the current token matches `Keyword.EXTENDS`. | 2745 * This method assumes that the current token matches `Keyword.EXTENDS`. |
| 2761 * | 2746 * |
| 2762 * classExtendsClause ::= | 2747 * classExtendsClause ::= |
| 2763 * 'extends' type | 2748 * 'extends' type |
| 2764 */ | 2749 */ |
| 2765 ExtendsClause parseExtendsClause() { | 2750 ExtendsClause parseExtendsClause() { |
| 2766 Token keyword = getAndAdvance(); | 2751 Token keyword = getAndAdvance(); |
| 2767 TypeName superclass = parseTypeName(false); | 2752 TypeName superclass = parseTypeName(false); |
| 2768 _mustNotBeNullable(superclass, ParserErrorCode.NULLABLE_TYPE_IN_EXTENDS); | 2753 _mustNotBeNullable(superclass, ParserErrorCode.NULLABLE_TYPE_IN_EXTENDS); |
| 2769 return astFactory.extendsClause(keyword, superclass); | 2754 return new ExtendsClause(keyword, superclass); |
| 2770 } | 2755 } |
| 2771 | 2756 |
| 2772 /** | 2757 /** |
| 2773 * Parse the 'final', 'const', 'var' or type preceding a variable declaration. | 2758 * Parse the 'final', 'const', 'var' or type preceding a variable declaration. |
| 2774 * The [optional] is `true` if the keyword and type are optional. Return the | 2759 * The [optional] is `true` if the keyword and type are optional. Return the |
| 2775 * 'final', 'const', 'var' or type that was parsed. | 2760 * 'final', 'const', 'var' or type that was parsed. |
| 2776 * | 2761 * |
| 2777 * finalConstVarOrType ::= | 2762 * finalConstVarOrType ::= |
| 2778 * 'final' type? | 2763 * 'final' type? |
| 2779 * | 'const' type? | 2764 * | 'const' type? |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2830 NormalFormalParameter parameter = parseNormalFormalParameter(); | 2815 NormalFormalParameter parameter = parseNormalFormalParameter(); |
| 2831 TokenType type = _currentToken.type; | 2816 TokenType type = _currentToken.type; |
| 2832 if (type == TokenType.EQ) { | 2817 if (type == TokenType.EQ) { |
| 2833 Token separator = getAndAdvance(); | 2818 Token separator = getAndAdvance(); |
| 2834 Expression defaultValue = parseExpression2(); | 2819 Expression defaultValue = parseExpression2(); |
| 2835 if (kind == ParameterKind.REQUIRED) { | 2820 if (kind == ParameterKind.REQUIRED) { |
| 2836 _reportErrorForNode( | 2821 _reportErrorForNode( |
| 2837 ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, parameter); | 2822 ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, parameter); |
| 2838 kind = ParameterKind.POSITIONAL; | 2823 kind = ParameterKind.POSITIONAL; |
| 2839 } | 2824 } |
| 2840 return astFactory.defaultFormalParameter( | 2825 return new DefaultFormalParameter( |
| 2841 parameter, kind, separator, defaultValue); | 2826 parameter, kind, separator, defaultValue); |
| 2842 } else if (type == TokenType.COLON) { | 2827 } else if (type == TokenType.COLON) { |
| 2843 Token separator = getAndAdvance(); | 2828 Token separator = getAndAdvance(); |
| 2844 Expression defaultValue = parseExpression2(); | 2829 Expression defaultValue = parseExpression2(); |
| 2845 if (kind == ParameterKind.POSITIONAL) { | 2830 if (kind == ParameterKind.POSITIONAL) { |
| 2846 _reportErrorForToken( | 2831 _reportErrorForToken( |
| 2847 ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, | 2832 ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, |
| 2848 separator); | 2833 separator); |
| 2849 } else if (kind == ParameterKind.REQUIRED) { | 2834 } else if (kind == ParameterKind.REQUIRED) { |
| 2850 _reportErrorForNode( | 2835 _reportErrorForNode( |
| 2851 ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter); | 2836 ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter); |
| 2852 kind = ParameterKind.NAMED; | 2837 kind = ParameterKind.NAMED; |
| 2853 } | 2838 } |
| 2854 return astFactory.defaultFormalParameter( | 2839 return new DefaultFormalParameter( |
| 2855 parameter, kind, separator, defaultValue); | 2840 parameter, kind, separator, defaultValue); |
| 2856 } else if (kind != ParameterKind.REQUIRED) { | 2841 } else if (kind != ParameterKind.REQUIRED) { |
| 2857 return astFactory.defaultFormalParameter(parameter, kind, null, null); | 2842 return new DefaultFormalParameter(parameter, kind, null, null); |
| 2858 } | 2843 } |
| 2859 return parameter; | 2844 return parameter; |
| 2860 } | 2845 } |
| 2861 | 2846 |
| 2862 /** | 2847 /** |
| 2863 * Parse a list of formal parameters. Return the formal parameters that were | 2848 * Parse a list of formal parameters. Return the formal parameters that were |
| 2864 * parsed. | 2849 * parsed. |
| 2865 * | 2850 * |
| 2866 * formalParameterList ::= | 2851 * formalParameterList ::= |
| 2867 * '(' ')' | 2852 * '(' ')' |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2920 Token forKeyword = _expectKeyword(Keyword.FOR); | 2905 Token forKeyword = _expectKeyword(Keyword.FOR); |
| 2921 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); | 2906 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); |
| 2922 VariableDeclarationList variableList = null; | 2907 VariableDeclarationList variableList = null; |
| 2923 Expression initialization = null; | 2908 Expression initialization = null; |
| 2924 if (!_matches(TokenType.SEMICOLON)) { | 2909 if (!_matches(TokenType.SEMICOLON)) { |
| 2925 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); | 2910 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); |
| 2926 if (_matchesIdentifier() && | 2911 if (_matchesIdentifier() && |
| 2927 (_tokenMatchesKeyword(_peek(), Keyword.IN) || | 2912 (_tokenMatchesKeyword(_peek(), Keyword.IN) || |
| 2928 _tokenMatches(_peek(), TokenType.COLON))) { | 2913 _tokenMatches(_peek(), TokenType.COLON))) { |
| 2929 SimpleIdentifier variableName = _parseSimpleIdentifierUnchecked(); | 2914 SimpleIdentifier variableName = _parseSimpleIdentifierUnchecked(); |
| 2930 variableList = astFactory.variableDeclarationList( | 2915 variableList = new VariableDeclarationList(commentAndMetadata.comment, |
| 2931 commentAndMetadata.comment, | 2916 commentAndMetadata.metadata, null, null, <VariableDeclaration>[ |
| 2932 commentAndMetadata.metadata, | 2917 new VariableDeclaration(variableName, null, null) |
| 2933 null, | |
| 2934 null, <VariableDeclaration>[ | |
| 2935 astFactory.variableDeclaration(variableName, null, null) | |
| 2936 ]); | 2918 ]); |
| 2937 } else if (isInitializedVariableDeclaration()) { | 2919 } else if (isInitializedVariableDeclaration()) { |
| 2938 variableList = | 2920 variableList = |
| 2939 parseVariableDeclarationListAfterMetadata(commentAndMetadata); | 2921 parseVariableDeclarationListAfterMetadata(commentAndMetadata); |
| 2940 } else { | 2922 } else { |
| 2941 initialization = parseExpression2(); | 2923 initialization = parseExpression2(); |
| 2942 } | 2924 } |
| 2943 TokenType type = _currentToken.type; | 2925 TokenType type = _currentToken.type; |
| 2944 if (_matchesKeyword(Keyword.IN) || type == TokenType.COLON) { | 2926 if (_matchesKeyword(Keyword.IN) || type == TokenType.COLON) { |
| 2945 if (type == TokenType.COLON) { | 2927 if (type == TokenType.COLON) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2959 [variables.length.toString()]); | 2941 [variables.length.toString()]); |
| 2960 } | 2942 } |
| 2961 VariableDeclaration variable = variables[0]; | 2943 VariableDeclaration variable = variables[0]; |
| 2962 if (variable.initializer != null) { | 2944 if (variable.initializer != null) { |
| 2963 _reportErrorForCurrentToken( | 2945 _reportErrorForCurrentToken( |
| 2964 ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH); | 2946 ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH); |
| 2965 } | 2947 } |
| 2966 Token keyword = variableList.keyword; | 2948 Token keyword = variableList.keyword; |
| 2967 TypeName type = variableList.type; | 2949 TypeName type = variableList.type; |
| 2968 if (keyword != null || type != null) { | 2950 if (keyword != null || type != null) { |
| 2969 loopVariable = astFactory.declaredIdentifier( | 2951 loopVariable = new DeclaredIdentifier( |
| 2970 commentAndMetadata.comment, | 2952 commentAndMetadata.comment, |
| 2971 commentAndMetadata.metadata, | 2953 commentAndMetadata.metadata, |
| 2972 keyword, | 2954 keyword, |
| 2973 type, | 2955 type, |
| 2974 astFactory.simpleIdentifier(variable.name.token, | 2956 new SimpleIdentifier(variable.name.token, |
| 2975 isDeclaration: true)); | 2957 isDeclaration: true)); |
| 2976 } else { | 2958 } else { |
| 2977 if (commentAndMetadata.hasMetadata) { | 2959 if (commentAndMetadata.hasMetadata) { |
| 2978 // TODO(jwren) metadata isn't allowed before the identifier in | 2960 // TODO(jwren) metadata isn't allowed before the identifier in |
| 2979 // "identifier in expression", add warning if commentAndMetadata | 2961 // "identifier in expression", add warning if commentAndMetadata |
| 2980 // has content | 2962 // has content |
| 2981 } | 2963 } |
| 2982 identifier = variable.name; | 2964 identifier = variable.name; |
| 2983 } | 2965 } |
| 2984 } | 2966 } |
| 2985 Token inKeyword = getAndAdvance(); | 2967 Token inKeyword = getAndAdvance(); |
| 2986 Expression iterator = parseExpression2(); | 2968 Expression iterator = parseExpression2(); |
| 2987 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); | 2969 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 2988 Statement body = parseStatement2(); | 2970 Statement body = parseStatement2(); |
| 2989 if (loopVariable == null) { | 2971 if (loopVariable == null) { |
| 2990 return astFactory.forEachStatementWithReference( | 2972 return new ForEachStatement.withReference( |
| 2991 awaitKeyword, | 2973 awaitKeyword, |
| 2992 forKeyword, | 2974 forKeyword, |
| 2993 leftParenthesis, | 2975 leftParenthesis, |
| 2994 identifier, | 2976 identifier, |
| 2995 inKeyword, | 2977 inKeyword, |
| 2996 iterator, | 2978 iterator, |
| 2997 rightParenthesis, | 2979 rightParenthesis, |
| 2998 body); | 2980 body); |
| 2999 } | 2981 } |
| 3000 return astFactory.forEachStatementWithDeclaration( | 2982 return new ForEachStatement.withDeclaration( |
| 3001 awaitKeyword, | 2983 awaitKeyword, |
| 3002 forKeyword, | 2984 forKeyword, |
| 3003 leftParenthesis, | 2985 leftParenthesis, |
| 3004 loopVariable, | 2986 loopVariable, |
| 3005 inKeyword, | 2987 inKeyword, |
| 3006 iterator, | 2988 iterator, |
| 3007 rightParenthesis, | 2989 rightParenthesis, |
| 3008 body); | 2990 body); |
| 3009 } | 2991 } |
| 3010 } | 2992 } |
| 3011 if (awaitKeyword != null) { | 2993 if (awaitKeyword != null) { |
| 3012 _reportErrorForToken( | 2994 _reportErrorForToken( |
| 3013 ParserErrorCode.INVALID_AWAIT_IN_FOR, awaitKeyword); | 2995 ParserErrorCode.INVALID_AWAIT_IN_FOR, awaitKeyword); |
| 3014 } | 2996 } |
| 3015 Token leftSeparator = _expect(TokenType.SEMICOLON); | 2997 Token leftSeparator = _expect(TokenType.SEMICOLON); |
| 3016 Expression condition = null; | 2998 Expression condition = null; |
| 3017 if (!_matches(TokenType.SEMICOLON)) { | 2999 if (!_matches(TokenType.SEMICOLON)) { |
| 3018 condition = parseExpression2(); | 3000 condition = parseExpression2(); |
| 3019 } | 3001 } |
| 3020 Token rightSeparator = _expect(TokenType.SEMICOLON); | 3002 Token rightSeparator = _expect(TokenType.SEMICOLON); |
| 3021 List<Expression> updaters = null; | 3003 List<Expression> updaters = null; |
| 3022 if (!_matches(TokenType.CLOSE_PAREN)) { | 3004 if (!_matches(TokenType.CLOSE_PAREN)) { |
| 3023 updaters = parseExpressionList(); | 3005 updaters = parseExpressionList(); |
| 3024 } | 3006 } |
| 3025 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); | 3007 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 3026 Statement body = parseStatement2(); | 3008 Statement body = parseStatement2(); |
| 3027 return astFactory.forStatement( | 3009 return new ForStatement( |
| 3028 forKeyword, | 3010 forKeyword, |
| 3029 leftParenthesis, | 3011 leftParenthesis, |
| 3030 variableList, | 3012 variableList, |
| 3031 initialization, | 3013 initialization, |
| 3032 leftSeparator, | 3014 leftSeparator, |
| 3033 condition, | 3015 condition, |
| 3034 rightSeparator, | 3016 rightSeparator, |
| 3035 updaters, | 3017 updaters, |
| 3036 rightParenthesis, | 3018 rightParenthesis, |
| 3037 body); | 3019 body); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3064 _inAsync = false; | 3046 _inAsync = false; |
| 3065 _inGenerator = false; | 3047 _inGenerator = false; |
| 3066 _inLoop = false; | 3048 _inLoop = false; |
| 3067 _inSwitch = false; | 3049 _inSwitch = false; |
| 3068 try { | 3050 try { |
| 3069 TokenType type = _currentToken.type; | 3051 TokenType type = _currentToken.type; |
| 3070 if (type == TokenType.SEMICOLON) { | 3052 if (type == TokenType.SEMICOLON) { |
| 3071 if (!mayBeEmpty) { | 3053 if (!mayBeEmpty) { |
| 3072 _reportErrorForCurrentToken(emptyErrorCode); | 3054 _reportErrorForCurrentToken(emptyErrorCode); |
| 3073 } | 3055 } |
| 3074 return astFactory.emptyFunctionBody(getAndAdvance()); | 3056 return new EmptyFunctionBody(getAndAdvance()); |
| 3075 } | 3057 } |
| 3076 Token keyword = null; | 3058 Token keyword = null; |
| 3077 Token star = null; | 3059 Token star = null; |
| 3078 bool foundAsync = false; | 3060 bool foundAsync = false; |
| 3079 bool foundSync = false; | 3061 bool foundSync = false; |
| 3080 if (type == TokenType.IDENTIFIER) { | 3062 if (type == TokenType.IDENTIFIER) { |
| 3081 String lexeme = _currentToken.lexeme; | 3063 String lexeme = _currentToken.lexeme; |
| 3082 if (lexeme == ASYNC) { | 3064 if (lexeme == ASYNC) { |
| 3083 foundAsync = true; | 3065 foundAsync = true; |
| 3084 keyword = getAndAdvance(); | 3066 keyword = getAndAdvance(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3113 _reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, | 3095 _reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, |
| 3114 [_currentToken.lexeme]); | 3096 [_currentToken.lexeme]); |
| 3115 _advance(); | 3097 _advance(); |
| 3116 } | 3098 } |
| 3117 Expression expression = parseExpression2(); | 3099 Expression expression = parseExpression2(); |
| 3118 Token semicolon = null; | 3100 Token semicolon = null; |
| 3119 if (!inExpression) { | 3101 if (!inExpression) { |
| 3120 semicolon = _expect(TokenType.SEMICOLON); | 3102 semicolon = _expect(TokenType.SEMICOLON); |
| 3121 } | 3103 } |
| 3122 if (!_parseFunctionBodies) { | 3104 if (!_parseFunctionBodies) { |
| 3123 return astFactory | 3105 return new EmptyFunctionBody( |
| 3124 .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)); | 3106 _createSyntheticToken(TokenType.SEMICOLON)); |
| 3125 } | 3107 } |
| 3126 return astFactory.expressionFunctionBody( | 3108 return new ExpressionFunctionBody( |
| 3127 keyword, functionDefinition, expression, semicolon); | 3109 keyword, functionDefinition, expression, semicolon); |
| 3128 } else if (type == TokenType.OPEN_CURLY_BRACKET) { | 3110 } else if (type == TokenType.OPEN_CURLY_BRACKET) { |
| 3129 if (keyword != null) { | 3111 if (keyword != null) { |
| 3130 if (foundSync && star == null) { | 3112 if (foundSync && star == null) { |
| 3131 _reportErrorForToken( | 3113 _reportErrorForToken( |
| 3132 ParserErrorCode.MISSING_STAR_AFTER_SYNC, keyword); | 3114 ParserErrorCode.MISSING_STAR_AFTER_SYNC, keyword); |
| 3133 } | 3115 } |
| 3134 } | 3116 } |
| 3135 if (!_parseFunctionBodies) { | 3117 if (!_parseFunctionBodies) { |
| 3136 _skipBlock(); | 3118 _skipBlock(); |
| 3137 return astFactory | 3119 return new EmptyFunctionBody( |
| 3138 .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)); | 3120 _createSyntheticToken(TokenType.SEMICOLON)); |
| 3139 } | 3121 } |
| 3140 return astFactory.blockFunctionBody(keyword, star, parseBlock()); | 3122 return new BlockFunctionBody(keyword, star, parseBlock()); |
| 3141 } else if (_matchesString(_NATIVE)) { | 3123 } else if (_matchesString(_NATIVE)) { |
| 3142 Token nativeToken = getAndAdvance(); | 3124 Token nativeToken = getAndAdvance(); |
| 3143 StringLiteral stringLiteral = null; | 3125 StringLiteral stringLiteral = null; |
| 3144 if (_matches(TokenType.STRING)) { | 3126 if (_matches(TokenType.STRING)) { |
| 3145 stringLiteral = _parseStringLiteralUnchecked(); | 3127 stringLiteral = _parseStringLiteralUnchecked(); |
| 3146 } | 3128 } |
| 3147 return astFactory.nativeFunctionBody( | 3129 return new NativeFunctionBody( |
| 3148 nativeToken, stringLiteral, _expect(TokenType.SEMICOLON)); | 3130 nativeToken, stringLiteral, _expect(TokenType.SEMICOLON)); |
| 3149 } else { | 3131 } else { |
| 3150 // Invalid function body | 3132 // Invalid function body |
| 3151 _reportErrorForCurrentToken(emptyErrorCode); | 3133 _reportErrorForCurrentToken(emptyErrorCode); |
| 3152 return astFactory | 3134 return new EmptyFunctionBody( |
| 3153 .emptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)); | 3135 _createSyntheticToken(TokenType.SEMICOLON)); |
| 3154 } | 3136 } |
| 3155 } finally { | 3137 } finally { |
| 3156 _inAsync = wasInAsync; | 3138 _inAsync = wasInAsync; |
| 3157 _inGenerator = wasInGenerator; | 3139 _inGenerator = wasInGenerator; |
| 3158 _inLoop = wasInLoop; | 3140 _inLoop = wasInLoop; |
| 3159 _inSwitch = wasInSwitch; | 3141 _inSwitch = wasInSwitch; |
| 3160 } | 3142 } |
| 3161 } | 3143 } |
| 3162 | 3144 |
| 3163 /** | 3145 /** |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3181 bool isGetter = false; | 3163 bool isGetter = false; |
| 3182 Keyword keyword = _currentToken.keyword; | 3164 Keyword keyword = _currentToken.keyword; |
| 3183 SimpleIdentifier name = null; | 3165 SimpleIdentifier name = null; |
| 3184 if (keyword == Keyword.GET) { | 3166 if (keyword == Keyword.GET) { |
| 3185 keywordToken = getAndAdvance(); | 3167 keywordToken = getAndAdvance(); |
| 3186 isGetter = true; | 3168 isGetter = true; |
| 3187 } else if (keyword == Keyword.SET) { | 3169 } else if (keyword == Keyword.SET) { |
| 3188 keywordToken = getAndAdvance(); | 3170 keywordToken = getAndAdvance(); |
| 3189 } | 3171 } |
| 3190 if (keywordToken != null && _matches(TokenType.OPEN_PAREN)) { | 3172 if (keywordToken != null && _matches(TokenType.OPEN_PAREN)) { |
| 3191 name = astFactory.simpleIdentifier(keywordToken, isDeclaration: true); | 3173 name = new SimpleIdentifier(keywordToken, isDeclaration: true); |
| 3192 keywordToken = null; | 3174 keywordToken = null; |
| 3193 isGetter = false; | 3175 isGetter = false; |
| 3194 } else { | 3176 } else { |
| 3195 name = parseSimpleIdentifier(isDeclaration: true); | 3177 name = parseSimpleIdentifier(isDeclaration: true); |
| 3196 } | 3178 } |
| 3197 TypeParameterList typeParameters = _parseGenericMethodTypeParameters(); | 3179 TypeParameterList typeParameters = _parseGenericMethodTypeParameters(); |
| 3198 FormalParameterList parameters = null; | 3180 FormalParameterList parameters = null; |
| 3199 if (!isGetter) { | 3181 if (!isGetter) { |
| 3200 if (_matches(TokenType.OPEN_PAREN)) { | 3182 if (_matches(TokenType.OPEN_PAREN)) { |
| 3201 parameters = _parseFormalParameterListUnchecked(); | 3183 parameters = _parseFormalParameterListUnchecked(); |
| 3202 _validateFormalParameterList(parameters); | 3184 _validateFormalParameterList(parameters); |
| 3203 } else { | 3185 } else { |
| 3204 _reportErrorForCurrentToken( | 3186 _reportErrorForCurrentToken( |
| 3205 ParserErrorCode.MISSING_FUNCTION_PARAMETERS); | 3187 ParserErrorCode.MISSING_FUNCTION_PARAMETERS); |
| 3206 parameters = astFactory.formalParameterList( | 3188 parameters = new FormalParameterList( |
| 3207 _createSyntheticToken(TokenType.OPEN_PAREN), | 3189 _createSyntheticToken(TokenType.OPEN_PAREN), |
| 3208 null, | 3190 null, |
| 3209 null, | 3191 null, |
| 3210 null, | 3192 null, |
| 3211 _createSyntheticToken(TokenType.CLOSE_PAREN)); | 3193 _createSyntheticToken(TokenType.CLOSE_PAREN)); |
| 3212 } | 3194 } |
| 3213 } else if (_matches(TokenType.OPEN_PAREN)) { | 3195 } else if (_matches(TokenType.OPEN_PAREN)) { |
| 3214 _reportErrorForCurrentToken(ParserErrorCode.GETTER_WITH_PARAMETERS); | 3196 _reportErrorForCurrentToken(ParserErrorCode.GETTER_WITH_PARAMETERS); |
| 3215 _parseFormalParameterListUnchecked(); | 3197 _parseFormalParameterListUnchecked(); |
| 3216 } | 3198 } |
| 3217 FunctionBody body; | 3199 FunctionBody body; |
| 3218 if (externalKeyword == null) { | 3200 if (externalKeyword == null) { |
| 3219 body = parseFunctionBody( | 3201 body = parseFunctionBody( |
| 3220 false, ParserErrorCode.MISSING_FUNCTION_BODY, false); | 3202 false, ParserErrorCode.MISSING_FUNCTION_BODY, false); |
| 3221 } else { | 3203 } else { |
| 3222 body = astFactory.emptyFunctionBody(_expect(TokenType.SEMICOLON)); | 3204 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON)); |
| 3223 } | 3205 } |
| 3224 // if (!isStatement && matches(TokenType.SEMICOLON)) { | 3206 // if (!isStatement && matches(TokenType.SEMICOLON)) { |
| 3225 // // TODO(brianwilkerson) Improve this error message. | 3207 // // TODO(brianwilkerson) Improve this error message. |
| 3226 // reportError(ParserErrorCode.UNEXPECTED_TOKEN, currentToken.getLexeme
()); | 3208 // reportError(ParserErrorCode.UNEXPECTED_TOKEN, currentToken.getLexeme
()); |
| 3227 // advance(); | 3209 // advance(); |
| 3228 // } | 3210 // } |
| 3229 return astFactory.functionDeclaration( | 3211 return new FunctionDeclaration( |
| 3230 commentAndMetadata.comment, | 3212 commentAndMetadata.comment, |
| 3231 commentAndMetadata.metadata, | 3213 commentAndMetadata.metadata, |
| 3232 externalKeyword, | 3214 externalKeyword, |
| 3233 returnType, | 3215 returnType, |
| 3234 keywordToken, | 3216 keywordToken, |
| 3235 name, | 3217 name, |
| 3236 astFactory.functionExpression(typeParameters, parameters, body)); | 3218 new FunctionExpression(typeParameters, parameters, body)); |
| 3237 } | 3219 } |
| 3238 | 3220 |
| 3239 /** | 3221 /** |
| 3240 * Parse a function declaration statement. Return the function declaration | 3222 * Parse a function declaration statement. Return the function declaration |
| 3241 * statement that was parsed. | 3223 * statement that was parsed. |
| 3242 * | 3224 * |
| 3243 * functionDeclarationStatement ::= | 3225 * functionDeclarationStatement ::= |
| 3244 * functionSignature functionBody | 3226 * functionSignature functionBody |
| 3245 */ | 3227 */ |
| 3246 Statement parseFunctionDeclarationStatement() { | 3228 Statement parseFunctionDeclarationStatement() { |
| 3247 Modifiers modifiers = parseModifiers(); | 3229 Modifiers modifiers = parseModifiers(); |
| 3248 _validateModifiersForFunctionDeclarationStatement(modifiers); | 3230 _validateModifiersForFunctionDeclarationStatement(modifiers); |
| 3249 return _parseFunctionDeclarationStatementAfterReturnType( | 3231 return _parseFunctionDeclarationStatementAfterReturnType( |
| 3250 parseCommentAndMetadata(), _parseOptionalReturnType()); | 3232 parseCommentAndMetadata(), _parseOptionalReturnType()); |
| 3251 } | 3233 } |
| 3252 | 3234 |
| 3253 /** | 3235 /** |
| 3254 * Parse a function expression. Return the function expression that was | 3236 * Parse a function expression. Return the function expression that was |
| 3255 * parsed. | 3237 * parsed. |
| 3256 * | 3238 * |
| 3257 * functionExpression ::= | 3239 * functionExpression ::= |
| 3258 * typeParameters? formalParameterList functionExpressionBody | 3240 * typeParameters? formalParameterList functionExpressionBody |
| 3259 */ | 3241 */ |
| 3260 FunctionExpression parseFunctionExpression() { | 3242 FunctionExpression parseFunctionExpression() { |
| 3261 TypeParameterList typeParameters = _parseGenericMethodTypeParameters(); | 3243 TypeParameterList typeParameters = _parseGenericMethodTypeParameters(); |
| 3262 FormalParameterList parameters = parseFormalParameterList(); | 3244 FormalParameterList parameters = parseFormalParameterList(); |
| 3263 _validateFormalParameterList(parameters); | 3245 _validateFormalParameterList(parameters); |
| 3264 FunctionBody body = | 3246 FunctionBody body = |
| 3265 parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, true); | 3247 parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, true); |
| 3266 return astFactory.functionExpression(typeParameters, parameters, body); | 3248 return new FunctionExpression(typeParameters, parameters, body); |
| 3267 } | 3249 } |
| 3268 | 3250 |
| 3269 /** | 3251 /** |
| 3270 * Parse a getter. The [commentAndMetadata] is the documentation comment and | 3252 * Parse a getter. The [commentAndMetadata] is the documentation comment and |
| 3271 * metadata to be associated with the declaration. The externalKeyword] is the | 3253 * metadata to be associated with the declaration. The externalKeyword] is the |
| 3272 * 'external' token. The staticKeyword] is the static keyword, or `null` if | 3254 * 'external' token. The staticKeyword] is the static keyword, or `null` if |
| 3273 * the getter is not static. The [returnType] the return type that has already | 3255 * the getter is not static. The [returnType] the return type that has already |
| 3274 * been parsed, or `null` if there was no return type. Return the getter that | 3256 * been parsed, or `null` if there was no return type. Return the getter that |
| 3275 * was parsed. | 3257 * was parsed. |
| 3276 * | 3258 * |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3292 _advance(); | 3274 _advance(); |
| 3293 _advance(); | 3275 _advance(); |
| 3294 } | 3276 } |
| 3295 FunctionBody body = parseFunctionBody( | 3277 FunctionBody body = parseFunctionBody( |
| 3296 externalKeyword != null || staticKeyword == null, | 3278 externalKeyword != null || staticKeyword == null, |
| 3297 ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, | 3279 ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, |
| 3298 false); | 3280 false); |
| 3299 if (externalKeyword != null && body is! EmptyFunctionBody) { | 3281 if (externalKeyword != null && body is! EmptyFunctionBody) { |
| 3300 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY); | 3282 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY); |
| 3301 } | 3283 } |
| 3302 return astFactory.methodDeclaration( | 3284 return new MethodDeclaration( |
| 3303 commentAndMetadata.comment, | 3285 commentAndMetadata.comment, |
| 3304 commentAndMetadata.metadata, | 3286 commentAndMetadata.metadata, |
| 3305 externalKeyword, | 3287 externalKeyword, |
| 3306 staticKeyword, | 3288 staticKeyword, |
| 3307 returnType, | 3289 returnType, |
| 3308 propertyKeyword, | 3290 propertyKeyword, |
| 3309 null, | 3291 null, |
| 3310 name, | 3292 name, |
| 3311 null, | 3293 null, |
| 3312 null, | 3294 null, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3332 | 3314 |
| 3333 /** | 3315 /** |
| 3334 * Parse an if-null expression. Return the if-null expression that was | 3316 * Parse an if-null expression. Return the if-null expression that was |
| 3335 * parsed. | 3317 * parsed. |
| 3336 * | 3318 * |
| 3337 * ifNullExpression ::= logicalOrExpression ('??' logicalOrExpression)* | 3319 * ifNullExpression ::= logicalOrExpression ('??' logicalOrExpression)* |
| 3338 */ | 3320 */ |
| 3339 Expression parseIfNullExpression() { | 3321 Expression parseIfNullExpression() { |
| 3340 Expression expression = parseLogicalOrExpression(); | 3322 Expression expression = parseLogicalOrExpression(); |
| 3341 while (_currentToken.type == TokenType.QUESTION_QUESTION) { | 3323 while (_currentToken.type == TokenType.QUESTION_QUESTION) { |
| 3342 expression = astFactory.binaryExpression( | 3324 expression = new BinaryExpression( |
| 3343 expression, getAndAdvance(), parseLogicalOrExpression()); | 3325 expression, getAndAdvance(), parseLogicalOrExpression()); |
| 3344 } | 3326 } |
| 3345 return expression; | 3327 return expression; |
| 3346 } | 3328 } |
| 3347 | 3329 |
| 3348 /** | 3330 /** |
| 3349 * Parse an if statement. Return the if statement that was parsed. | 3331 * Parse an if statement. Return the if statement that was parsed. |
| 3350 * | 3332 * |
| 3351 * This method assumes that the current token matches `Keyword.IF`. | 3333 * This method assumes that the current token matches `Keyword.IF`. |
| 3352 * | 3334 * |
| 3353 * ifStatement ::= | 3335 * ifStatement ::= |
| 3354 * 'if' '(' expression ')' statement ('else' statement)? | 3336 * 'if' '(' expression ')' statement ('else' statement)? |
| 3355 */ | 3337 */ |
| 3356 Statement parseIfStatement() { | 3338 Statement parseIfStatement() { |
| 3357 Token ifKeyword = getAndAdvance(); | 3339 Token ifKeyword = getAndAdvance(); |
| 3358 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); | 3340 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); |
| 3359 Expression condition = parseExpression2(); | 3341 Expression condition = parseExpression2(); |
| 3360 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); | 3342 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 3361 Statement thenStatement = parseStatement2(); | 3343 Statement thenStatement = parseStatement2(); |
| 3362 Token elseKeyword = null; | 3344 Token elseKeyword = null; |
| 3363 Statement elseStatement = null; | 3345 Statement elseStatement = null; |
| 3364 if (_matchesKeyword(Keyword.ELSE)) { | 3346 if (_matchesKeyword(Keyword.ELSE)) { |
| 3365 elseKeyword = getAndAdvance(); | 3347 elseKeyword = getAndAdvance(); |
| 3366 elseStatement = parseStatement2(); | 3348 elseStatement = parseStatement2(); |
| 3367 } | 3349 } |
| 3368 return astFactory.ifStatement(ifKeyword, leftParenthesis, condition, | 3350 return new IfStatement(ifKeyword, leftParenthesis, condition, |
| 3369 rightParenthesis, thenStatement, elseKeyword, elseStatement); | 3351 rightParenthesis, thenStatement, elseKeyword, elseStatement); |
| 3370 } | 3352 } |
| 3371 | 3353 |
| 3372 /** | 3354 /** |
| 3373 * Parse an implements clause. Return the implements clause that was parsed. | 3355 * Parse an implements clause. Return the implements clause that was parsed. |
| 3374 * | 3356 * |
| 3375 * This method assumes that the current token matches `Keyword.IMPLEMENTS`. | 3357 * This method assumes that the current token matches `Keyword.IMPLEMENTS`. |
| 3376 * | 3358 * |
| 3377 * implementsClause ::= | 3359 * implementsClause ::= |
| 3378 * 'implements' type (',' type)* | 3360 * 'implements' type (',' type)* |
| 3379 */ | 3361 */ |
| 3380 ImplementsClause parseImplementsClause() { | 3362 ImplementsClause parseImplementsClause() { |
| 3381 Token keyword = getAndAdvance(); | 3363 Token keyword = getAndAdvance(); |
| 3382 List<TypeName> interfaces = <TypeName>[]; | 3364 List<TypeName> interfaces = <TypeName>[]; |
| 3383 do { | 3365 do { |
| 3384 TypeName typeName = parseTypeName(false); | 3366 TypeName typeName = parseTypeName(false); |
| 3385 _mustNotBeNullable(typeName, ParserErrorCode.NULLABLE_TYPE_IN_IMPLEMENTS); | 3367 _mustNotBeNullable(typeName, ParserErrorCode.NULLABLE_TYPE_IN_IMPLEMENTS); |
| 3386 interfaces.add(typeName); | 3368 interfaces.add(typeName); |
| 3387 } while (_optional(TokenType.COMMA)); | 3369 } while (_optional(TokenType.COMMA)); |
| 3388 return astFactory.implementsClause(keyword, interfaces); | 3370 return new ImplementsClause(keyword, interfaces); |
| 3389 } | 3371 } |
| 3390 | 3372 |
| 3391 /** | 3373 /** |
| 3392 * Parse an import directive. The [commentAndMetadata] is the metadata to be | 3374 * Parse an import directive. The [commentAndMetadata] is the metadata to be |
| 3393 * associated with the directive. Return the import directive that was parsed. | 3375 * associated with the directive. Return the import directive that was parsed. |
| 3394 * | 3376 * |
| 3395 * This method assumes that the current token matches `Keyword.IMPORT`. | 3377 * This method assumes that the current token matches `Keyword.IMPORT`. |
| 3396 * | 3378 * |
| 3397 * importDirective ::= | 3379 * importDirective ::= |
| 3398 * metadata 'import' stringLiteral configuration* (deferred)? ('as' id
entifier)? combinator*';' | 3380 * metadata 'import' stringLiteral configuration* (deferred)? ('as' id
entifier)? combinator*';' |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3424 ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken]); | 3406 ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken]); |
| 3425 _advance(); | 3407 _advance(); |
| 3426 if (_matchesKeyword(Keyword.AS)) { | 3408 if (_matchesKeyword(Keyword.AS)) { |
| 3427 asToken = getAndAdvance(); | 3409 asToken = getAndAdvance(); |
| 3428 prefix = parseSimpleIdentifier(isDeclaration: true); | 3410 prefix = parseSimpleIdentifier(isDeclaration: true); |
| 3429 } | 3411 } |
| 3430 } | 3412 } |
| 3431 } | 3413 } |
| 3432 List<Combinator> combinators = parseCombinators(); | 3414 List<Combinator> combinators = parseCombinators(); |
| 3433 Token semicolon = _expect(TokenType.SEMICOLON); | 3415 Token semicolon = _expect(TokenType.SEMICOLON); |
| 3434 return astFactory.importDirective( | 3416 return new ImportDirective( |
| 3435 commentAndMetadata.comment, | 3417 commentAndMetadata.comment, |
| 3436 commentAndMetadata.metadata, | 3418 commentAndMetadata.metadata, |
| 3437 importKeyword, | 3419 importKeyword, |
| 3438 libraryUri, | 3420 libraryUri, |
| 3439 configurations, | 3421 configurations, |
| 3440 deferredToken, | 3422 deferredToken, |
| 3441 asToken, | 3423 asToken, |
| 3442 prefix, | 3424 prefix, |
| 3443 combinators, | 3425 combinators, |
| 3444 semicolon); | 3426 semicolon); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3463 * initializedIdentifier ::= | 3445 * initializedIdentifier ::= |
| 3464 * identifier ('=' expression)? | 3446 * identifier ('=' expression)? |
| 3465 */ | 3447 */ |
| 3466 FieldDeclaration parseInitializedIdentifierList( | 3448 FieldDeclaration parseInitializedIdentifierList( |
| 3467 CommentAndMetadata commentAndMetadata, | 3449 CommentAndMetadata commentAndMetadata, |
| 3468 Token staticKeyword, | 3450 Token staticKeyword, |
| 3469 Token keyword, | 3451 Token keyword, |
| 3470 TypeName type) { | 3452 TypeName type) { |
| 3471 VariableDeclarationList fieldList = | 3453 VariableDeclarationList fieldList = |
| 3472 parseVariableDeclarationListAfterType(null, keyword, type); | 3454 parseVariableDeclarationListAfterType(null, keyword, type); |
| 3473 return astFactory.fieldDeclaration( | 3455 return new FieldDeclaration( |
| 3474 commentAndMetadata.comment, | 3456 commentAndMetadata.comment, |
| 3475 commentAndMetadata.metadata, | 3457 commentAndMetadata.metadata, |
| 3476 staticKeyword, | 3458 staticKeyword, |
| 3477 fieldList, | 3459 fieldList, |
| 3478 _expect(TokenType.SEMICOLON)); | 3460 _expect(TokenType.SEMICOLON)); |
| 3479 } | 3461 } |
| 3480 | 3462 |
| 3481 /** | 3463 /** |
| 3482 * Parse an instance creation expression. The [keyword] is the 'new' or | 3464 * Parse an instance creation expression. The [keyword] is the 'new' or |
| 3483 * 'const' keyword that introduces the expression. Return the instance | 3465 * 'const' keyword that introduces the expression. Return the instance |
| 3484 * creation expression that was parsed. | 3466 * creation expression that was parsed. |
| 3485 * | 3467 * |
| 3486 * instanceCreationExpression ::= | 3468 * instanceCreationExpression ::= |
| 3487 * ('new' | 'const') type ('.' identifier)? argumentList | 3469 * ('new' | 'const') type ('.' identifier)? argumentList |
| 3488 */ | 3470 */ |
| 3489 InstanceCreationExpression parseInstanceCreationExpression(Token keyword) { | 3471 InstanceCreationExpression parseInstanceCreationExpression(Token keyword) { |
| 3490 ConstructorName constructorName = parseConstructorName(); | 3472 ConstructorName constructorName = parseConstructorName(); |
| 3491 ArgumentList argumentList = _parseArgumentListChecked(); | 3473 ArgumentList argumentList = _parseArgumentListChecked(); |
| 3492 return astFactory.instanceCreationExpression( | 3474 return new InstanceCreationExpression( |
| 3493 keyword, constructorName, argumentList); | 3475 keyword, constructorName, argumentList); |
| 3494 } | 3476 } |
| 3495 | 3477 |
| 3496 /** | 3478 /** |
| 3497 * Parse a label. Return the label that was parsed. | 3479 * Parse a label. Return the label that was parsed. |
| 3498 * | 3480 * |
| 3499 * This method assumes that the current token matches an identifier and that | 3481 * This method assumes that the current token matches an identifier and that |
| 3500 * the following token matches `TokenType.COLON`. | 3482 * the following token matches `TokenType.COLON`. |
| 3501 * | 3483 * |
| 3502 * label ::= | 3484 * label ::= |
| 3503 * identifier ':' | 3485 * identifier ':' |
| 3504 */ | 3486 */ |
| 3505 Label parseLabel({bool isDeclaration: false}) { | 3487 Label parseLabel({bool isDeclaration: false}) { |
| 3506 SimpleIdentifier label = | 3488 SimpleIdentifier label = |
| 3507 _parseSimpleIdentifierUnchecked(isDeclaration: isDeclaration); | 3489 _parseSimpleIdentifierUnchecked(isDeclaration: isDeclaration); |
| 3508 Token colon = getAndAdvance(); | 3490 Token colon = getAndAdvance(); |
| 3509 return astFactory.label(label, colon); | 3491 return new Label(label, colon); |
| 3510 } | 3492 } |
| 3511 | 3493 |
| 3512 /** | 3494 /** |
| 3513 * Parse a library directive. The [commentAndMetadata] is the metadata to be | 3495 * Parse a library directive. The [commentAndMetadata] is the metadata to be |
| 3514 * associated with the directive. Return the library directive that was | 3496 * associated with the directive. Return the library directive that was |
| 3515 * parsed. | 3497 * parsed. |
| 3516 * | 3498 * |
| 3517 * This method assumes that the current token matches `Keyword.LIBRARY`. | 3499 * This method assumes that the current token matches `Keyword.LIBRARY`. |
| 3518 * | 3500 * |
| 3519 * libraryDirective ::= | 3501 * libraryDirective ::= |
| 3520 * metadata 'library' identifier ';' | 3502 * metadata 'library' identifier ';' |
| 3521 */ | 3503 */ |
| 3522 LibraryDirective parseLibraryDirective( | 3504 LibraryDirective parseLibraryDirective( |
| 3523 CommentAndMetadata commentAndMetadata) { | 3505 CommentAndMetadata commentAndMetadata) { |
| 3524 Token keyword = getAndAdvance(); | 3506 Token keyword = getAndAdvance(); |
| 3525 LibraryIdentifier libraryName = _parseLibraryName( | 3507 LibraryIdentifier libraryName = _parseLibraryName( |
| 3526 ParserErrorCode.MISSING_NAME_IN_LIBRARY_DIRECTIVE, keyword); | 3508 ParserErrorCode.MISSING_NAME_IN_LIBRARY_DIRECTIVE, keyword); |
| 3527 Token semicolon = _expect(TokenType.SEMICOLON); | 3509 Token semicolon = _expect(TokenType.SEMICOLON); |
| 3528 return astFactory.libraryDirective(commentAndMetadata.comment, | 3510 return new LibraryDirective(commentAndMetadata.comment, |
| 3529 commentAndMetadata.metadata, keyword, libraryName, semicolon); | 3511 commentAndMetadata.metadata, keyword, libraryName, semicolon); |
| 3530 } | 3512 } |
| 3531 | 3513 |
| 3532 /** | 3514 /** |
| 3533 * Parse a library identifier. Return the library identifier that was parsed. | 3515 * Parse a library identifier. Return the library identifier that was parsed. |
| 3534 * | 3516 * |
| 3535 * libraryIdentifier ::= | 3517 * libraryIdentifier ::= |
| 3536 * identifier ('.' identifier)* | 3518 * identifier ('.' identifier)* |
| 3537 */ | 3519 */ |
| 3538 LibraryIdentifier parseLibraryIdentifier() { | 3520 LibraryIdentifier parseLibraryIdentifier() { |
| 3539 List<SimpleIdentifier> components = <SimpleIdentifier>[]; | 3521 List<SimpleIdentifier> components = <SimpleIdentifier>[]; |
| 3540 components.add(parseSimpleIdentifier()); | 3522 components.add(parseSimpleIdentifier()); |
| 3541 while (_optional(TokenType.PERIOD)) { | 3523 while (_optional(TokenType.PERIOD)) { |
| 3542 components.add(parseSimpleIdentifier()); | 3524 components.add(parseSimpleIdentifier()); |
| 3543 } | 3525 } |
| 3544 return astFactory.libraryIdentifier(components); | 3526 return new LibraryIdentifier(components); |
| 3545 } | 3527 } |
| 3546 | 3528 |
| 3547 /** | 3529 /** |
| 3548 * Parse a list literal. The [modifier] is the 'const' modifier appearing | 3530 * Parse a list literal. The [modifier] is the 'const' modifier appearing |
| 3549 * before the literal, or `null` if there is no modifier. The [typeArguments] | 3531 * before the literal, or `null` if there is no modifier. The [typeArguments] |
| 3550 * is the type arguments appearing before the literal, or `null` if there are | 3532 * is the type arguments appearing before the literal, or `null` if there are |
| 3551 * no type arguments. Return the list literal that was parsed. | 3533 * no type arguments. Return the list literal that was parsed. |
| 3552 * | 3534 * |
| 3553 * This method assumes that the current token matches either | 3535 * This method assumes that the current token matches either |
| 3554 * `TokenType.OPEN_SQUARE_BRACKET` or `TokenType.INDEX`. | 3536 * `TokenType.OPEN_SQUARE_BRACKET` or `TokenType.INDEX`. |
| 3555 * | 3537 * |
| 3556 * listLiteral ::= | 3538 * listLiteral ::= |
| 3557 * 'const'? typeArguments? '[' (expressionList ','?)? ']' | 3539 * 'const'? typeArguments? '[' (expressionList ','?)? ']' |
| 3558 */ | 3540 */ |
| 3559 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) { | 3541 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) { |
| 3560 if (_matches(TokenType.INDEX)) { | 3542 if (_matches(TokenType.INDEX)) { |
| 3561 _splitIndex(); | 3543 _splitIndex(); |
| 3562 return astFactory.listLiteral( | 3544 return new ListLiteral( |
| 3563 modifier, typeArguments, getAndAdvance(), null, getAndAdvance()); | 3545 modifier, typeArguments, getAndAdvance(), null, getAndAdvance()); |
| 3564 } | 3546 } |
| 3565 Token leftBracket = getAndAdvance(); | 3547 Token leftBracket = getAndAdvance(); |
| 3566 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { | 3548 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { |
| 3567 return astFactory.listLiteral( | 3549 return new ListLiteral( |
| 3568 modifier, typeArguments, leftBracket, null, getAndAdvance()); | 3550 modifier, typeArguments, leftBracket, null, getAndAdvance()); |
| 3569 } | 3551 } |
| 3570 bool wasInInitializer = _inInitializer; | 3552 bool wasInInitializer = _inInitializer; |
| 3571 _inInitializer = false; | 3553 _inInitializer = false; |
| 3572 try { | 3554 try { |
| 3573 List<Expression> elements = <Expression>[parseExpression2()]; | 3555 List<Expression> elements = <Expression>[parseExpression2()]; |
| 3574 while (_optional(TokenType.COMMA)) { | 3556 while (_optional(TokenType.COMMA)) { |
| 3575 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { | 3557 if (_matches(TokenType.CLOSE_SQUARE_BRACKET)) { |
| 3576 return astFactory.listLiteral( | 3558 return new ListLiteral( |
| 3577 modifier, typeArguments, leftBracket, elements, getAndAdvance()); | 3559 modifier, typeArguments, leftBracket, elements, getAndAdvance()); |
| 3578 } | 3560 } |
| 3579 elements.add(parseExpression2()); | 3561 elements.add(parseExpression2()); |
| 3580 } | 3562 } |
| 3581 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); | 3563 Token rightBracket = _expect(TokenType.CLOSE_SQUARE_BRACKET); |
| 3582 return astFactory.listLiteral( | 3564 return new ListLiteral( |
| 3583 modifier, typeArguments, leftBracket, elements, rightBracket); | 3565 modifier, typeArguments, leftBracket, elements, rightBracket); |
| 3584 } finally { | 3566 } finally { |
| 3585 _inInitializer = wasInInitializer; | 3567 _inInitializer = wasInInitializer; |
| 3586 } | 3568 } |
| 3587 } | 3569 } |
| 3588 | 3570 |
| 3589 /** | 3571 /** |
| 3590 * Parse a list or map literal. The [modifier] is the 'const' modifier | 3572 * Parse a list or map literal. The [modifier] is the 'const' modifier |
| 3591 * appearing before the literal, or `null` if there is no modifier. Return the | 3573 * appearing before the literal, or `null` if there is no modifier. Return the |
| 3592 * list or map literal that was parsed. | 3574 * list or map literal that was parsed. |
| 3593 * | 3575 * |
| 3594 * listOrMapLiteral ::= | 3576 * listOrMapLiteral ::= |
| 3595 * listLiteral | 3577 * listLiteral |
| 3596 * | mapLiteral | 3578 * | mapLiteral |
| 3597 */ | 3579 */ |
| 3598 TypedLiteral parseListOrMapLiteral(Token modifier) { | 3580 TypedLiteral parseListOrMapLiteral(Token modifier) { |
| 3599 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); | 3581 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); |
| 3600 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { | 3582 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { |
| 3601 return parseMapLiteral(modifier, typeArguments); | 3583 return parseMapLiteral(modifier, typeArguments); |
| 3602 } else if (_matches(TokenType.OPEN_SQUARE_BRACKET) || | 3584 } else if (_matches(TokenType.OPEN_SQUARE_BRACKET) || |
| 3603 _matches(TokenType.INDEX)) { | 3585 _matches(TokenType.INDEX)) { |
| 3604 return parseListLiteral(modifier, typeArguments); | 3586 return parseListLiteral(modifier, typeArguments); |
| 3605 } | 3587 } |
| 3606 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL); | 3588 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL); |
| 3607 return astFactory.listLiteral( | 3589 return new ListLiteral( |
| 3608 modifier, | 3590 modifier, |
| 3609 typeArguments, | 3591 typeArguments, |
| 3610 _createSyntheticToken(TokenType.OPEN_SQUARE_BRACKET), | 3592 _createSyntheticToken(TokenType.OPEN_SQUARE_BRACKET), |
| 3611 null, | 3593 null, |
| 3612 _createSyntheticToken(TokenType.CLOSE_SQUARE_BRACKET)); | 3594 _createSyntheticToken(TokenType.CLOSE_SQUARE_BRACKET)); |
| 3613 } | 3595 } |
| 3614 | 3596 |
| 3615 /** | 3597 /** |
| 3616 * Parse a logical and expression. Return the logical and expression that was | 3598 * Parse a logical and expression. Return the logical and expression that was |
| 3617 * parsed. | 3599 * parsed. |
| 3618 * | 3600 * |
| 3619 * logicalAndExpression ::= | 3601 * logicalAndExpression ::= |
| 3620 * equalityExpression ('&&' equalityExpression)* | 3602 * equalityExpression ('&&' equalityExpression)* |
| 3621 */ | 3603 */ |
| 3622 Expression parseLogicalAndExpression() { | 3604 Expression parseLogicalAndExpression() { |
| 3623 Expression expression = parseEqualityExpression(); | 3605 Expression expression = parseEqualityExpression(); |
| 3624 while (_currentToken.type == TokenType.AMPERSAND_AMPERSAND) { | 3606 while (_currentToken.type == TokenType.AMPERSAND_AMPERSAND) { |
| 3625 expression = astFactory.binaryExpression( | 3607 expression = new BinaryExpression( |
| 3626 expression, getAndAdvance(), parseEqualityExpression()); | 3608 expression, getAndAdvance(), parseEqualityExpression()); |
| 3627 } | 3609 } |
| 3628 return expression; | 3610 return expression; |
| 3629 } | 3611 } |
| 3630 | 3612 |
| 3631 /** | 3613 /** |
| 3632 * Parse a logical or expression. Return the logical or expression that was | 3614 * Parse a logical or expression. Return the logical or expression that was |
| 3633 * parsed. | 3615 * parsed. |
| 3634 * | 3616 * |
| 3635 * logicalOrExpression ::= | 3617 * logicalOrExpression ::= |
| 3636 * logicalAndExpression ('||' logicalAndExpression)* | 3618 * logicalAndExpression ('||' logicalAndExpression)* |
| 3637 */ | 3619 */ |
| 3638 Expression parseLogicalOrExpression() { | 3620 Expression parseLogicalOrExpression() { |
| 3639 Expression expression = parseLogicalAndExpression(); | 3621 Expression expression = parseLogicalAndExpression(); |
| 3640 while (_currentToken.type == TokenType.BAR_BAR) { | 3622 while (_currentToken.type == TokenType.BAR_BAR) { |
| 3641 expression = astFactory.binaryExpression( | 3623 expression = new BinaryExpression( |
| 3642 expression, getAndAdvance(), parseLogicalAndExpression()); | 3624 expression, getAndAdvance(), parseLogicalAndExpression()); |
| 3643 } | 3625 } |
| 3644 return expression; | 3626 return expression; |
| 3645 } | 3627 } |
| 3646 | 3628 |
| 3647 /** | 3629 /** |
| 3648 * Parse a map literal. The [modifier] is the 'const' modifier appearing | 3630 * Parse a map literal. The [modifier] is the 'const' modifier appearing |
| 3649 * before the literal, or `null` if there is no modifier. The [typeArguments] | 3631 * before the literal, or `null` if there is no modifier. The [typeArguments] |
| 3650 * is the type arguments that were declared, or `null` if there are no type | 3632 * is the type arguments that were declared, or `null` if there are no type |
| 3651 * arguments. Return the map literal that was parsed. | 3633 * arguments. Return the map literal that was parsed. |
| 3652 * | 3634 * |
| 3653 * This method assumes that the current token matches | 3635 * This method assumes that the current token matches |
| 3654 * `TokenType.OPEN_CURLY_BRACKET`. | 3636 * `TokenType.OPEN_CURLY_BRACKET`. |
| 3655 * | 3637 * |
| 3656 * mapLiteral ::= | 3638 * mapLiteral ::= |
| 3657 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)*
','?)? '}' | 3639 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)*
','?)? '}' |
| 3658 */ | 3640 */ |
| 3659 MapLiteral parseMapLiteral(Token modifier, TypeArgumentList typeArguments) { | 3641 MapLiteral parseMapLiteral(Token modifier, TypeArgumentList typeArguments) { |
| 3660 Token leftBracket = getAndAdvance(); | 3642 Token leftBracket = getAndAdvance(); |
| 3661 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { | 3643 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { |
| 3662 return astFactory.mapLiteral( | 3644 return new MapLiteral( |
| 3663 modifier, typeArguments, leftBracket, null, getAndAdvance()); | 3645 modifier, typeArguments, leftBracket, null, getAndAdvance()); |
| 3664 } | 3646 } |
| 3665 bool wasInInitializer = _inInitializer; | 3647 bool wasInInitializer = _inInitializer; |
| 3666 _inInitializer = false; | 3648 _inInitializer = false; |
| 3667 try { | 3649 try { |
| 3668 List<MapLiteralEntry> entries = <MapLiteralEntry>[parseMapLiteralEntry()]; | 3650 List<MapLiteralEntry> entries = <MapLiteralEntry>[parseMapLiteralEntry()]; |
| 3669 while (_optional(TokenType.COMMA)) { | 3651 while (_optional(TokenType.COMMA)) { |
| 3670 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { | 3652 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { |
| 3671 return astFactory.mapLiteral( | 3653 return new MapLiteral( |
| 3672 modifier, typeArguments, leftBracket, entries, getAndAdvance()); | 3654 modifier, typeArguments, leftBracket, entries, getAndAdvance()); |
| 3673 } | 3655 } |
| 3674 entries.add(parseMapLiteralEntry()); | 3656 entries.add(parseMapLiteralEntry()); |
| 3675 } | 3657 } |
| 3676 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); | 3658 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); |
| 3677 return astFactory.mapLiteral( | 3659 return new MapLiteral( |
| 3678 modifier, typeArguments, leftBracket, entries, rightBracket); | 3660 modifier, typeArguments, leftBracket, entries, rightBracket); |
| 3679 } finally { | 3661 } finally { |
| 3680 _inInitializer = wasInInitializer; | 3662 _inInitializer = wasInInitializer; |
| 3681 } | 3663 } |
| 3682 } | 3664 } |
| 3683 | 3665 |
| 3684 /** | 3666 /** |
| 3685 * Parse a map literal entry. Return the map literal entry that was parsed. | 3667 * Parse a map literal entry. Return the map literal entry that was parsed. |
| 3686 * | 3668 * |
| 3687 * mapLiteralEntry ::= | 3669 * mapLiteralEntry ::= |
| 3688 * expression ':' expression | 3670 * expression ':' expression |
| 3689 */ | 3671 */ |
| 3690 MapLiteralEntry parseMapLiteralEntry() { | 3672 MapLiteralEntry parseMapLiteralEntry() { |
| 3691 Expression key = parseExpression2(); | 3673 Expression key = parseExpression2(); |
| 3692 Token separator = _expect(TokenType.COLON); | 3674 Token separator = _expect(TokenType.COLON); |
| 3693 Expression value = parseExpression2(); | 3675 Expression value = parseExpression2(); |
| 3694 return astFactory.mapLiteralEntry(key, separator, value); | 3676 return new MapLiteralEntry(key, separator, value); |
| 3695 } | 3677 } |
| 3696 | 3678 |
| 3697 /** | 3679 /** |
| 3698 * Parse the modifiers preceding a declaration. This method allows the | 3680 * Parse the modifiers preceding a declaration. This method allows the |
| 3699 * modifiers to appear in any order but does generate errors for duplicated | 3681 * modifiers to appear in any order but does generate errors for duplicated |
| 3700 * modifiers. Checks for other problems, such as having the modifiers appear | 3682 * modifiers. Checks for other problems, such as having the modifiers appear |
| 3701 * in the wrong order or specifying both 'const' and 'final', are reported in | 3683 * in the wrong order or specifying both 'const' and 'final', are reported in |
| 3702 * one of the methods whose name is prefixed with `validateModifiersFor`. | 3684 * one of the methods whose name is prefixed with `validateModifiersFor`. |
| 3703 * Return the modifiers that were parsed. | 3685 * Return the modifiers that were parsed. |
| 3704 * | 3686 * |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3784 * that was parsed. | 3766 * that was parsed. |
| 3785 * | 3767 * |
| 3786 * multiplicativeExpression ::= | 3768 * multiplicativeExpression ::= |
| 3787 * unaryExpression (multiplicativeOperator unaryExpression)* | 3769 * unaryExpression (multiplicativeOperator unaryExpression)* |
| 3788 * | 'super' (multiplicativeOperator unaryExpression)+ | 3770 * | 'super' (multiplicativeOperator unaryExpression)+ |
| 3789 */ | 3771 */ |
| 3790 Expression parseMultiplicativeExpression() { | 3772 Expression parseMultiplicativeExpression() { |
| 3791 Expression expression; | 3773 Expression expression; |
| 3792 if (_currentToken.keyword == Keyword.SUPER && | 3774 if (_currentToken.keyword == Keyword.SUPER && |
| 3793 _currentToken.next.type.isMultiplicativeOperator) { | 3775 _currentToken.next.type.isMultiplicativeOperator) { |
| 3794 expression = astFactory.superExpression(getAndAdvance()); | 3776 expression = new SuperExpression(getAndAdvance()); |
| 3795 } else { | 3777 } else { |
| 3796 expression = parseUnaryExpression(); | 3778 expression = parseUnaryExpression(); |
| 3797 } | 3779 } |
| 3798 while (_currentToken.type.isMultiplicativeOperator) { | 3780 while (_currentToken.type.isMultiplicativeOperator) { |
| 3799 expression = astFactory.binaryExpression( | 3781 expression = new BinaryExpression( |
| 3800 expression, getAndAdvance(), parseUnaryExpression()); | 3782 expression, getAndAdvance(), parseUnaryExpression()); |
| 3801 } | 3783 } |
| 3802 return expression; | 3784 return expression; |
| 3803 } | 3785 } |
| 3804 | 3786 |
| 3805 /** | 3787 /** |
| 3806 * Parse a new expression. Return the new expression that was parsed. | 3788 * Parse a new expression. Return the new expression that was parsed. |
| 3807 * | 3789 * |
| 3808 * This method assumes that the current token matches `Keyword.NEW`. | 3790 * This method assumes that the current token matches `Keyword.NEW`. |
| 3809 * | 3791 * |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3834 * | functionSignature functionBody | 3816 * | functionSignature functionBody |
| 3835 */ | 3817 */ |
| 3836 Statement parseNonLabeledStatement() { | 3818 Statement parseNonLabeledStatement() { |
| 3837 // TODO(brianwilkerson) Pass the comment and metadata on where appropriate. | 3819 // TODO(brianwilkerson) Pass the comment and metadata on where appropriate. |
| 3838 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); | 3820 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); |
| 3839 TokenType type = _currentToken.type; | 3821 TokenType type = _currentToken.type; |
| 3840 if (type == TokenType.OPEN_CURLY_BRACKET) { | 3822 if (type == TokenType.OPEN_CURLY_BRACKET) { |
| 3841 if (_tokenMatches(_peek(), TokenType.STRING)) { | 3823 if (_tokenMatches(_peek(), TokenType.STRING)) { |
| 3842 Token afterString = skipStringLiteral(_currentToken.next); | 3824 Token afterString = skipStringLiteral(_currentToken.next); |
| 3843 if (afterString != null && afterString.type == TokenType.COLON) { | 3825 if (afterString != null && afterString.type == TokenType.COLON) { |
| 3844 return astFactory.expressionStatement( | 3826 return new ExpressionStatement( |
| 3845 parseExpression2(), _expect(TokenType.SEMICOLON)); | 3827 parseExpression2(), _expect(TokenType.SEMICOLON)); |
| 3846 } | 3828 } |
| 3847 } | 3829 } |
| 3848 return parseBlock(); | 3830 return parseBlock(); |
| 3849 } else if (type == TokenType.KEYWORD && | 3831 } else if (type == TokenType.KEYWORD && |
| 3850 !_currentToken.keyword.isPseudoKeyword) { | 3832 !_currentToken.keyword.isPseudoKeyword) { |
| 3851 Keyword keyword = _currentToken.keyword; | 3833 Keyword keyword = _currentToken.keyword; |
| 3852 // TODO(jwren) compute some metrics to figure out a better order for this | 3834 // TODO(jwren) compute some metrics to figure out a better order for this |
| 3853 // if-then sequence to optimize performance | 3835 // if-then sequence to optimize performance |
| 3854 if (keyword == Keyword.ASSERT) { | 3836 if (keyword == Keyword.ASSERT) { |
| 3855 return parseAssertStatement(); | 3837 return parseAssertStatement(); |
| 3856 } else if (keyword == Keyword.BREAK) { | 3838 } else if (keyword == Keyword.BREAK) { |
| 3857 return parseBreakStatement(); | 3839 return parseBreakStatement(); |
| 3858 } else if (keyword == Keyword.CONTINUE) { | 3840 } else if (keyword == Keyword.CONTINUE) { |
| 3859 return parseContinueStatement(); | 3841 return parseContinueStatement(); |
| 3860 } else if (keyword == Keyword.DO) { | 3842 } else if (keyword == Keyword.DO) { |
| 3861 return parseDoStatement(); | 3843 return parseDoStatement(); |
| 3862 } else if (keyword == Keyword.FOR) { | 3844 } else if (keyword == Keyword.FOR) { |
| 3863 return parseForStatement(); | 3845 return parseForStatement(); |
| 3864 } else if (keyword == Keyword.IF) { | 3846 } else if (keyword == Keyword.IF) { |
| 3865 return parseIfStatement(); | 3847 return parseIfStatement(); |
| 3866 } else if (keyword == Keyword.RETHROW) { | 3848 } else if (keyword == Keyword.RETHROW) { |
| 3867 return astFactory.expressionStatement( | 3849 return new ExpressionStatement( |
| 3868 parseRethrowExpression(), _expect(TokenType.SEMICOLON)); | 3850 parseRethrowExpression(), _expect(TokenType.SEMICOLON)); |
| 3869 } else if (keyword == Keyword.RETURN) { | 3851 } else if (keyword == Keyword.RETURN) { |
| 3870 return parseReturnStatement(); | 3852 return parseReturnStatement(); |
| 3871 } else if (keyword == Keyword.SWITCH) { | 3853 } else if (keyword == Keyword.SWITCH) { |
| 3872 return parseSwitchStatement(); | 3854 return parseSwitchStatement(); |
| 3873 } else if (keyword == Keyword.THROW) { | 3855 } else if (keyword == Keyword.THROW) { |
| 3874 return astFactory.expressionStatement( | 3856 return new ExpressionStatement( |
| 3875 parseThrowExpression(), _expect(TokenType.SEMICOLON)); | 3857 parseThrowExpression(), _expect(TokenType.SEMICOLON)); |
| 3876 } else if (keyword == Keyword.TRY) { | 3858 } else if (keyword == Keyword.TRY) { |
| 3877 return parseTryStatement(); | 3859 return parseTryStatement(); |
| 3878 } else if (keyword == Keyword.WHILE) { | 3860 } else if (keyword == Keyword.WHILE) { |
| 3879 return parseWhileStatement(); | 3861 return parseWhileStatement(); |
| 3880 } else if (keyword == Keyword.VAR || keyword == Keyword.FINAL) { | 3862 } else if (keyword == Keyword.VAR || keyword == Keyword.FINAL) { |
| 3881 return parseVariableDeclarationStatementAfterMetadata( | 3863 return parseVariableDeclarationStatementAfterMetadata( |
| 3882 commentAndMetadata); | 3864 commentAndMetadata); |
| 3883 } else if (keyword == Keyword.VOID) { | 3865 } else if (keyword == Keyword.VOID) { |
| 3884 TypeName returnType = astFactory.typeName( | 3866 TypeName returnType = |
| 3885 astFactory.simpleIdentifier(getAndAdvance()), null); | 3867 new TypeName(new SimpleIdentifier(getAndAdvance()), null); |
| 3886 Token next = _currentToken.next; | 3868 Token next = _currentToken.next; |
| 3887 if (_matchesIdentifier() && | 3869 if (_matchesIdentifier() && |
| 3888 next.matchesAny(const <TokenType>[ | 3870 next.matchesAny(const <TokenType>[ |
| 3889 TokenType.OPEN_PAREN, | 3871 TokenType.OPEN_PAREN, |
| 3890 TokenType.OPEN_CURLY_BRACKET, | 3872 TokenType.OPEN_CURLY_BRACKET, |
| 3891 TokenType.FUNCTION, | 3873 TokenType.FUNCTION, |
| 3892 TokenType.LT | 3874 TokenType.LT |
| 3893 ])) { | 3875 ])) { |
| 3894 return _parseFunctionDeclarationStatementAfterReturnType( | 3876 return _parseFunctionDeclarationStatementAfterReturnType( |
| 3895 commentAndMetadata, returnType); | 3877 commentAndMetadata, returnType); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3913 } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { | 3895 } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { |
| 3914 // | 3896 // |
| 3915 // We appear to have found an incomplete statement at the end of a | 3897 // We appear to have found an incomplete statement at the end of a |
| 3916 // block. Parse it as a variable declaration. | 3898 // block. Parse it as a variable declaration. |
| 3917 // | 3899 // |
| 3918 return _parseVariableDeclarationStatementAfterType( | 3900 return _parseVariableDeclarationStatementAfterType( |
| 3919 commentAndMetadata, null, returnType); | 3901 commentAndMetadata, null, returnType); |
| 3920 } | 3902 } |
| 3921 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT); | 3903 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT); |
| 3922 // TODO(brianwilkerson) Recover from this error. | 3904 // TODO(brianwilkerson) Recover from this error. |
| 3923 return astFactory | 3905 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); |
| 3924 .emptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); | |
| 3925 } | 3906 } |
| 3926 } else if (keyword == Keyword.CONST) { | 3907 } else if (keyword == Keyword.CONST) { |
| 3927 Token next = _currentToken.next; | 3908 Token next = _currentToken.next; |
| 3928 if (next.matchesAny(const <TokenType>[ | 3909 if (next.matchesAny(const <TokenType>[ |
| 3929 TokenType.LT, | 3910 TokenType.LT, |
| 3930 TokenType.OPEN_CURLY_BRACKET, | 3911 TokenType.OPEN_CURLY_BRACKET, |
| 3931 TokenType.OPEN_SQUARE_BRACKET, | 3912 TokenType.OPEN_SQUARE_BRACKET, |
| 3932 TokenType.INDEX | 3913 TokenType.INDEX |
| 3933 ])) { | 3914 ])) { |
| 3934 return astFactory.expressionStatement( | 3915 return new ExpressionStatement( |
| 3935 parseExpression2(), _expect(TokenType.SEMICOLON)); | 3916 parseExpression2(), _expect(TokenType.SEMICOLON)); |
| 3936 } else if (_tokenMatches(next, TokenType.IDENTIFIER)) { | 3917 } else if (_tokenMatches(next, TokenType.IDENTIFIER)) { |
| 3937 Token afterType = skipTypeName(next); | 3918 Token afterType = skipTypeName(next); |
| 3938 if (afterType != null) { | 3919 if (afterType != null) { |
| 3939 if (_tokenMatches(afterType, TokenType.OPEN_PAREN) || | 3920 if (_tokenMatches(afterType, TokenType.OPEN_PAREN) || |
| 3940 (_tokenMatches(afterType, TokenType.PERIOD) && | 3921 (_tokenMatches(afterType, TokenType.PERIOD) && |
| 3941 _tokenMatches(afterType.next, TokenType.IDENTIFIER) && | 3922 _tokenMatches(afterType.next, TokenType.IDENTIFIER) && |
| 3942 _tokenMatches(afterType.next.next, TokenType.OPEN_PAREN))) { | 3923 _tokenMatches(afterType.next.next, TokenType.OPEN_PAREN))) { |
| 3943 return astFactory.expressionStatement( | 3924 return new ExpressionStatement( |
| 3944 parseExpression2(), _expect(TokenType.SEMICOLON)); | 3925 parseExpression2(), _expect(TokenType.SEMICOLON)); |
| 3945 } | 3926 } |
| 3946 } | 3927 } |
| 3947 } | 3928 } |
| 3948 return parseVariableDeclarationStatementAfterMetadata( | 3929 return parseVariableDeclarationStatementAfterMetadata( |
| 3949 commentAndMetadata); | 3930 commentAndMetadata); |
| 3950 } else if (keyword == Keyword.NEW || | 3931 } else if (keyword == Keyword.NEW || |
| 3951 keyword == Keyword.TRUE || | 3932 keyword == Keyword.TRUE || |
| 3952 keyword == Keyword.FALSE || | 3933 keyword == Keyword.FALSE || |
| 3953 keyword == Keyword.NULL || | 3934 keyword == Keyword.NULL || |
| 3954 keyword == Keyword.SUPER || | 3935 keyword == Keyword.SUPER || |
| 3955 keyword == Keyword.THIS) { | 3936 keyword == Keyword.THIS) { |
| 3956 return astFactory.expressionStatement( | 3937 return new ExpressionStatement( |
| 3957 parseExpression2(), _expect(TokenType.SEMICOLON)); | 3938 parseExpression2(), _expect(TokenType.SEMICOLON)); |
| 3958 } else { | 3939 } else { |
| 3959 // | 3940 // |
| 3960 // We have found an error of some kind. Try to recover. | 3941 // We have found an error of some kind. Try to recover. |
| 3961 // | 3942 // |
| 3962 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT); | 3943 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT); |
| 3963 return astFactory | 3944 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); |
| 3964 .emptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); | |
| 3965 } | 3945 } |
| 3966 } else if (_inGenerator && _matchesString(_YIELD)) { | 3946 } else if (_inGenerator && _matchesString(_YIELD)) { |
| 3967 return parseYieldStatement(); | 3947 return parseYieldStatement(); |
| 3968 } else if (_inAsync && _matchesString(_AWAIT)) { | 3948 } else if (_inAsync && _matchesString(_AWAIT)) { |
| 3969 if (_tokenMatchesKeyword(_peek(), Keyword.FOR)) { | 3949 if (_tokenMatchesKeyword(_peek(), Keyword.FOR)) { |
| 3970 return parseForStatement(); | 3950 return parseForStatement(); |
| 3971 } | 3951 } |
| 3972 return astFactory.expressionStatement( | 3952 return new ExpressionStatement( |
| 3973 parseExpression2(), _expect(TokenType.SEMICOLON)); | 3953 parseExpression2(), _expect(TokenType.SEMICOLON)); |
| 3974 } else if (_matchesString(_AWAIT) && | 3954 } else if (_matchesString(_AWAIT) && |
| 3975 _tokenMatchesKeyword(_peek(), Keyword.FOR)) { | 3955 _tokenMatchesKeyword(_peek(), Keyword.FOR)) { |
| 3976 Token awaitToken = _currentToken; | 3956 Token awaitToken = _currentToken; |
| 3977 Statement statement = parseForStatement(); | 3957 Statement statement = parseForStatement(); |
| 3978 if (statement is! ForStatement) { | 3958 if (statement is! ForStatement) { |
| 3979 _reportErrorForToken( | 3959 _reportErrorForToken( |
| 3980 CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT, awaitToken); | 3960 CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT, awaitToken); |
| 3981 } | 3961 } |
| 3982 return statement; | 3962 return statement; |
| 3983 } else if (type == TokenType.SEMICOLON) { | 3963 } else if (type == TokenType.SEMICOLON) { |
| 3984 return parseEmptyStatement(); | 3964 return parseEmptyStatement(); |
| 3985 } else if (isInitializedVariableDeclaration()) { | 3965 } else if (isInitializedVariableDeclaration()) { |
| 3986 return parseVariableDeclarationStatementAfterMetadata(commentAndMetadata); | 3966 return parseVariableDeclarationStatementAfterMetadata(commentAndMetadata); |
| 3987 } else if (isFunctionDeclaration()) { | 3967 } else if (isFunctionDeclaration()) { |
| 3988 return parseFunctionDeclarationStatement(); | 3968 return parseFunctionDeclarationStatement(); |
| 3989 } else if (type == TokenType.CLOSE_CURLY_BRACKET) { | 3969 } else if (type == TokenType.CLOSE_CURLY_BRACKET) { |
| 3990 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT); | 3970 _reportErrorForCurrentToken(ParserErrorCode.MISSING_STATEMENT); |
| 3991 return astFactory | 3971 return new EmptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); |
| 3992 .emptyStatement(_createSyntheticToken(TokenType.SEMICOLON)); | |
| 3993 } else { | 3972 } else { |
| 3994 return astFactory.expressionStatement( | 3973 return new ExpressionStatement( |
| 3995 parseExpression2(), _expect(TokenType.SEMICOLON)); | 3974 parseExpression2(), _expect(TokenType.SEMICOLON)); |
| 3996 } | 3975 } |
| 3997 } | 3976 } |
| 3998 | 3977 |
| 3999 /** | 3978 /** |
| 4000 * Parse a normal formal parameter. Return the normal formal parameter that | 3979 * Parse a normal formal parameter. Return the normal formal parameter that |
| 4001 * was parsed. | 3980 * was parsed. |
| 4002 * | 3981 * |
| 4003 * normalFormalParameter ::= | 3982 * normalFormalParameter ::= |
| 4004 * functionSignature | 3983 * functionSignature |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4030 FormalParameterList parameters = _parseFormalParameterListUnchecked(); | 4009 FormalParameterList parameters = _parseFormalParameterListUnchecked(); |
| 4031 if (thisKeyword == null) { | 4010 if (thisKeyword == null) { |
| 4032 if (holder.keyword != null) { | 4011 if (holder.keyword != null) { |
| 4033 _reportErrorForToken( | 4012 _reportErrorForToken( |
| 4034 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword); | 4013 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword); |
| 4035 } | 4014 } |
| 4036 Token question = null; | 4015 Token question = null; |
| 4037 if (enableNnbd && _matches(TokenType.QUESTION)) { | 4016 if (enableNnbd && _matches(TokenType.QUESTION)) { |
| 4038 question = getAndAdvance(); | 4017 question = getAndAdvance(); |
| 4039 } | 4018 } |
| 4040 return astFactory.functionTypedFormalParameter( | 4019 return new FunctionTypedFormalParameter( |
| 4041 commentAndMetadata.comment, | 4020 commentAndMetadata.comment, |
| 4042 commentAndMetadata.metadata, | 4021 commentAndMetadata.metadata, |
| 4043 holder.type, | 4022 holder.type, |
| 4044 astFactory.simpleIdentifier(identifier.token, isDeclaration: true), | 4023 new SimpleIdentifier(identifier.token, isDeclaration: true), |
| 4045 typeParameters, | 4024 typeParameters, |
| 4046 parameters, | 4025 parameters, |
| 4047 question: question); | 4026 question: question); |
| 4048 } else { | 4027 } else { |
| 4049 return astFactory.fieldFormalParameter( | 4028 return new FieldFormalParameter( |
| 4050 commentAndMetadata.comment, | 4029 commentAndMetadata.comment, |
| 4051 commentAndMetadata.metadata, | 4030 commentAndMetadata.metadata, |
| 4052 holder.keyword, | 4031 holder.keyword, |
| 4053 holder.type, | 4032 holder.type, |
| 4054 thisKeyword, | 4033 thisKeyword, |
| 4055 period, | 4034 period, |
| 4056 identifier, | 4035 identifier, |
| 4057 typeParameters, | 4036 typeParameters, |
| 4058 parameters); | 4037 parameters); |
| 4059 } | 4038 } |
| 4060 } else if (typeParameters != null) { | 4039 } else if (typeParameters != null) { |
| 4061 // TODO(brianwilkerson) Report an error. It looks like a function-typed | 4040 // TODO(brianwilkerson) Report an error. It looks like a function-typed |
| 4062 // parameter with no parameter list. | 4041 // parameter with no parameter list. |
| 4063 //_reportErrorForToken(ParserErrorCode.MISSING_PARAMETERS, typeParameters.
endToken); | 4042 //_reportErrorForToken(ParserErrorCode.MISSING_PARAMETERS, typeParameters.
endToken); |
| 4064 } | 4043 } |
| 4065 TypeName type = holder.type; | 4044 TypeName type = holder.type; |
| 4066 if (type != null) { | 4045 if (type != null) { |
| 4067 if (_tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) { | 4046 if (_tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) { |
| 4068 _reportErrorForToken( | 4047 _reportErrorForToken( |
| 4069 ParserErrorCode.VOID_PARAMETER, type.name.beginToken); | 4048 ParserErrorCode.VOID_PARAMETER, type.name.beginToken); |
| 4070 } else if (holder.keyword != null && | 4049 } else if (holder.keyword != null && |
| 4071 _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) { | 4050 _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) { |
| 4072 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword); | 4051 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword); |
| 4073 } | 4052 } |
| 4074 } | 4053 } |
| 4075 if (thisKeyword != null) { | 4054 if (thisKeyword != null) { |
| 4076 // TODO(brianwilkerson) If there are type parameters but no parameters, | 4055 // TODO(brianwilkerson) If there are type parameters but no parameters, |
| 4077 // should we create a synthetic empty parameter list here so we can | 4056 // should we create a synthetic empty parameter list here so we can |
| 4078 // capture the type parameters? | 4057 // capture the type parameters? |
| 4079 return astFactory.fieldFormalParameter( | 4058 return new FieldFormalParameter( |
| 4080 commentAndMetadata.comment, | 4059 commentAndMetadata.comment, |
| 4081 commentAndMetadata.metadata, | 4060 commentAndMetadata.metadata, |
| 4082 holder.keyword, | 4061 holder.keyword, |
| 4083 holder.type, | 4062 holder.type, |
| 4084 thisKeyword, | 4063 thisKeyword, |
| 4085 period, | 4064 period, |
| 4086 identifier, | 4065 identifier, |
| 4087 null, | 4066 null, |
| 4088 null); | 4067 null); |
| 4089 } | 4068 } |
| 4090 return astFactory.simpleFormalParameter( | 4069 return new SimpleFormalParameter( |
| 4091 commentAndMetadata.comment, | 4070 commentAndMetadata.comment, |
| 4092 commentAndMetadata.metadata, | 4071 commentAndMetadata.metadata, |
| 4093 holder.keyword, | 4072 holder.keyword, |
| 4094 holder.type, | 4073 holder.type, |
| 4095 astFactory.simpleIdentifier(identifier.token, isDeclaration: true)); | 4074 new SimpleIdentifier(identifier.token, isDeclaration: true)); |
| 4096 } | 4075 } |
| 4097 | 4076 |
| 4098 /** | 4077 /** |
| 4099 * Parse an operator declaration. The [commentAndMetadata] is the | 4078 * Parse an operator declaration. The [commentAndMetadata] is the |
| 4100 * documentation comment and metadata to be associated with the declaration. | 4079 * documentation comment and metadata to be associated with the declaration. |
| 4101 * The [externalKeyword] is the 'external' token. The [returnType] is the | 4080 * The [externalKeyword] is the 'external' token. The [returnType] is the |
| 4102 * return type that has already been parsed, or `null` if there was no return | 4081 * return type that has already been parsed, or `null` if there was no return |
| 4103 * type. Return the operator declaration that was parsed. | 4082 * type. Return the operator declaration that was parsed. |
| 4104 * | 4083 * |
| 4105 * operatorDeclaration ::= | 4084 * operatorDeclaration ::= |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4161 type == TokenType.QUESTION_PERIOD || | 4140 type == TokenType.QUESTION_PERIOD || |
| 4162 type == TokenType.OPEN_PAREN || | 4141 type == TokenType.OPEN_PAREN || |
| 4163 type == TokenType.LT || | 4142 type == TokenType.LT || |
| 4164 type == TokenType.INDEX) { | 4143 type == TokenType.INDEX) { |
| 4165 do { | 4144 do { |
| 4166 if (_isLikelyArgumentList()) { | 4145 if (_isLikelyArgumentList()) { |
| 4167 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); | 4146 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); |
| 4168 ArgumentList argumentList = parseArgumentList(); | 4147 ArgumentList argumentList = parseArgumentList(); |
| 4169 Expression currentOperand = operand; | 4148 Expression currentOperand = operand; |
| 4170 if (currentOperand is PropertyAccess) { | 4149 if (currentOperand is PropertyAccess) { |
| 4171 operand = astFactory.methodInvocation( | 4150 operand = new MethodInvocation( |
| 4172 currentOperand.target, | 4151 currentOperand.target, |
| 4173 currentOperand.operator, | 4152 currentOperand.operator, |
| 4174 currentOperand.propertyName, | 4153 currentOperand.propertyName, |
| 4175 typeArguments, | 4154 typeArguments, |
| 4176 argumentList); | 4155 argumentList); |
| 4177 } else { | 4156 } else { |
| 4178 operand = astFactory.functionExpressionInvocation( | 4157 operand = new FunctionExpressionInvocation( |
| 4179 operand, typeArguments, argumentList); | 4158 operand, typeArguments, argumentList); |
| 4180 } | 4159 } |
| 4181 } else { | 4160 } else { |
| 4182 operand = parseAssignableSelector(operand, true); | 4161 operand = parseAssignableSelector(operand, true); |
| 4183 } | 4162 } |
| 4184 type = _currentToken.type; | 4163 type = _currentToken.type; |
| 4185 } while (type == TokenType.OPEN_SQUARE_BRACKET || | 4164 } while (type == TokenType.OPEN_SQUARE_BRACKET || |
| 4186 type == TokenType.PERIOD || | 4165 type == TokenType.PERIOD || |
| 4187 type == TokenType.QUESTION_PERIOD || | 4166 type == TokenType.QUESTION_PERIOD || |
| 4188 type == TokenType.OPEN_PAREN || | 4167 type == TokenType.OPEN_PAREN || |
| 4189 type == TokenType.INDEX); | 4168 type == TokenType.INDEX); |
| 4190 return operand; | 4169 return operand; |
| 4191 } | 4170 } |
| 4192 if (!_currentToken.type.isIncrementOperator) { | 4171 if (!_currentToken.type.isIncrementOperator) { |
| 4193 return operand; | 4172 return operand; |
| 4194 } | 4173 } |
| 4195 _ensureAssignable(operand); | 4174 _ensureAssignable(operand); |
| 4196 Token operator = getAndAdvance(); | 4175 Token operator = getAndAdvance(); |
| 4197 return astFactory.postfixExpression(operand, operator); | 4176 return new PostfixExpression(operand, operator); |
| 4198 } | 4177 } |
| 4199 | 4178 |
| 4200 /** | 4179 /** |
| 4201 * Parse a prefixed identifier. Return the prefixed identifier that was | 4180 * Parse a prefixed identifier. Return the prefixed identifier that was |
| 4202 * parsed. | 4181 * parsed. |
| 4203 * | 4182 * |
| 4204 * prefixedIdentifier ::= | 4183 * prefixedIdentifier ::= |
| 4205 * identifier ('.' identifier)? | 4184 * identifier ('.' identifier)? |
| 4206 */ | 4185 */ |
| 4207 Identifier parsePrefixedIdentifier() { | 4186 Identifier parsePrefixedIdentifier() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4250 if (type == TokenType.STRING) { | 4229 if (type == TokenType.STRING) { |
| 4251 return parseStringLiteral(); | 4230 return parseStringLiteral(); |
| 4252 } else if (type == TokenType.INT) { | 4231 } else if (type == TokenType.INT) { |
| 4253 Token token = getAndAdvance(); | 4232 Token token = getAndAdvance(); |
| 4254 int value = null; | 4233 int value = null; |
| 4255 try { | 4234 try { |
| 4256 value = int.parse(token.lexeme); | 4235 value = int.parse(token.lexeme); |
| 4257 } on FormatException { | 4236 } on FormatException { |
| 4258 // The invalid format should have been reported by the scanner. | 4237 // The invalid format should have been reported by the scanner. |
| 4259 } | 4238 } |
| 4260 return astFactory.integerLiteral(token, value); | 4239 return new IntegerLiteral(token, value); |
| 4261 } | 4240 } |
| 4262 Keyword keyword = _currentToken.keyword; | 4241 Keyword keyword = _currentToken.keyword; |
| 4263 if (keyword == Keyword.NULL) { | 4242 if (keyword == Keyword.NULL) { |
| 4264 return astFactory.nullLiteral(getAndAdvance()); | 4243 return new NullLiteral(getAndAdvance()); |
| 4265 } else if (keyword == Keyword.NEW) { | 4244 } else if (keyword == Keyword.NEW) { |
| 4266 return parseNewExpression(); | 4245 return parseNewExpression(); |
| 4267 } else if (keyword == Keyword.THIS) { | 4246 } else if (keyword == Keyword.THIS) { |
| 4268 return astFactory.thisExpression(getAndAdvance()); | 4247 return new ThisExpression(getAndAdvance()); |
| 4269 } else if (keyword == Keyword.SUPER) { | 4248 } else if (keyword == Keyword.SUPER) { |
| 4270 // TODO(paulberry): verify with Gilad that "super" must be followed by | 4249 // TODO(paulberry): verify with Gilad that "super" must be followed by |
| 4271 // unconditionalAssignableSelector in this case. | 4250 // unconditionalAssignableSelector in this case. |
| 4272 return parseAssignableSelector( | 4251 return parseAssignableSelector( |
| 4273 astFactory.superExpression(getAndAdvance()), false, | 4252 new SuperExpression(getAndAdvance()), false, |
| 4274 allowConditional: false); | 4253 allowConditional: false); |
| 4275 } else if (keyword == Keyword.FALSE) { | 4254 } else if (keyword == Keyword.FALSE) { |
| 4276 return astFactory.booleanLiteral(getAndAdvance(), false); | 4255 return new BooleanLiteral(getAndAdvance(), false); |
| 4277 } else if (keyword == Keyword.TRUE) { | 4256 } else if (keyword == Keyword.TRUE) { |
| 4278 return astFactory.booleanLiteral(getAndAdvance(), true); | 4257 return new BooleanLiteral(getAndAdvance(), true); |
| 4279 } | 4258 } |
| 4280 if (type == TokenType.DOUBLE) { | 4259 if (type == TokenType.DOUBLE) { |
| 4281 Token token = getAndAdvance(); | 4260 Token token = getAndAdvance(); |
| 4282 double value = 0.0; | 4261 double value = 0.0; |
| 4283 try { | 4262 try { |
| 4284 value = double.parse(token.lexeme); | 4263 value = double.parse(token.lexeme); |
| 4285 } on FormatException { | 4264 } on FormatException { |
| 4286 // The invalid format should have been reported by the scanner. | 4265 // The invalid format should have been reported by the scanner. |
| 4287 } | 4266 } |
| 4288 return astFactory.doubleLiteral(token, value); | 4267 return new DoubleLiteral(token, value); |
| 4289 } else if (type == TokenType.HEXADECIMAL) { | 4268 } else if (type == TokenType.HEXADECIMAL) { |
| 4290 Token token = getAndAdvance(); | 4269 Token token = getAndAdvance(); |
| 4291 int value = null; | 4270 int value = null; |
| 4292 try { | 4271 try { |
| 4293 value = int.parse(token.lexeme.substring(2), radix: 16); | 4272 value = int.parse(token.lexeme.substring(2), radix: 16); |
| 4294 } on FormatException { | 4273 } on FormatException { |
| 4295 // The invalid format should have been reported by the scanner. | 4274 // The invalid format should have been reported by the scanner. |
| 4296 } | 4275 } |
| 4297 return astFactory.integerLiteral(token, value); | 4276 return new IntegerLiteral(token, value); |
| 4298 } else if (keyword == Keyword.CONST) { | 4277 } else if (keyword == Keyword.CONST) { |
| 4299 return parseConstExpression(); | 4278 return parseConstExpression(); |
| 4300 } else if (type == TokenType.OPEN_PAREN) { | 4279 } else if (type == TokenType.OPEN_PAREN) { |
| 4301 if (isFunctionExpression(_currentToken)) { | 4280 if (isFunctionExpression(_currentToken)) { |
| 4302 return parseFunctionExpression(); | 4281 return parseFunctionExpression(); |
| 4303 } | 4282 } |
| 4304 Token leftParenthesis = getAndAdvance(); | 4283 Token leftParenthesis = getAndAdvance(); |
| 4305 bool wasInInitializer = _inInitializer; | 4284 bool wasInInitializer = _inInitializer; |
| 4306 _inInitializer = false; | 4285 _inInitializer = false; |
| 4307 try { | 4286 try { |
| 4308 Expression expression = parseExpression2(); | 4287 Expression expression = parseExpression2(); |
| 4309 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); | 4288 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 4310 return astFactory.parenthesizedExpression( | 4289 return new ParenthesizedExpression( |
| 4311 leftParenthesis, expression, rightParenthesis); | 4290 leftParenthesis, expression, rightParenthesis); |
| 4312 } finally { | 4291 } finally { |
| 4313 _inInitializer = wasInInitializer; | 4292 _inInitializer = wasInInitializer; |
| 4314 } | 4293 } |
| 4315 } else if (type == TokenType.LT || _injectGenericCommentTypeList()) { | 4294 } else if (type == TokenType.LT || _injectGenericCommentTypeList()) { |
| 4316 if (isFunctionExpression(currentToken)) { | 4295 if (isFunctionExpression(currentToken)) { |
| 4317 return parseFunctionExpression(); | 4296 return parseFunctionExpression(); |
| 4318 } | 4297 } |
| 4319 return parseListOrMapLiteral(null); | 4298 return parseListOrMapLiteral(null); |
| 4320 } else if (type == TokenType.OPEN_CURLY_BRACKET) { | 4299 } else if (type == TokenType.OPEN_CURLY_BRACKET) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4365 period = getAndAdvance(); | 4344 period = getAndAdvance(); |
| 4366 if (_matchesIdentifier()) { | 4345 if (_matchesIdentifier()) { |
| 4367 constructorName = _parseSimpleIdentifierUnchecked(isDeclaration: false); | 4346 constructorName = _parseSimpleIdentifierUnchecked(isDeclaration: false); |
| 4368 } else { | 4347 } else { |
| 4369 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); | 4348 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); |
| 4370 constructorName = createSyntheticIdentifier(isDeclaration: false); | 4349 constructorName = createSyntheticIdentifier(isDeclaration: false); |
| 4371 _advance(); | 4350 _advance(); |
| 4372 } | 4351 } |
| 4373 } | 4352 } |
| 4374 ArgumentList argumentList = _parseArgumentListChecked(); | 4353 ArgumentList argumentList = _parseArgumentListChecked(); |
| 4375 return astFactory.redirectingConstructorInvocation( | 4354 return new RedirectingConstructorInvocation( |
| 4376 keyword, period, constructorName, argumentList); | 4355 keyword, period, constructorName, argumentList); |
| 4377 } | 4356 } |
| 4378 | 4357 |
| 4379 /** | 4358 /** |
| 4380 * Parse a relational expression. Return the relational expression that was | 4359 * Parse a relational expression. Return the relational expression that was |
| 4381 * parsed. | 4360 * parsed. |
| 4382 * | 4361 * |
| 4383 * relationalExpression ::= | 4362 * relationalExpression ::= |
| 4384 * bitwiseOrExpression ('is' '!'? type | 'as' type | relationalOperato
r bitwiseOrExpression)? | 4363 * bitwiseOrExpression ('is' '!'? type | 'as' type | relationalOperato
r bitwiseOrExpression)? |
| 4385 * | 'super' relationalOperator bitwiseOrExpression | 4364 * | 'super' relationalOperator bitwiseOrExpression |
| 4386 */ | 4365 */ |
| 4387 Expression parseRelationalExpression() { | 4366 Expression parseRelationalExpression() { |
| 4388 if (_currentToken.keyword == Keyword.SUPER && | 4367 if (_currentToken.keyword == Keyword.SUPER && |
| 4389 _currentToken.next.type.isRelationalOperator) { | 4368 _currentToken.next.type.isRelationalOperator) { |
| 4390 Expression expression = astFactory.superExpression(getAndAdvance()); | 4369 Expression expression = new SuperExpression(getAndAdvance()); |
| 4391 Token operator = getAndAdvance(); | 4370 Token operator = getAndAdvance(); |
| 4392 return astFactory.binaryExpression( | 4371 return new BinaryExpression( |
| 4393 expression, operator, parseBitwiseOrExpression()); | 4372 expression, operator, parseBitwiseOrExpression()); |
| 4394 } | 4373 } |
| 4395 Expression expression = parseBitwiseOrExpression(); | 4374 Expression expression = parseBitwiseOrExpression(); |
| 4396 Keyword keyword = _currentToken.keyword; | 4375 Keyword keyword = _currentToken.keyword; |
| 4397 if (keyword == Keyword.AS) { | 4376 if (keyword == Keyword.AS) { |
| 4398 Token asOperator = getAndAdvance(); | 4377 Token asOperator = getAndAdvance(); |
| 4399 return astFactory.asExpression( | 4378 return new AsExpression(expression, asOperator, parseTypeName(true)); |
| 4400 expression, asOperator, parseTypeName(true)); | |
| 4401 } else if (keyword == Keyword.IS) { | 4379 } else if (keyword == Keyword.IS) { |
| 4402 Token isOperator = getAndAdvance(); | 4380 Token isOperator = getAndAdvance(); |
| 4403 Token notOperator = null; | 4381 Token notOperator = null; |
| 4404 if (_matches(TokenType.BANG)) { | 4382 if (_matches(TokenType.BANG)) { |
| 4405 notOperator = getAndAdvance(); | 4383 notOperator = getAndAdvance(); |
| 4406 } | 4384 } |
| 4407 return astFactory.isExpression( | 4385 return new IsExpression( |
| 4408 expression, isOperator, notOperator, parseTypeName(true)); | 4386 expression, isOperator, notOperator, parseTypeName(true)); |
| 4409 } else if (_currentToken.type.isRelationalOperator) { | 4387 } else if (_currentToken.type.isRelationalOperator) { |
| 4410 Token operator = getAndAdvance(); | 4388 Token operator = getAndAdvance(); |
| 4411 return astFactory.binaryExpression( | 4389 return new BinaryExpression( |
| 4412 expression, operator, parseBitwiseOrExpression()); | 4390 expression, operator, parseBitwiseOrExpression()); |
| 4413 } | 4391 } |
| 4414 return expression; | 4392 return expression; |
| 4415 } | 4393 } |
| 4416 | 4394 |
| 4417 /** | 4395 /** |
| 4418 * Parse a rethrow expression. Return the rethrow expression that was parsed. | 4396 * Parse a rethrow expression. Return the rethrow expression that was parsed. |
| 4419 * | 4397 * |
| 4420 * This method assumes that the current token matches `Keyword.RETHROW`. | 4398 * This method assumes that the current token matches `Keyword.RETHROW`. |
| 4421 * | 4399 * |
| 4422 * rethrowExpression ::= | 4400 * rethrowExpression ::= |
| 4423 * 'rethrow' | 4401 * 'rethrow' |
| 4424 */ | 4402 */ |
| 4425 Expression parseRethrowExpression() => | 4403 Expression parseRethrowExpression() => new RethrowExpression(getAndAdvance()); |
| 4426 astFactory.rethrowExpression(getAndAdvance()); | |
| 4427 | 4404 |
| 4428 /** | 4405 /** |
| 4429 * Parse a return statement. Return the return statement that was parsed. | 4406 * Parse a return statement. Return the return statement that was parsed. |
| 4430 * | 4407 * |
| 4431 * This method assumes that the current token matches `Keyword.RETURN`. | 4408 * This method assumes that the current token matches `Keyword.RETURN`. |
| 4432 * | 4409 * |
| 4433 * returnStatement ::= | 4410 * returnStatement ::= |
| 4434 * 'return' expression? ';' | 4411 * 'return' expression? ';' |
| 4435 */ | 4412 */ |
| 4436 Statement parseReturnStatement() { | 4413 Statement parseReturnStatement() { |
| 4437 Token returnKeyword = getAndAdvance(); | 4414 Token returnKeyword = getAndAdvance(); |
| 4438 if (_matches(TokenType.SEMICOLON)) { | 4415 if (_matches(TokenType.SEMICOLON)) { |
| 4439 return astFactory.returnStatement(returnKeyword, null, getAndAdvance()); | 4416 return new ReturnStatement(returnKeyword, null, getAndAdvance()); |
| 4440 } | 4417 } |
| 4441 Expression expression = parseExpression2(); | 4418 Expression expression = parseExpression2(); |
| 4442 Token semicolon = _expect(TokenType.SEMICOLON); | 4419 Token semicolon = _expect(TokenType.SEMICOLON); |
| 4443 return astFactory.returnStatement(returnKeyword, expression, semicolon); | 4420 return new ReturnStatement(returnKeyword, expression, semicolon); |
| 4444 } | 4421 } |
| 4445 | 4422 |
| 4446 /** | 4423 /** |
| 4447 * Parse a return type. Return the return type that was parsed. | 4424 * Parse a return type. Return the return type that was parsed. |
| 4448 * | 4425 * |
| 4449 * returnType ::= | 4426 * returnType ::= |
| 4450 * 'void' | 4427 * 'void' |
| 4451 * | type | 4428 * | type |
| 4452 */ | 4429 */ |
| 4453 TypeName parseReturnType() { | 4430 TypeName parseReturnType() { |
| 4454 if (_currentToken.keyword == Keyword.VOID) { | 4431 if (_currentToken.keyword == Keyword.VOID) { |
| 4455 return astFactory.typeName( | 4432 return new TypeName(new SimpleIdentifier(getAndAdvance()), null); |
| 4456 astFactory.simpleIdentifier(getAndAdvance()), null); | |
| 4457 } else { | 4433 } else { |
| 4458 return parseTypeName(false); | 4434 return parseTypeName(false); |
| 4459 } | 4435 } |
| 4460 } | 4436 } |
| 4461 | 4437 |
| 4462 /** | 4438 /** |
| 4463 * Parse a setter. The [commentAndMetadata] is the documentation comment and | 4439 * Parse a setter. The [commentAndMetadata] is the documentation comment and |
| 4464 * metadata to be associated with the declaration. The [externalKeyword] is | 4440 * metadata to be associated with the declaration. The [externalKeyword] is |
| 4465 * the 'external' token. The [staticKeyword] is the static keyword, or `null` | 4441 * the 'external' token. The [staticKeyword] is the static keyword, or `null` |
| 4466 * if the setter is not static. The [returnType] is the return type that has | 4442 * if the setter is not static. The [returnType] is the return type that has |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4481 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true); | 4457 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true); |
| 4482 FormalParameterList parameters = parseFormalParameterList(); | 4458 FormalParameterList parameters = parseFormalParameterList(); |
| 4483 _validateFormalParameterList(parameters); | 4459 _validateFormalParameterList(parameters); |
| 4484 FunctionBody body = parseFunctionBody( | 4460 FunctionBody body = parseFunctionBody( |
| 4485 externalKeyword != null || staticKeyword == null, | 4461 externalKeyword != null || staticKeyword == null, |
| 4486 ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, | 4462 ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, |
| 4487 false); | 4463 false); |
| 4488 if (externalKeyword != null && body is! EmptyFunctionBody) { | 4464 if (externalKeyword != null && body is! EmptyFunctionBody) { |
| 4489 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY); | 4465 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY); |
| 4490 } | 4466 } |
| 4491 return astFactory.methodDeclaration( | 4467 return new MethodDeclaration( |
| 4492 commentAndMetadata.comment, | 4468 commentAndMetadata.comment, |
| 4493 commentAndMetadata.metadata, | 4469 commentAndMetadata.metadata, |
| 4494 externalKeyword, | 4470 externalKeyword, |
| 4495 staticKeyword, | 4471 staticKeyword, |
| 4496 returnType, | 4472 returnType, |
| 4497 propertyKeyword, | 4473 propertyKeyword, |
| 4498 null, | 4474 null, |
| 4499 name, | 4475 name, |
| 4500 null, | 4476 null, |
| 4501 parameters, | 4477 parameters, |
| 4502 body); | 4478 body); |
| 4503 } | 4479 } |
| 4504 | 4480 |
| 4505 /** | 4481 /** |
| 4506 * Parse a shift expression. Return the shift expression that was parsed. | 4482 * Parse a shift expression. Return the shift expression that was parsed. |
| 4507 * | 4483 * |
| 4508 * shiftExpression ::= | 4484 * shiftExpression ::= |
| 4509 * additiveExpression (shiftOperator additiveExpression)* | 4485 * additiveExpression (shiftOperator additiveExpression)* |
| 4510 * | 'super' (shiftOperator additiveExpression)+ | 4486 * | 'super' (shiftOperator additiveExpression)+ |
| 4511 */ | 4487 */ |
| 4512 Expression parseShiftExpression() { | 4488 Expression parseShiftExpression() { |
| 4513 Expression expression; | 4489 Expression expression; |
| 4514 if (_currentToken.keyword == Keyword.SUPER && | 4490 if (_currentToken.keyword == Keyword.SUPER && |
| 4515 _currentToken.next.type.isShiftOperator) { | 4491 _currentToken.next.type.isShiftOperator) { |
| 4516 expression = astFactory.superExpression(getAndAdvance()); | 4492 expression = new SuperExpression(getAndAdvance()); |
| 4517 } else { | 4493 } else { |
| 4518 expression = parseAdditiveExpression(); | 4494 expression = parseAdditiveExpression(); |
| 4519 } | 4495 } |
| 4520 while (_currentToken.type.isShiftOperator) { | 4496 while (_currentToken.type.isShiftOperator) { |
| 4521 expression = astFactory.binaryExpression( | 4497 expression = new BinaryExpression( |
| 4522 expression, getAndAdvance(), parseAdditiveExpression()); | 4498 expression, getAndAdvance(), parseAdditiveExpression()); |
| 4523 } | 4499 } |
| 4524 return expression; | 4500 return expression; |
| 4525 } | 4501 } |
| 4526 | 4502 |
| 4527 /** | 4503 /** |
| 4528 * Parse a simple identifier. Return the simple identifier that was parsed. | 4504 * Parse a simple identifier. Return the simple identifier that was parsed. |
| 4529 * | 4505 * |
| 4530 * identifier ::= | 4506 * identifier ::= |
| 4531 * IDENTIFIER | 4507 * IDENTIFIER |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4561 if (labels == null) { | 4537 if (labels == null) { |
| 4562 labels = <Label>[label]; | 4538 labels = <Label>[label]; |
| 4563 } else { | 4539 } else { |
| 4564 labels.add(label); | 4540 labels.add(label); |
| 4565 } | 4541 } |
| 4566 } | 4542 } |
| 4567 Statement statement = parseNonLabeledStatement(); | 4543 Statement statement = parseNonLabeledStatement(); |
| 4568 if (labels == null) { | 4544 if (labels == null) { |
| 4569 return statement; | 4545 return statement; |
| 4570 } | 4546 } |
| 4571 return astFactory.labeledStatement(labels, statement); | 4547 return new LabeledStatement(labels, statement); |
| 4572 } | 4548 } |
| 4573 | 4549 |
| 4574 /** | 4550 /** |
| 4575 * Parse a sequence of statements, starting with the given [token]. Return the | 4551 * Parse a sequence of statements, starting with the given [token]. Return the |
| 4576 * statements that were parsed, or `null` if the tokens do not represent a | 4552 * statements that were parsed, or `null` if the tokens do not represent a |
| 4577 * recognizable sequence of statements. | 4553 * recognizable sequence of statements. |
| 4578 */ | 4554 */ |
| 4579 List<Statement> parseStatements(Token token) { | 4555 List<Statement> parseStatements(Token token) { |
| 4580 _currentToken = token; | 4556 _currentToken = token; |
| 4581 return _parseStatementList(); | 4557 return _parseStatementList(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4607 */ | 4583 */ |
| 4608 SuperConstructorInvocation parseSuperConstructorInvocation() { | 4584 SuperConstructorInvocation parseSuperConstructorInvocation() { |
| 4609 Token keyword = getAndAdvance(); | 4585 Token keyword = getAndAdvance(); |
| 4610 Token period = null; | 4586 Token period = null; |
| 4611 SimpleIdentifier constructorName = null; | 4587 SimpleIdentifier constructorName = null; |
| 4612 if (_matches(TokenType.PERIOD)) { | 4588 if (_matches(TokenType.PERIOD)) { |
| 4613 period = getAndAdvance(); | 4589 period = getAndAdvance(); |
| 4614 constructorName = parseSimpleIdentifier(); | 4590 constructorName = parseSimpleIdentifier(); |
| 4615 } | 4591 } |
| 4616 ArgumentList argumentList = _parseArgumentListChecked(); | 4592 ArgumentList argumentList = _parseArgumentListChecked(); |
| 4617 return astFactory.superConstructorInvocation( | 4593 return new SuperConstructorInvocation( |
| 4618 keyword, period, constructorName, argumentList); | 4594 keyword, period, constructorName, argumentList); |
| 4619 } | 4595 } |
| 4620 | 4596 |
| 4621 /** | 4597 /** |
| 4622 * Parse a switch statement. Return the switch statement that was parsed. | 4598 * Parse a switch statement. Return the switch statement that was parsed. |
| 4623 * | 4599 * |
| 4624 * switchStatement ::= | 4600 * switchStatement ::= |
| 4625 * 'switch' '(' expression ')' '{' switchCase* defaultCase? '}' | 4601 * 'switch' '(' expression ')' '{' switchCase* defaultCase? '}' |
| 4626 * | 4602 * |
| 4627 * switchCase ::= | 4603 * switchCase ::= |
| (...skipping 24 matching lines...) Expand all Loading... |
| 4652 String label = identifier.token.lexeme; | 4628 String label = identifier.token.lexeme; |
| 4653 if (definedLabels.contains(label)) { | 4629 if (definedLabels.contains(label)) { |
| 4654 _reportErrorForToken( | 4630 _reportErrorForToken( |
| 4655 ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, | 4631 ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, |
| 4656 identifier.token, | 4632 identifier.token, |
| 4657 [label]); | 4633 [label]); |
| 4658 } else { | 4634 } else { |
| 4659 definedLabels.add(label); | 4635 definedLabels.add(label); |
| 4660 } | 4636 } |
| 4661 Token colon = getAndAdvance(); | 4637 Token colon = getAndAdvance(); |
| 4662 labels.add(astFactory.label(identifier, colon)); | 4638 labels.add(new Label(identifier, colon)); |
| 4663 } | 4639 } |
| 4664 Keyword keyword = _currentToken.keyword; | 4640 Keyword keyword = _currentToken.keyword; |
| 4665 if (keyword == Keyword.CASE) { | 4641 if (keyword == Keyword.CASE) { |
| 4666 Token caseKeyword = getAndAdvance(); | 4642 Token caseKeyword = getAndAdvance(); |
| 4667 Expression caseExpression = parseExpression2(); | 4643 Expression caseExpression = parseExpression2(); |
| 4668 Token colon = _expect(TokenType.COLON); | 4644 Token colon = _expect(TokenType.COLON); |
| 4669 members.add(astFactory.switchCase(labels, caseKeyword, caseExpression, | 4645 members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon, |
| 4670 colon, _parseStatementList())); | 4646 _parseStatementList())); |
| 4671 if (defaultKeyword != null) { | 4647 if (defaultKeyword != null) { |
| 4672 _reportErrorForToken( | 4648 _reportErrorForToken( |
| 4673 ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, | 4649 ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, |
| 4674 caseKeyword); | 4650 caseKeyword); |
| 4675 } | 4651 } |
| 4676 } else if (keyword == Keyword.DEFAULT) { | 4652 } else if (keyword == Keyword.DEFAULT) { |
| 4677 if (defaultKeyword != null) { | 4653 if (defaultKeyword != null) { |
| 4678 _reportErrorForToken( | 4654 _reportErrorForToken( |
| 4679 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, _peek()); | 4655 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, _peek()); |
| 4680 } | 4656 } |
| 4681 defaultKeyword = getAndAdvance(); | 4657 defaultKeyword = getAndAdvance(); |
| 4682 Token colon = _expect(TokenType.COLON); | 4658 Token colon = _expect(TokenType.COLON); |
| 4683 members.add(astFactory.switchDefault( | 4659 members.add(new SwitchDefault( |
| 4684 labels, defaultKeyword, colon, _parseStatementList())); | 4660 labels, defaultKeyword, colon, _parseStatementList())); |
| 4685 } else { | 4661 } else { |
| 4686 // We need to advance, otherwise we could end up in an infinite loop, | 4662 // We need to advance, otherwise we could end up in an infinite loop, |
| 4687 // but this could be a lot smarter about recovering from the error. | 4663 // but this could be a lot smarter about recovering from the error. |
| 4688 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT); | 4664 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT); |
| 4689 bool atEndOrNextMember() { | 4665 bool atEndOrNextMember() { |
| 4690 TokenType type = _currentToken.type; | 4666 TokenType type = _currentToken.type; |
| 4691 if (type == TokenType.EOF || | 4667 if (type == TokenType.EOF || |
| 4692 type == TokenType.CLOSE_CURLY_BRACKET) { | 4668 type == TokenType.CLOSE_CURLY_BRACKET) { |
| 4693 return true; | 4669 return true; |
| 4694 } | 4670 } |
| 4695 Keyword keyword = _currentToken.keyword; | 4671 Keyword keyword = _currentToken.keyword; |
| 4696 return keyword == Keyword.CASE || keyword == Keyword.DEFAULT; | 4672 return keyword == Keyword.CASE || keyword == Keyword.DEFAULT; |
| 4697 } | 4673 } |
| 4698 | 4674 |
| 4699 while (!atEndOrNextMember()) { | 4675 while (!atEndOrNextMember()) { |
| 4700 _advance(); | 4676 _advance(); |
| 4701 } | 4677 } |
| 4702 } | 4678 } |
| 4703 type = _currentToken.type; | 4679 type = _currentToken.type; |
| 4704 } | 4680 } |
| 4705 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); | 4681 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); |
| 4706 return astFactory.switchStatement(keyword, leftParenthesis, expression, | 4682 return new SwitchStatement(keyword, leftParenthesis, expression, |
| 4707 rightParenthesis, leftBracket, members, rightBracket); | 4683 rightParenthesis, leftBracket, members, rightBracket); |
| 4708 } finally { | 4684 } finally { |
| 4709 _inSwitch = wasInSwitch; | 4685 _inSwitch = wasInSwitch; |
| 4710 } | 4686 } |
| 4711 } | 4687 } |
| 4712 | 4688 |
| 4713 /** | 4689 /** |
| 4714 * Parse a symbol literal. Return the symbol literal that was parsed. | 4690 * Parse a symbol literal. Return the symbol literal that was parsed. |
| 4715 * | 4691 * |
| 4716 * This method assumes that the current token matches [TokenType.HASH]. | 4692 * This method assumes that the current token matches [TokenType.HASH]. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4733 } | 4709 } |
| 4734 } | 4710 } |
| 4735 } else if (_currentToken.isOperator) { | 4711 } else if (_currentToken.isOperator) { |
| 4736 components.add(getAndAdvance()); | 4712 components.add(getAndAdvance()); |
| 4737 } else if (_matchesKeyword(Keyword.VOID)) { | 4713 } else if (_matchesKeyword(Keyword.VOID)) { |
| 4738 components.add(getAndAdvance()); | 4714 components.add(getAndAdvance()); |
| 4739 } else { | 4715 } else { |
| 4740 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); | 4716 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); |
| 4741 components.add(_createSyntheticToken(TokenType.IDENTIFIER)); | 4717 components.add(_createSyntheticToken(TokenType.IDENTIFIER)); |
| 4742 } | 4718 } |
| 4743 return astFactory.symbolLiteral(poundSign, components); | 4719 return new SymbolLiteral(poundSign, components); |
| 4744 } | 4720 } |
| 4745 | 4721 |
| 4746 /** | 4722 /** |
| 4747 * Parse a throw expression. Return the throw expression that was parsed. | 4723 * Parse a throw expression. Return the throw expression that was parsed. |
| 4748 * | 4724 * |
| 4749 * This method assumes that the current token matches [Keyword.THROW]. | 4725 * This method assumes that the current token matches [Keyword.THROW]. |
| 4750 * | 4726 * |
| 4751 * throwExpression ::= | 4727 * throwExpression ::= |
| 4752 * 'throw' expression | 4728 * 'throw' expression |
| 4753 */ | 4729 */ |
| 4754 Expression parseThrowExpression() { | 4730 Expression parseThrowExpression() { |
| 4755 Token keyword = getAndAdvance(); | 4731 Token keyword = getAndAdvance(); |
| 4756 TokenType type = _currentToken.type; | 4732 TokenType type = _currentToken.type; |
| 4757 if (type == TokenType.SEMICOLON || type == TokenType.CLOSE_PAREN) { | 4733 if (type == TokenType.SEMICOLON || type == TokenType.CLOSE_PAREN) { |
| 4758 _reportErrorForToken( | 4734 _reportErrorForToken( |
| 4759 ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken); | 4735 ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken); |
| 4760 return astFactory.throwExpression(keyword, createSyntheticIdentifier()); | 4736 return new ThrowExpression(keyword, createSyntheticIdentifier()); |
| 4761 } | 4737 } |
| 4762 Expression expression = parseExpression2(); | 4738 Expression expression = parseExpression2(); |
| 4763 return astFactory.throwExpression(keyword, expression); | 4739 return new ThrowExpression(keyword, expression); |
| 4764 } | 4740 } |
| 4765 | 4741 |
| 4766 /** | 4742 /** |
| 4767 * Parse a throw expression. Return the throw expression that was parsed. | 4743 * Parse a throw expression. Return the throw expression that was parsed. |
| 4768 * | 4744 * |
| 4769 * This method assumes that the current token matches [Keyword.THROW]. | 4745 * This method assumes that the current token matches [Keyword.THROW]. |
| 4770 * | 4746 * |
| 4771 * throwExpressionWithoutCascade ::= | 4747 * throwExpressionWithoutCascade ::= |
| 4772 * 'throw' expressionWithoutCascade | 4748 * 'throw' expressionWithoutCascade |
| 4773 */ | 4749 */ |
| 4774 Expression parseThrowExpressionWithoutCascade() { | 4750 Expression parseThrowExpressionWithoutCascade() { |
| 4775 Token keyword = getAndAdvance(); | 4751 Token keyword = getAndAdvance(); |
| 4776 TokenType type = _currentToken.type; | 4752 TokenType type = _currentToken.type; |
| 4777 if (type == TokenType.SEMICOLON || type == TokenType.CLOSE_PAREN) { | 4753 if (type == TokenType.SEMICOLON || type == TokenType.CLOSE_PAREN) { |
| 4778 _reportErrorForToken( | 4754 _reportErrorForToken( |
| 4779 ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken); | 4755 ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken); |
| 4780 return astFactory.throwExpression(keyword, createSyntheticIdentifier()); | 4756 return new ThrowExpression(keyword, createSyntheticIdentifier()); |
| 4781 } | 4757 } |
| 4782 Expression expression = parseExpressionWithoutCascade(); | 4758 Expression expression = parseExpressionWithoutCascade(); |
| 4783 return astFactory.throwExpression(keyword, expression); | 4759 return new ThrowExpression(keyword, expression); |
| 4784 } | 4760 } |
| 4785 | 4761 |
| 4786 /** | 4762 /** |
| 4787 * Parse a try statement. Return the try statement that was parsed. | 4763 * Parse a try statement. Return the try statement that was parsed. |
| 4788 * | 4764 * |
| 4789 * This method assumes that the current token matches [Keyword.TRY]. | 4765 * This method assumes that the current token matches [Keyword.TRY]. |
| 4790 * | 4766 * |
| 4791 * tryStatement ::= | 4767 * tryStatement ::= |
| 4792 * 'try' block (onPart+ finallyPart? | finallyPart) | 4768 * 'try' block (onPart+ finallyPart? | finallyPart) |
| 4793 * | 4769 * |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4823 catchKeyword = getAndAdvance(); | 4799 catchKeyword = getAndAdvance(); |
| 4824 leftParenthesis = _expect(TokenType.OPEN_PAREN); | 4800 leftParenthesis = _expect(TokenType.OPEN_PAREN); |
| 4825 exceptionParameter = parseSimpleIdentifier(isDeclaration: true); | 4801 exceptionParameter = parseSimpleIdentifier(isDeclaration: true); |
| 4826 if (_matches(TokenType.COMMA)) { | 4802 if (_matches(TokenType.COMMA)) { |
| 4827 comma = getAndAdvance(); | 4803 comma = getAndAdvance(); |
| 4828 stackTraceParameter = parseSimpleIdentifier(isDeclaration: true); | 4804 stackTraceParameter = parseSimpleIdentifier(isDeclaration: true); |
| 4829 } | 4805 } |
| 4830 rightParenthesis = _expect(TokenType.CLOSE_PAREN); | 4806 rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 4831 } | 4807 } |
| 4832 Block catchBody = _parseBlockChecked(); | 4808 Block catchBody = _parseBlockChecked(); |
| 4833 catchClauses.add(astFactory.catchClause( | 4809 catchClauses.add(new CatchClause( |
| 4834 onKeyword, | 4810 onKeyword, |
| 4835 exceptionType, | 4811 exceptionType, |
| 4836 catchKeyword, | 4812 catchKeyword, |
| 4837 leftParenthesis, | 4813 leftParenthesis, |
| 4838 exceptionParameter, | 4814 exceptionParameter, |
| 4839 comma, | 4815 comma, |
| 4840 stackTraceParameter, | 4816 stackTraceParameter, |
| 4841 rightParenthesis, | 4817 rightParenthesis, |
| 4842 catchBody)); | 4818 catchBody)); |
| 4843 } | 4819 } |
| 4844 Token finallyKeyword = null; | 4820 Token finallyKeyword = null; |
| 4845 if (_matchesKeyword(Keyword.FINALLY)) { | 4821 if (_matchesKeyword(Keyword.FINALLY)) { |
| 4846 finallyKeyword = getAndAdvance(); | 4822 finallyKeyword = getAndAdvance(); |
| 4847 finallyClause = _parseBlockChecked(); | 4823 finallyClause = _parseBlockChecked(); |
| 4848 } else if (catchClauses.isEmpty) { | 4824 } else if (catchClauses.isEmpty) { |
| 4849 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CATCH_OR_FINALLY); | 4825 _reportErrorForCurrentToken(ParserErrorCode.MISSING_CATCH_OR_FINALLY); |
| 4850 } | 4826 } |
| 4851 return astFactory.tryStatement( | 4827 return new TryStatement( |
| 4852 tryKeyword, body, catchClauses, finallyKeyword, finallyClause); | 4828 tryKeyword, body, catchClauses, finallyKeyword, finallyClause); |
| 4853 } | 4829 } |
| 4854 | 4830 |
| 4855 /** | 4831 /** |
| 4856 * Parse a type alias. The [commentAndMetadata] is the metadata to be | 4832 * Parse a type alias. The [commentAndMetadata] is the metadata to be |
| 4857 * associated with the member. Return the type alias that was parsed. | 4833 * associated with the member. Return the type alias that was parsed. |
| 4858 * | 4834 * |
| 4859 * This method assumes that the current token matches [Keyword.TYPEDEF]. | 4835 * This method assumes that the current token matches [Keyword.TYPEDEF]. |
| 4860 * | 4836 * |
| 4861 * typeAlias ::= | 4837 * typeAlias ::= |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4913 * typeList ::= | 4889 * typeList ::= |
| 4914 * type (',' type)* | 4890 * type (',' type)* |
| 4915 */ | 4891 */ |
| 4916 TypeArgumentList parseTypeArgumentList() { | 4892 TypeArgumentList parseTypeArgumentList() { |
| 4917 Token leftBracket = getAndAdvance(); | 4893 Token leftBracket = getAndAdvance(); |
| 4918 List<TypeName> arguments = <TypeName>[parseTypeName(false)]; | 4894 List<TypeName> arguments = <TypeName>[parseTypeName(false)]; |
| 4919 while (_optional(TokenType.COMMA)) { | 4895 while (_optional(TokenType.COMMA)) { |
| 4920 arguments.add(parseTypeName(false)); | 4896 arguments.add(parseTypeName(false)); |
| 4921 } | 4897 } |
| 4922 Token rightBracket = _expectGt(); | 4898 Token rightBracket = _expectGt(); |
| 4923 return astFactory.typeArgumentList(leftBracket, arguments, rightBracket); | 4899 return new TypeArgumentList(leftBracket, arguments, rightBracket); |
| 4924 } | 4900 } |
| 4925 | 4901 |
| 4926 /** | 4902 /** |
| 4927 * Parse a type name. Return the type name that was parsed. | 4903 * Parse a type name. Return the type name that was parsed. |
| 4928 * | 4904 * |
| 4929 * type ::= | 4905 * type ::= |
| 4930 * qualified typeArguments? | 4906 * qualified typeArguments? |
| 4931 */ | 4907 */ |
| 4932 TypeName parseTypeName(bool inExpression) { | 4908 TypeName parseTypeName(bool inExpression) { |
| 4933 TypeName realType = _parseTypeName(inExpression); | 4909 TypeName realType = _parseTypeName(inExpression); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4948 TypeParameter parseTypeParameter() { | 4924 TypeParameter parseTypeParameter() { |
| 4949 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); | 4925 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); |
| 4950 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true); | 4926 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true); |
| 4951 if (_matches(TokenType.QUESTION)) { | 4927 if (_matches(TokenType.QUESTION)) { |
| 4952 _reportErrorForCurrentToken(ParserErrorCode.NULLABLE_TYPE_PARAMETER); | 4928 _reportErrorForCurrentToken(ParserErrorCode.NULLABLE_TYPE_PARAMETER); |
| 4953 _advance(); | 4929 _advance(); |
| 4954 } | 4930 } |
| 4955 if (_matchesKeyword(Keyword.EXTENDS)) { | 4931 if (_matchesKeyword(Keyword.EXTENDS)) { |
| 4956 Token keyword = getAndAdvance(); | 4932 Token keyword = getAndAdvance(); |
| 4957 TypeName bound = parseTypeName(false); | 4933 TypeName bound = parseTypeName(false); |
| 4958 return astFactory.typeParameter(commentAndMetadata.comment, | 4934 return new TypeParameter(commentAndMetadata.comment, |
| 4959 commentAndMetadata.metadata, name, keyword, bound); | 4935 commentAndMetadata.metadata, name, keyword, bound); |
| 4960 } | 4936 } |
| 4961 return astFactory.typeParameter(commentAndMetadata.comment, | 4937 return new TypeParameter(commentAndMetadata.comment, |
| 4962 commentAndMetadata.metadata, name, null, null); | 4938 commentAndMetadata.metadata, name, null, null); |
| 4963 } | 4939 } |
| 4964 | 4940 |
| 4965 /** | 4941 /** |
| 4966 * Parse a list of type parameters. Return the list of type parameters that | 4942 * Parse a list of type parameters. Return the list of type parameters that |
| 4967 * were parsed. | 4943 * were parsed. |
| 4968 * | 4944 * |
| 4969 * This method assumes that the current token matches `TokenType.LT`. | 4945 * This method assumes that the current token matches `TokenType.LT`. |
| 4970 * | 4946 * |
| 4971 * typeParameterList ::= | 4947 * typeParameterList ::= |
| 4972 * '<' typeParameter (',' typeParameter)* '>' | 4948 * '<' typeParameter (',' typeParameter)* '>' |
| 4973 */ | 4949 */ |
| 4974 TypeParameterList parseTypeParameterList() { | 4950 TypeParameterList parseTypeParameterList() { |
| 4975 Token leftBracket = getAndAdvance(); | 4951 Token leftBracket = getAndAdvance(); |
| 4976 List<TypeParameter> typeParameters = <TypeParameter>[parseTypeParameter()]; | 4952 List<TypeParameter> typeParameters = <TypeParameter>[parseTypeParameter()]; |
| 4977 while (_optional(TokenType.COMMA)) { | 4953 while (_optional(TokenType.COMMA)) { |
| 4978 typeParameters.add(parseTypeParameter()); | 4954 typeParameters.add(parseTypeParameter()); |
| 4979 } | 4955 } |
| 4980 Token rightBracket = _expectGt(); | 4956 Token rightBracket = _expectGt(); |
| 4981 return astFactory.typeParameterList( | 4957 return new TypeParameterList(leftBracket, typeParameters, rightBracket); |
| 4982 leftBracket, typeParameters, rightBracket); | |
| 4983 } | 4958 } |
| 4984 | 4959 |
| 4985 /** | 4960 /** |
| 4986 * Parse a unary expression. Return the unary expression that was parsed. | 4961 * Parse a unary expression. Return the unary expression that was parsed. |
| 4987 * | 4962 * |
| 4988 * unaryExpression ::= | 4963 * unaryExpression ::= |
| 4989 * prefixOperator unaryExpression | 4964 * prefixOperator unaryExpression |
| 4990 * | awaitExpression | 4965 * | awaitExpression |
| 4991 * | postfixExpression | 4966 * | postfixExpression |
| 4992 * | unaryOperator 'super' | 4967 * | unaryOperator 'super' |
| 4993 * | '-' 'super' | 4968 * | '-' 'super' |
| 4994 * | incrementOperator assignableExpression | 4969 * | incrementOperator assignableExpression |
| 4995 */ | 4970 */ |
| 4996 Expression parseUnaryExpression() { | 4971 Expression parseUnaryExpression() { |
| 4997 TokenType type = _currentToken.type; | 4972 TokenType type = _currentToken.type; |
| 4998 if (type == TokenType.MINUS || | 4973 if (type == TokenType.MINUS || |
| 4999 type == TokenType.BANG || | 4974 type == TokenType.BANG || |
| 5000 type == TokenType.TILDE) { | 4975 type == TokenType.TILDE) { |
| 5001 Token operator = getAndAdvance(); | 4976 Token operator = getAndAdvance(); |
| 5002 if (_matchesKeyword(Keyword.SUPER)) { | 4977 if (_matchesKeyword(Keyword.SUPER)) { |
| 5003 TokenType nextType = _peek().type; | 4978 TokenType nextType = _peek().type; |
| 5004 if (nextType == TokenType.OPEN_SQUARE_BRACKET || | 4979 if (nextType == TokenType.OPEN_SQUARE_BRACKET || |
| 5005 nextType == TokenType.PERIOD) { | 4980 nextType == TokenType.PERIOD) { |
| 5006 // "prefixOperator unaryExpression" | 4981 // "prefixOperator unaryExpression" |
| 5007 // --> "prefixOperator postfixExpression" | 4982 // --> "prefixOperator postfixExpression" |
| 5008 // --> "prefixOperator primary selector*" | 4983 // --> "prefixOperator primary selector*" |
| 5009 // --> "prefixOperator 'super' assignableSelector selector*" | 4984 // --> "prefixOperator 'super' assignableSelector selector*" |
| 5010 return astFactory.prefixExpression(operator, parseUnaryExpression()); | 4985 return new PrefixExpression(operator, parseUnaryExpression()); |
| 5011 } | 4986 } |
| 5012 return astFactory.prefixExpression( | 4987 return new PrefixExpression( |
| 5013 operator, astFactory.superExpression(getAndAdvance())); | 4988 operator, new SuperExpression(getAndAdvance())); |
| 5014 } | 4989 } |
| 5015 return astFactory.prefixExpression(operator, parseUnaryExpression()); | 4990 return new PrefixExpression(operator, parseUnaryExpression()); |
| 5016 } else if (_currentToken.type.isIncrementOperator) { | 4991 } else if (_currentToken.type.isIncrementOperator) { |
| 5017 Token operator = getAndAdvance(); | 4992 Token operator = getAndAdvance(); |
| 5018 if (_matchesKeyword(Keyword.SUPER)) { | 4993 if (_matchesKeyword(Keyword.SUPER)) { |
| 5019 TokenType nextType = _peek().type; | 4994 TokenType nextType = _peek().type; |
| 5020 if (nextType == TokenType.OPEN_SQUARE_BRACKET || | 4995 if (nextType == TokenType.OPEN_SQUARE_BRACKET || |
| 5021 nextType == TokenType.PERIOD) { | 4996 nextType == TokenType.PERIOD) { |
| 5022 // --> "prefixOperator 'super' assignableSelector selector*" | 4997 // --> "prefixOperator 'super' assignableSelector selector*" |
| 5023 return astFactory.prefixExpression(operator, parseUnaryExpression()); | 4998 return new PrefixExpression(operator, parseUnaryExpression()); |
| 5024 } | 4999 } |
| 5025 // | 5000 // |
| 5026 // Even though it is not valid to use an incrementing operator | 5001 // Even though it is not valid to use an incrementing operator |
| 5027 // ('++' or '--') before 'super', we can (and therefore must) interpret | 5002 // ('++' or '--') before 'super', we can (and therefore must) interpret |
| 5028 // "--super" as semantically equivalent to "-(-super)". Unfortunately, | 5003 // "--super" as semantically equivalent to "-(-super)". Unfortunately, |
| 5029 // we cannot do the same for "++super" because "+super" is also not | 5004 // we cannot do the same for "++super" because "+super" is also not |
| 5030 // valid. | 5005 // valid. |
| 5031 // | 5006 // |
| 5032 if (type == TokenType.MINUS_MINUS) { | 5007 if (type == TokenType.MINUS_MINUS) { |
| 5033 Token firstOperator = _createToken(operator, TokenType.MINUS); | 5008 Token firstOperator = _createToken(operator, TokenType.MINUS); |
| 5034 Token secondOperator = | 5009 Token secondOperator = |
| 5035 new Token(TokenType.MINUS, operator.offset + 1); | 5010 new Token(TokenType.MINUS, operator.offset + 1); |
| 5036 secondOperator.setNext(_currentToken); | 5011 secondOperator.setNext(_currentToken); |
| 5037 firstOperator.setNext(secondOperator); | 5012 firstOperator.setNext(secondOperator); |
| 5038 operator.previous.setNext(firstOperator); | 5013 operator.previous.setNext(firstOperator); |
| 5039 return astFactory.prefixExpression( | 5014 return new PrefixExpression( |
| 5040 firstOperator, | 5015 firstOperator, |
| 5041 astFactory.prefixExpression( | 5016 new PrefixExpression( |
| 5042 secondOperator, astFactory.superExpression(getAndAdvance()))); | 5017 secondOperator, new SuperExpression(getAndAdvance()))); |
| 5043 } | 5018 } |
| 5044 // Invalid operator before 'super' | 5019 // Invalid operator before 'super' |
| 5045 _reportErrorForCurrentToken( | 5020 _reportErrorForCurrentToken( |
| 5046 ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.lexeme]); | 5021 ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.lexeme]); |
| 5047 return astFactory.prefixExpression( | 5022 return new PrefixExpression( |
| 5048 operator, astFactory.superExpression(getAndAdvance())); | 5023 operator, new SuperExpression(getAndAdvance())); |
| 5049 } | 5024 } |
| 5050 return astFactory.prefixExpression( | 5025 return new PrefixExpression( |
| 5051 operator, _parseAssignableExpressionNotStartingWithSuper(false)); | 5026 operator, _parseAssignableExpressionNotStartingWithSuper(false)); |
| 5052 } else if (type == TokenType.PLUS) { | 5027 } else if (type == TokenType.PLUS) { |
| 5053 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); | 5028 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); |
| 5054 return createSyntheticIdentifier(); | 5029 return createSyntheticIdentifier(); |
| 5055 } else if (_inAsync && _matchesString(_AWAIT)) { | 5030 } else if (_inAsync && _matchesString(_AWAIT)) { |
| 5056 return parseAwaitExpression(); | 5031 return parseAwaitExpression(); |
| 5057 } | 5032 } |
| 5058 return parsePostfixExpression(); | 5033 return parsePostfixExpression(); |
| 5059 } | 5034 } |
| 5060 | 5035 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5075 // of a construct like "class C { int @deprecated foo() {} }" (i.e. the | 5050 // of a construct like "class C { int @deprecated foo() {} }" (i.e. the |
| 5076 // user is in the middle of inserting "int bar;" prior to | 5051 // user is in the middle of inserting "int bar;" prior to |
| 5077 // "@deprecated foo() {}"). | 5052 // "@deprecated foo() {}"). |
| 5078 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true); | 5053 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true); |
| 5079 Token equals = null; | 5054 Token equals = null; |
| 5080 Expression initializer = null; | 5055 Expression initializer = null; |
| 5081 if (_matches(TokenType.EQ)) { | 5056 if (_matches(TokenType.EQ)) { |
| 5082 equals = getAndAdvance(); | 5057 equals = getAndAdvance(); |
| 5083 initializer = parseExpression2(); | 5058 initializer = parseExpression2(); |
| 5084 } | 5059 } |
| 5085 return astFactory.variableDeclaration(name, equals, initializer); | 5060 return new VariableDeclaration(name, equals, initializer); |
| 5086 } | 5061 } |
| 5087 | 5062 |
| 5088 /** | 5063 /** |
| 5089 * Parse a variable declaration list. The [commentAndMetadata] is the metadata | 5064 * Parse a variable declaration list. The [commentAndMetadata] is the metadata |
| 5090 * to be associated with the variable declaration list. Return the variable | 5065 * to be associated with the variable declaration list. Return the variable |
| 5091 * declaration list that was parsed. | 5066 * declaration list that was parsed. |
| 5092 * | 5067 * |
| 5093 * variableDeclarationList ::= | 5068 * variableDeclarationList ::= |
| 5094 * finalConstVarOrType variableDeclaration (',' variableDeclaration)* | 5069 * finalConstVarOrType variableDeclaration (',' variableDeclaration)* |
| 5095 */ | 5070 */ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 5117 keyword != null && | 5092 keyword != null && |
| 5118 _tokenMatchesKeyword(keyword, Keyword.VAR)) { | 5093 _tokenMatchesKeyword(keyword, Keyword.VAR)) { |
| 5119 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, keyword); | 5094 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, keyword); |
| 5120 } | 5095 } |
| 5121 List<VariableDeclaration> variables = <VariableDeclaration>[ | 5096 List<VariableDeclaration> variables = <VariableDeclaration>[ |
| 5122 parseVariableDeclaration() | 5097 parseVariableDeclaration() |
| 5123 ]; | 5098 ]; |
| 5124 while (_optional(TokenType.COMMA)) { | 5099 while (_optional(TokenType.COMMA)) { |
| 5125 variables.add(parseVariableDeclaration()); | 5100 variables.add(parseVariableDeclaration()); |
| 5126 } | 5101 } |
| 5127 return astFactory.variableDeclarationList(commentAndMetadata?.comment, | 5102 return new VariableDeclarationList(commentAndMetadata?.comment, |
| 5128 commentAndMetadata?.metadata, keyword, type, variables); | 5103 commentAndMetadata?.metadata, keyword, type, variables); |
| 5129 } | 5104 } |
| 5130 | 5105 |
| 5131 /** | 5106 /** |
| 5132 * Parse a variable declaration statement. The [commentAndMetadata] is the | 5107 * Parse a variable declaration statement. The [commentAndMetadata] is the |
| 5133 * metadata to be associated with the variable declaration statement, or | 5108 * metadata to be associated with the variable declaration statement, or |
| 5134 * `null` if there is no attempt at parsing the comment and metadata. Return | 5109 * `null` if there is no attempt at parsing the comment and metadata. Return |
| 5135 * the variable declaration statement that was parsed. | 5110 * the variable declaration statement that was parsed. |
| 5136 * | 5111 * |
| 5137 * variableDeclarationStatement ::= | 5112 * variableDeclarationStatement ::= |
| 5138 * variableDeclarationList ';' | 5113 * variableDeclarationList ';' |
| 5139 */ | 5114 */ |
| 5140 VariableDeclarationStatement parseVariableDeclarationStatementAfterMetadata( | 5115 VariableDeclarationStatement parseVariableDeclarationStatementAfterMetadata( |
| 5141 CommentAndMetadata commentAndMetadata) { | 5116 CommentAndMetadata commentAndMetadata) { |
| 5142 // Token startToken = currentToken; | 5117 // Token startToken = currentToken; |
| 5143 VariableDeclarationList variableList = | 5118 VariableDeclarationList variableList = |
| 5144 parseVariableDeclarationListAfterMetadata(commentAndMetadata); | 5119 parseVariableDeclarationListAfterMetadata(commentAndMetadata); |
| 5145 // if (!matches(TokenType.SEMICOLON)) { | 5120 // if (!matches(TokenType.SEMICOLON)) { |
| 5146 // if (matches(startToken, Keyword.VAR) && isTypedIdentifier(startToken
.getNext())) { | 5121 // if (matches(startToken, Keyword.VAR) && isTypedIdentifier(startToken
.getNext())) { |
| 5147 // // TODO(brianwilkerson) This appears to be of the form "var type v
ariable". We should do | 5122 // // TODO(brianwilkerson) This appears to be of the form "var type v
ariable". We should do |
| 5148 // // a better job of recovering in this case. | 5123 // // a better job of recovering in this case. |
| 5149 // } | 5124 // } |
| 5150 // } | 5125 // } |
| 5151 Token semicolon = _expect(TokenType.SEMICOLON); | 5126 Token semicolon = _expect(TokenType.SEMICOLON); |
| 5152 return astFactory.variableDeclarationStatement(variableList, semicolon); | 5127 return new VariableDeclarationStatement(variableList, semicolon); |
| 5153 } | 5128 } |
| 5154 | 5129 |
| 5155 /** | 5130 /** |
| 5156 * Parse a while statement. Return the while statement that was parsed. | 5131 * Parse a while statement. Return the while statement that was parsed. |
| 5157 * | 5132 * |
| 5158 * This method assumes that the current token matches [Keyword.WHILE]. | 5133 * This method assumes that the current token matches [Keyword.WHILE]. |
| 5159 * | 5134 * |
| 5160 * whileStatement ::= | 5135 * whileStatement ::= |
| 5161 * 'while' '(' expression ')' statement | 5136 * 'while' '(' expression ')' statement |
| 5162 */ | 5137 */ |
| 5163 Statement parseWhileStatement() { | 5138 Statement parseWhileStatement() { |
| 5164 bool wasInLoop = _inLoop; | 5139 bool wasInLoop = _inLoop; |
| 5165 _inLoop = true; | 5140 _inLoop = true; |
| 5166 try { | 5141 try { |
| 5167 Token keyword = getAndAdvance(); | 5142 Token keyword = getAndAdvance(); |
| 5168 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); | 5143 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); |
| 5169 Expression condition = parseExpression2(); | 5144 Expression condition = parseExpression2(); |
| 5170 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); | 5145 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN); |
| 5171 Statement body = parseStatement2(); | 5146 Statement body = parseStatement2(); |
| 5172 return astFactory.whileStatement( | 5147 return new WhileStatement( |
| 5173 keyword, leftParenthesis, condition, rightParenthesis, body); | 5148 keyword, leftParenthesis, condition, rightParenthesis, body); |
| 5174 } finally { | 5149 } finally { |
| 5175 _inLoop = wasInLoop; | 5150 _inLoop = wasInLoop; |
| 5176 } | 5151 } |
| 5177 } | 5152 } |
| 5178 | 5153 |
| 5179 /** | 5154 /** |
| 5180 * Parse a with clause. Return the with clause that was parsed. | 5155 * Parse a with clause. Return the with clause that was parsed. |
| 5181 * | 5156 * |
| 5182 * This method assumes that the current token matches `Keyword.WITH`. | 5157 * This method assumes that the current token matches `Keyword.WITH`. |
| 5183 * | 5158 * |
| 5184 * withClause ::= | 5159 * withClause ::= |
| 5185 * 'with' typeName (',' typeName)* | 5160 * 'with' typeName (',' typeName)* |
| 5186 */ | 5161 */ |
| 5187 WithClause parseWithClause() { | 5162 WithClause parseWithClause() { |
| 5188 Token withKeyword = getAndAdvance(); | 5163 Token withKeyword = getAndAdvance(); |
| 5189 List<TypeName> types = <TypeName>[]; | 5164 List<TypeName> types = <TypeName>[]; |
| 5190 do { | 5165 do { |
| 5191 TypeName typeName = parseTypeName(false); | 5166 TypeName typeName = parseTypeName(false); |
| 5192 _mustNotBeNullable(typeName, ParserErrorCode.NULLABLE_TYPE_IN_WITH); | 5167 _mustNotBeNullable(typeName, ParserErrorCode.NULLABLE_TYPE_IN_WITH); |
| 5193 types.add(typeName); | 5168 types.add(typeName); |
| 5194 } while (_optional(TokenType.COMMA)); | 5169 } while (_optional(TokenType.COMMA)); |
| 5195 return astFactory.withClause(withKeyword, types); | 5170 return new WithClause(withKeyword, types); |
| 5196 } | 5171 } |
| 5197 | 5172 |
| 5198 /** | 5173 /** |
| 5199 * Parse a yield statement. Return the yield statement that was parsed. | 5174 * Parse a yield statement. Return the yield statement that was parsed. |
| 5200 * | 5175 * |
| 5201 * This method assumes that the current token matches [Keyword.YIELD]. | 5176 * This method assumes that the current token matches [Keyword.YIELD]. |
| 5202 * | 5177 * |
| 5203 * yieldStatement ::= | 5178 * yieldStatement ::= |
| 5204 * 'yield' '*'? expression ';' | 5179 * 'yield' '*'? expression ';' |
| 5205 */ | 5180 */ |
| 5206 YieldStatement parseYieldStatement() { | 5181 YieldStatement parseYieldStatement() { |
| 5207 Token yieldToken = getAndAdvance(); | 5182 Token yieldToken = getAndAdvance(); |
| 5208 Token star = null; | 5183 Token star = null; |
| 5209 if (_matches(TokenType.STAR)) { | 5184 if (_matches(TokenType.STAR)) { |
| 5210 star = getAndAdvance(); | 5185 star = getAndAdvance(); |
| 5211 } | 5186 } |
| 5212 Expression expression = parseExpression2(); | 5187 Expression expression = parseExpression2(); |
| 5213 Token semicolon = _expect(TokenType.SEMICOLON); | 5188 Token semicolon = _expect(TokenType.SEMICOLON); |
| 5214 return astFactory.yieldStatement(yieldToken, star, expression, semicolon); | 5189 return new YieldStatement(yieldToken, star, expression, semicolon); |
| 5215 } | 5190 } |
| 5216 | 5191 |
| 5217 /** | 5192 /** |
| 5218 * Parse a prefixed identifier, starting at the [startToken], without actually | 5193 * Parse a prefixed identifier, starting at the [startToken], without actually |
| 5219 * creating a prefixed identifier or changing the current token. Return the | 5194 * creating a prefixed identifier or changing the current token. Return the |
| 5220 * token following the prefixed identifier that was parsed, or `null` if the | 5195 * token following the prefixed identifier that was parsed, or `null` if the |
| 5221 * given token is not the first token in a valid prefixed identifier. | 5196 * given token is not the first token in a valid prefixed identifier. |
| 5222 * | 5197 * |
| 5223 * This method must be kept in sync with [parsePrefixedIdentifier]. | 5198 * This method must be kept in sync with [parsePrefixedIdentifier]. |
| 5224 * | 5199 * |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5434 current.setNext(tail); | 5409 current.setNext(tail); |
| 5435 return head.next; | 5410 return head.next; |
| 5436 } | 5411 } |
| 5437 | 5412 |
| 5438 /** | 5413 /** |
| 5439 * Convert the given [method] declaration into the nearest valid top-level | 5414 * Convert the given [method] declaration into the nearest valid top-level |
| 5440 * function declaration (that is, the function declaration that most closely | 5415 * function declaration (that is, the function declaration that most closely |
| 5441 * captures the components of the given method declaration). | 5416 * captures the components of the given method declaration). |
| 5442 */ | 5417 */ |
| 5443 FunctionDeclaration _convertToFunctionDeclaration(MethodDeclaration method) => | 5418 FunctionDeclaration _convertToFunctionDeclaration(MethodDeclaration method) => |
| 5444 astFactory.functionDeclaration( | 5419 new FunctionDeclaration( |
| 5445 method.documentationComment, | 5420 method.documentationComment, |
| 5446 method.metadata, | 5421 method.metadata, |
| 5447 method.externalKeyword, | 5422 method.externalKeyword, |
| 5448 method.returnType, | 5423 method.returnType, |
| 5449 method.propertyKeyword, | 5424 method.propertyKeyword, |
| 5450 method.name, | 5425 method.name, |
| 5451 astFactory.functionExpression( | 5426 new FunctionExpression( |
| 5452 method.typeParameters, method.parameters, method.body)); | 5427 method.typeParameters, method.parameters, method.body)); |
| 5453 | 5428 |
| 5454 /** | 5429 /** |
| 5455 * Return `true` if the current token could be the start of a compilation unit | 5430 * Return `true` if the current token could be the start of a compilation unit |
| 5456 * member. This method is used for recovery purposes to decide when to stop | 5431 * member. This method is used for recovery purposes to decide when to stop |
| 5457 * skipping tokens after finding an error while parsing a compilation unit | 5432 * skipping tokens after finding an error while parsing a compilation unit |
| 5458 * member. | 5433 * member. |
| 5459 */ | 5434 */ |
| 5460 bool _couldBeStartOfCompilationUnitMember() { | 5435 bool _couldBeStartOfCompilationUnitMember() { |
| 5461 Keyword keyword = _currentToken.keyword; | 5436 Keyword keyword = _currentToken.keyword; |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6002 * when there isn't one. Return the argument list that was parsed. | 5977 * when there isn't one. Return the argument list that was parsed. |
| 6003 */ | 5978 */ |
| 6004 ArgumentList _parseArgumentListChecked() { | 5979 ArgumentList _parseArgumentListChecked() { |
| 6005 if (_matches(TokenType.OPEN_PAREN)) { | 5980 if (_matches(TokenType.OPEN_PAREN)) { |
| 6006 return parseArgumentList(); | 5981 return parseArgumentList(); |
| 6007 } | 5982 } |
| 6008 _reportErrorForCurrentToken( | 5983 _reportErrorForCurrentToken( |
| 6009 ParserErrorCode.EXPECTED_TOKEN, [TokenType.OPEN_PAREN.lexeme]); | 5984 ParserErrorCode.EXPECTED_TOKEN, [TokenType.OPEN_PAREN.lexeme]); |
| 6010 // Recovery: Look to see whether there is a close paren that isn't matched | 5985 // Recovery: Look to see whether there is a close paren that isn't matched |
| 6011 // to an open paren and if so parse the list of arguments as normal. | 5986 // to an open paren and if so parse the list of arguments as normal. |
| 6012 return astFactory.argumentList(_createSyntheticToken(TokenType.OPEN_PAREN), | 5987 return new ArgumentList(_createSyntheticToken(TokenType.OPEN_PAREN), null, |
| 6013 null, _createSyntheticToken(TokenType.CLOSE_PAREN)); | 5988 _createSyntheticToken(TokenType.CLOSE_PAREN)); |
| 6014 } | 5989 } |
| 6015 | 5990 |
| 6016 /** | 5991 /** |
| 6017 * Parse an assert within a constructor's initializer list. Return the assert. | 5992 * Parse an assert within a constructor's initializer list. Return the assert. |
| 6018 * | 5993 * |
| 6019 * This method assumes that the current token matches `Keyword.ASSERT`. | 5994 * This method assumes that the current token matches `Keyword.ASSERT`. |
| 6020 * | 5995 * |
| 6021 * assertInitializer ::= | 5996 * assertInitializer ::= |
| 6022 * 'assert' '(' expression [',' expression] ')' | 5997 * 'assert' '(' expression [',' expression] ')' |
| 6023 */ | 5998 */ |
| 6024 AssertInitializer _parseAssertInitializer() { | 5999 AssertInitializer _parseAssertInitializer() { |
| 6025 Token keyword = getAndAdvance(); | 6000 Token keyword = getAndAdvance(); |
| 6026 Token leftParen = _expect(TokenType.OPEN_PAREN); | 6001 Token leftParen = _expect(TokenType.OPEN_PAREN); |
| 6027 Expression expression = parseExpression2(); | 6002 Expression expression = parseExpression2(); |
| 6028 Token comma; | 6003 Token comma; |
| 6029 Expression message; | 6004 Expression message; |
| 6030 if (_matches(TokenType.COMMA)) { | 6005 if (_matches(TokenType.COMMA)) { |
| 6031 comma = getAndAdvance(); | 6006 comma = getAndAdvance(); |
| 6032 message = parseExpression2(); | 6007 message = parseExpression2(); |
| 6033 } | 6008 } |
| 6034 Token rightParen = _expect(TokenType.CLOSE_PAREN); | 6009 Token rightParen = _expect(TokenType.CLOSE_PAREN); |
| 6035 return astFactory.assertInitializer( | 6010 return new AssertInitializer( |
| 6036 keyword, leftParen, expression, comma, message, rightParen); | 6011 keyword, leftParen, expression, comma, message, rightParen); |
| 6037 } | 6012 } |
| 6038 | 6013 |
| 6039 /** | 6014 /** |
| 6040 * Parse an assignable expression given that the current token is not 'super'. | 6015 * Parse an assignable expression given that the current token is not 'super'. |
| 6041 * The [primaryAllowed] is `true` if the expression is allowed to be a primary | 6016 * The [primaryAllowed] is `true` if the expression is allowed to be a primary |
| 6042 * without any assignable selector. Return the assignable expression that was | 6017 * without any assignable selector. Return the assignable expression that was |
| 6043 * parsed. | 6018 * parsed. |
| 6044 */ | 6019 */ |
| 6045 Expression _parseAssignableExpressionNotStartingWithSuper( | 6020 Expression _parseAssignableExpressionNotStartingWithSuper( |
| 6046 bool primaryAllowed) { | 6021 bool primaryAllowed) { |
| 6047 // | 6022 // |
| 6048 // A primary expression can start with an identifier. We resolve the | 6023 // A primary expression can start with an identifier. We resolve the |
| 6049 // ambiguity by determining whether the primary consists of anything other | 6024 // ambiguity by determining whether the primary consists of anything other |
| 6050 // than an identifier and/or is followed by an assignableSelector. | 6025 // than an identifier and/or is followed by an assignableSelector. |
| 6051 // | 6026 // |
| 6052 Expression expression = parsePrimaryExpression(); | 6027 Expression expression = parsePrimaryExpression(); |
| 6053 bool isOptional = primaryAllowed || expression is SimpleIdentifier; | 6028 bool isOptional = primaryAllowed || expression is SimpleIdentifier; |
| 6054 while (true) { | 6029 while (true) { |
| 6055 while (_isLikelyArgumentList()) { | 6030 while (_isLikelyArgumentList()) { |
| 6056 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); | 6031 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); |
| 6057 ArgumentList argumentList = parseArgumentList(); | 6032 ArgumentList argumentList = parseArgumentList(); |
| 6058 Expression currentExpression = expression; | 6033 Expression currentExpression = expression; |
| 6059 if (currentExpression is SimpleIdentifier) { | 6034 if (currentExpression is SimpleIdentifier) { |
| 6060 expression = astFactory.methodInvocation( | 6035 expression = new MethodInvocation( |
| 6061 null, null, currentExpression, typeArguments, argumentList); | 6036 null, null, currentExpression, typeArguments, argumentList); |
| 6062 } else if (currentExpression is PrefixedIdentifier) { | 6037 } else if (currentExpression is PrefixedIdentifier) { |
| 6063 expression = astFactory.methodInvocation( | 6038 expression = new MethodInvocation( |
| 6064 currentExpression.prefix, | 6039 currentExpression.prefix, |
| 6065 currentExpression.period, | 6040 currentExpression.period, |
| 6066 currentExpression.identifier, | 6041 currentExpression.identifier, |
| 6067 typeArguments, | 6042 typeArguments, |
| 6068 argumentList); | 6043 argumentList); |
| 6069 } else if (currentExpression is PropertyAccess) { | 6044 } else if (currentExpression is PropertyAccess) { |
| 6070 expression = astFactory.methodInvocation( | 6045 expression = new MethodInvocation( |
| 6071 currentExpression.target, | 6046 currentExpression.target, |
| 6072 currentExpression.operator, | 6047 currentExpression.operator, |
| 6073 currentExpression.propertyName, | 6048 currentExpression.propertyName, |
| 6074 typeArguments, | 6049 typeArguments, |
| 6075 argumentList); | 6050 argumentList); |
| 6076 } else { | 6051 } else { |
| 6077 expression = astFactory.functionExpressionInvocation( | 6052 expression = new FunctionExpressionInvocation( |
| 6078 expression, typeArguments, argumentList); | 6053 expression, typeArguments, argumentList); |
| 6079 } | 6054 } |
| 6080 if (!primaryAllowed) { | 6055 if (!primaryAllowed) { |
| 6081 isOptional = false; | 6056 isOptional = false; |
| 6082 } | 6057 } |
| 6083 } | 6058 } |
| 6084 Expression selectorExpression = parseAssignableSelector( | 6059 Expression selectorExpression = parseAssignableSelector( |
| 6085 expression, isOptional || (expression is PrefixedIdentifier)); | 6060 expression, isOptional || (expression is PrefixedIdentifier)); |
| 6086 if (identical(selectorExpression, expression)) { | 6061 if (identical(selectorExpression, expression)) { |
| 6087 if (!isOptional && (expression is PrefixedIdentifier)) { | 6062 if (!isOptional && (expression is PrefixedIdentifier)) { |
| 6088 PrefixedIdentifier identifier = expression as PrefixedIdentifier; | 6063 PrefixedIdentifier identifier = expression as PrefixedIdentifier; |
| 6089 expression = astFactory.propertyAccess( | 6064 expression = new PropertyAccess( |
| 6090 identifier.prefix, identifier.period, identifier.identifier); | 6065 identifier.prefix, identifier.period, identifier.identifier); |
| 6091 } | 6066 } |
| 6092 return expression; | 6067 return expression; |
| 6093 } | 6068 } |
| 6094 expression = selectorExpression; | 6069 expression = selectorExpression; |
| 6095 isOptional = true; | 6070 isOptional = true; |
| 6096 } | 6071 } |
| 6097 } | 6072 } |
| 6098 | 6073 |
| 6099 /** | 6074 /** |
| 6100 * Parse a block when we need to check for an open curly brace and recover | 6075 * Parse a block when we need to check for an open curly brace and recover |
| 6101 * when there isn't one. Return the block that was parsed. | 6076 * when there isn't one. Return the block that was parsed. |
| 6102 * | 6077 * |
| 6103 * block ::= | 6078 * block ::= |
| 6104 * '{' statements '}' | 6079 * '{' statements '}' |
| 6105 */ | 6080 */ |
| 6106 Block _parseBlockChecked() { | 6081 Block _parseBlockChecked() { |
| 6107 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { | 6082 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { |
| 6108 return parseBlock(); | 6083 return parseBlock(); |
| 6109 } | 6084 } |
| 6110 // TODO(brianwilkerson) Improve the error message. | 6085 // TODO(brianwilkerson) Improve the error message. |
| 6111 _reportErrorForCurrentToken( | 6086 _reportErrorForCurrentToken( |
| 6112 ParserErrorCode.EXPECTED_TOKEN, [TokenType.OPEN_CURLY_BRACKET.lexeme]); | 6087 ParserErrorCode.EXPECTED_TOKEN, [TokenType.OPEN_CURLY_BRACKET.lexeme]); |
| 6113 // Recovery: Check for an unmatched closing curly bracket and parse | 6088 // Recovery: Check for an unmatched closing curly bracket and parse |
| 6114 // statements until it is reached. | 6089 // statements until it is reached. |
| 6115 return astFactory.block(_createSyntheticToken(TokenType.OPEN_CURLY_BRACKET), | 6090 return new Block(_createSyntheticToken(TokenType.OPEN_CURLY_BRACKET), null, |
| 6116 null, _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET)); | 6091 _createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET)); |
| 6117 } | 6092 } |
| 6118 | 6093 |
| 6119 /** | 6094 /** |
| 6120 * Parse a list of class members. The [className] is the name of the class | 6095 * Parse a list of class members. The [className] is the name of the class |
| 6121 * whose members are being parsed. The [closingBracket] is the closing bracket | 6096 * whose members are being parsed. The [closingBracket] is the closing bracket |
| 6122 * for the class, or `null` if the closing bracket is missing. Return the list | 6097 * for the class, or `null` if the closing bracket is missing. Return the list |
| 6123 * of class members that were parsed. | 6098 * of class members that were parsed. |
| 6124 * | 6099 * |
| 6125 * classMembers ::= | 6100 * classMembers ::= |
| 6126 * (metadata memberDefinition)* | 6101 * (metadata memberDefinition)* |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6198 ParserErrorCode.EXPECTED_TOKEN, [TokenType.SEMICOLON.lexeme]); | 6173 ParserErrorCode.EXPECTED_TOKEN, [TokenType.SEMICOLON.lexeme]); |
| 6199 Token leftBracket = getAndAdvance(); | 6174 Token leftBracket = getAndAdvance(); |
| 6200 _parseClassMembers(className.name, _getEndToken(leftBracket)); | 6175 _parseClassMembers(className.name, _getEndToken(leftBracket)); |
| 6201 _expect(TokenType.CLOSE_CURLY_BRACKET); | 6176 _expect(TokenType.CLOSE_CURLY_BRACKET); |
| 6202 } else { | 6177 } else { |
| 6203 _reportErrorForToken(ParserErrorCode.EXPECTED_TOKEN, | 6178 _reportErrorForToken(ParserErrorCode.EXPECTED_TOKEN, |
| 6204 _currentToken.previous, [TokenType.SEMICOLON.lexeme]); | 6179 _currentToken.previous, [TokenType.SEMICOLON.lexeme]); |
| 6205 } | 6180 } |
| 6206 semicolon = _createSyntheticToken(TokenType.SEMICOLON); | 6181 semicolon = _createSyntheticToken(TokenType.SEMICOLON); |
| 6207 } | 6182 } |
| 6208 return astFactory.classTypeAlias( | 6183 return new ClassTypeAlias( |
| 6209 commentAndMetadata.comment, | 6184 commentAndMetadata.comment, |
| 6210 commentAndMetadata.metadata, | 6185 commentAndMetadata.metadata, |
| 6211 classKeyword, | 6186 classKeyword, |
| 6212 className, | 6187 className, |
| 6213 typeParameters, | 6188 typeParameters, |
| 6214 equals, | 6189 equals, |
| 6215 abstractKeyword, | 6190 abstractKeyword, |
| 6216 superclass, | 6191 superclass, |
| 6217 withClause, | 6192 withClause, |
| 6218 implementsClause, | 6193 implementsClause, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6276 if (factoryKeyword != null) { | 6251 if (factoryKeyword != null) { |
| 6277 _reportErrorForToken( | 6252 _reportErrorForToken( |
| 6278 ParserErrorCode.FACTORY_WITH_INITIALIZERS, factoryKeyword); | 6253 ParserErrorCode.FACTORY_WITH_INITIALIZERS, factoryKeyword); |
| 6279 } | 6254 } |
| 6280 } | 6255 } |
| 6281 ConstructorName redirectedConstructor = null; | 6256 ConstructorName redirectedConstructor = null; |
| 6282 FunctionBody body; | 6257 FunctionBody body; |
| 6283 if (_matches(TokenType.EQ)) { | 6258 if (_matches(TokenType.EQ)) { |
| 6284 separator = getAndAdvance(); | 6259 separator = getAndAdvance(); |
| 6285 redirectedConstructor = parseConstructorName(); | 6260 redirectedConstructor = parseConstructorName(); |
| 6286 body = astFactory.emptyFunctionBody(_expect(TokenType.SEMICOLON)); | 6261 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON)); |
| 6287 if (factoryKeyword == null) { | 6262 if (factoryKeyword == null) { |
| 6288 _reportErrorForNode( | 6263 _reportErrorForNode( |
| 6289 ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, | 6264 ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, |
| 6290 redirectedConstructor); | 6265 redirectedConstructor); |
| 6291 } | 6266 } |
| 6292 } else { | 6267 } else { |
| 6293 body = | 6268 body = |
| 6294 parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, false); | 6269 parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, false); |
| 6295 if (constKeyword != null && | 6270 if (constKeyword != null && |
| 6296 factoryKeyword != null && | 6271 factoryKeyword != null && |
| (...skipping 13 matching lines...) Expand all Loading... |
| 6310 ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body); | 6285 ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body); |
| 6311 } else if (externalKeyword != null) { | 6286 } else if (externalKeyword != null) { |
| 6312 _reportErrorForNode( | 6287 _reportErrorForNode( |
| 6313 ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, body); | 6288 ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, body); |
| 6314 } else if (!bodyAllowed) { | 6289 } else if (!bodyAllowed) { |
| 6315 _reportErrorForNode( | 6290 _reportErrorForNode( |
| 6316 ParserErrorCode.REDIRECTING_CONSTRUCTOR_WITH_BODY, body); | 6291 ParserErrorCode.REDIRECTING_CONSTRUCTOR_WITH_BODY, body); |
| 6317 } | 6292 } |
| 6318 } | 6293 } |
| 6319 } | 6294 } |
| 6320 return astFactory.constructorDeclaration( | 6295 return new ConstructorDeclaration( |
| 6321 commentAndMetadata.comment, | 6296 commentAndMetadata.comment, |
| 6322 commentAndMetadata.metadata, | 6297 commentAndMetadata.metadata, |
| 6323 externalKeyword, | 6298 externalKeyword, |
| 6324 constKeyword, | 6299 constKeyword, |
| 6325 factoryKeyword, | 6300 factoryKeyword, |
| 6326 returnType, | 6301 returnType, |
| 6327 period, | 6302 period, |
| 6328 name, | 6303 name, |
| 6329 parameters, | 6304 parameters, |
| 6330 separator, | 6305 separator, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 6352 SimpleIdentifier name; | 6327 SimpleIdentifier name; |
| 6353 if (_matchesIdentifier()) { | 6328 if (_matchesIdentifier()) { |
| 6354 name = _parseSimpleIdentifierUnchecked(isDeclaration: true); | 6329 name = _parseSimpleIdentifierUnchecked(isDeclaration: true); |
| 6355 } else { | 6330 } else { |
| 6356 name = createSyntheticIdentifier(); | 6331 name = createSyntheticIdentifier(); |
| 6357 } | 6332 } |
| 6358 if (commentAndMetadata.hasMetadata) { | 6333 if (commentAndMetadata.hasMetadata) { |
| 6359 _reportErrorForNode(ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT, | 6334 _reportErrorForNode(ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT, |
| 6360 commentAndMetadata.metadata[0]); | 6335 commentAndMetadata.metadata[0]); |
| 6361 } | 6336 } |
| 6362 return astFactory.enumConstantDeclaration( | 6337 return new EnumConstantDeclaration( |
| 6363 commentAndMetadata.comment, commentAndMetadata.metadata, name); | 6338 commentAndMetadata.comment, commentAndMetadata.metadata, name); |
| 6364 } | 6339 } |
| 6365 | 6340 |
| 6366 /** | 6341 /** |
| 6367 * Parse a list of formal parameters given that the list starts with the given | 6342 * Parse a list of formal parameters given that the list starts with the given |
| 6368 * [leftParenthesis]. Return the formal parameters that were parsed. | 6343 * [leftParenthesis]. Return the formal parameters that were parsed. |
| 6369 */ | 6344 */ |
| 6370 FormalParameterList _parseFormalParameterListAfterParen( | 6345 FormalParameterList _parseFormalParameterListAfterParen( |
| 6371 Token leftParenthesis) { | 6346 Token leftParenthesis) { |
| 6372 if (_matches(TokenType.CLOSE_PAREN)) { | 6347 if (_matches(TokenType.CLOSE_PAREN)) { |
| 6373 return astFactory.formalParameterList( | 6348 return new FormalParameterList( |
| 6374 leftParenthesis, null, null, null, getAndAdvance()); | 6349 leftParenthesis, null, null, null, getAndAdvance()); |
| 6375 } | 6350 } |
| 6376 // | 6351 // |
| 6377 // Even though it is invalid to have default parameters outside of brackets, | 6352 // Even though it is invalid to have default parameters outside of brackets, |
| 6378 // required parameters inside of brackets, or multiple groups of default and | 6353 // required parameters inside of brackets, or multiple groups of default and |
| 6379 // named parameters, we allow all of these cases so that we can recover | 6354 // named parameters, we allow all of these cases so that we can recover |
| 6380 // better. | 6355 // better. |
| 6381 // | 6356 // |
| 6382 List<FormalParameter> parameters = <FormalParameter>[]; | 6357 List<FormalParameter> parameters = <FormalParameter>[]; |
| 6383 Token leftSquareBracket = null; | 6358 Token leftSquareBracket = null; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6513 } | 6488 } |
| 6514 if (leftCurlyBracket != null && rightCurlyBracket == null) { | 6489 if (leftCurlyBracket != null && rightCurlyBracket == null) { |
| 6515 _reportErrorForCurrentToken( | 6490 _reportErrorForCurrentToken( |
| 6516 ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["}"]); | 6491 ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["}"]); |
| 6517 } | 6492 } |
| 6518 // | 6493 // |
| 6519 // Build the parameter list. | 6494 // Build the parameter list. |
| 6520 // | 6495 // |
| 6521 leftSquareBracket ??= leftCurlyBracket; | 6496 leftSquareBracket ??= leftCurlyBracket; |
| 6522 rightSquareBracket ??= rightCurlyBracket; | 6497 rightSquareBracket ??= rightCurlyBracket; |
| 6523 return astFactory.formalParameterList(leftParenthesis, parameters, | 6498 return new FormalParameterList(leftParenthesis, parameters, |
| 6524 leftSquareBracket, rightSquareBracket, rightParenthesis); | 6499 leftSquareBracket, rightSquareBracket, rightParenthesis); |
| 6525 } | 6500 } |
| 6526 | 6501 |
| 6527 /** | 6502 /** |
| 6528 * Parse a list of formal parameters. Return the formal parameters that were | 6503 * Parse a list of formal parameters. Return the formal parameters that were |
| 6529 * parsed. | 6504 * parsed. |
| 6530 * | 6505 * |
| 6531 * This method assumes that the current token matches `TokenType.OPEN_PAREN`. | 6506 * This method assumes that the current token matches `TokenType.OPEN_PAREN`. |
| 6532 */ | 6507 */ |
| 6533 FormalParameterList _parseFormalParameterListUnchecked() { | 6508 FormalParameterList _parseFormalParameterListUnchecked() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 6550 Token propertyKeyword = declaration.propertyKeyword; | 6525 Token propertyKeyword = declaration.propertyKeyword; |
| 6551 if (propertyKeyword != null) { | 6526 if (propertyKeyword != null) { |
| 6552 if (propertyKeyword.keyword == Keyword.GET) { | 6527 if (propertyKeyword.keyword == Keyword.GET) { |
| 6553 _reportErrorForToken( | 6528 _reportErrorForToken( |
| 6554 ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword); | 6529 ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword); |
| 6555 } else { | 6530 } else { |
| 6556 _reportErrorForToken( | 6531 _reportErrorForToken( |
| 6557 ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword); | 6532 ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword); |
| 6558 } | 6533 } |
| 6559 } | 6534 } |
| 6560 return astFactory.functionDeclarationStatement(declaration); | 6535 return new FunctionDeclarationStatement(declaration); |
| 6561 } | 6536 } |
| 6562 | 6537 |
| 6563 /** | 6538 /** |
| 6564 * Parse a function type alias. The [commentAndMetadata] is the metadata to be | 6539 * Parse a function type alias. The [commentAndMetadata] is the metadata to be |
| 6565 * associated with the member. The [keyword] is the token representing the | 6540 * associated with the member. The [keyword] is the token representing the |
| 6566 * 'typedef' keyword. Return the function type alias that was parsed. | 6541 * 'typedef' keyword. Return the function type alias that was parsed. |
| 6567 * | 6542 * |
| 6568 * functionTypeAlias ::= | 6543 * functionTypeAlias ::= |
| 6569 * functionPrefix typeParameterList? formalParameterList ';' | 6544 * functionPrefix typeParameterList? formalParameterList ';' |
| 6570 * | 6545 * |
| 6571 * functionPrefix ::= | 6546 * functionPrefix ::= |
| 6572 * returnType? name | 6547 * returnType? name |
| 6573 */ | 6548 */ |
| 6574 FunctionTypeAlias _parseFunctionTypeAlias( | 6549 FunctionTypeAlias _parseFunctionTypeAlias( |
| 6575 CommentAndMetadata commentAndMetadata, Token keyword) { | 6550 CommentAndMetadata commentAndMetadata, Token keyword) { |
| 6576 TypeName returnType = null; | 6551 TypeName returnType = null; |
| 6577 if (hasReturnTypeInTypeAlias) { | 6552 if (hasReturnTypeInTypeAlias) { |
| 6578 returnType = parseReturnType(); | 6553 returnType = parseReturnType(); |
| 6579 } | 6554 } |
| 6580 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true); | 6555 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true); |
| 6581 TypeParameterList typeParameters = null; | 6556 TypeParameterList typeParameters = null; |
| 6582 if (_matches(TokenType.LT)) { | 6557 if (_matches(TokenType.LT)) { |
| 6583 typeParameters = parseTypeParameterList(); | 6558 typeParameters = parseTypeParameterList(); |
| 6584 } | 6559 } |
| 6585 TokenType type = _currentToken.type; | 6560 TokenType type = _currentToken.type; |
| 6586 if (type == TokenType.SEMICOLON || type == TokenType.EOF) { | 6561 if (type == TokenType.SEMICOLON || type == TokenType.EOF) { |
| 6587 _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS); | 6562 _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS); |
| 6588 FormalParameterList parameters = astFactory.formalParameterList( | 6563 FormalParameterList parameters = new FormalParameterList( |
| 6589 _createSyntheticToken(TokenType.OPEN_PAREN), | 6564 _createSyntheticToken(TokenType.OPEN_PAREN), |
| 6590 null, | 6565 null, |
| 6591 null, | 6566 null, |
| 6592 null, | 6567 null, |
| 6593 _createSyntheticToken(TokenType.CLOSE_PAREN)); | 6568 _createSyntheticToken(TokenType.CLOSE_PAREN)); |
| 6594 Token semicolon = _expect(TokenType.SEMICOLON); | 6569 Token semicolon = _expect(TokenType.SEMICOLON); |
| 6595 return astFactory.functionTypeAlias( | 6570 return new FunctionTypeAlias( |
| 6596 commentAndMetadata.comment, | 6571 commentAndMetadata.comment, |
| 6597 commentAndMetadata.metadata, | 6572 commentAndMetadata.metadata, |
| 6598 keyword, | 6573 keyword, |
| 6599 returnType, | 6574 returnType, |
| 6600 name, | 6575 name, |
| 6601 typeParameters, | 6576 typeParameters, |
| 6602 parameters, | 6577 parameters, |
| 6603 semicolon); | 6578 semicolon); |
| 6604 } else if (type == TokenType.OPEN_PAREN) { | 6579 } else if (type == TokenType.OPEN_PAREN) { |
| 6605 FormalParameterList parameters = _parseFormalParameterListUnchecked(); | 6580 FormalParameterList parameters = _parseFormalParameterListUnchecked(); |
| 6606 _validateFormalParameterList(parameters); | 6581 _validateFormalParameterList(parameters); |
| 6607 Token semicolon = _expect(TokenType.SEMICOLON); | 6582 Token semicolon = _expect(TokenType.SEMICOLON); |
| 6608 return astFactory.functionTypeAlias( | 6583 return new FunctionTypeAlias( |
| 6609 commentAndMetadata.comment, | 6584 commentAndMetadata.comment, |
| 6610 commentAndMetadata.metadata, | 6585 commentAndMetadata.metadata, |
| 6611 keyword, | 6586 keyword, |
| 6612 returnType, | 6587 returnType, |
| 6613 name, | 6588 name, |
| 6614 typeParameters, | 6589 typeParameters, |
| 6615 parameters, | 6590 parameters, |
| 6616 semicolon); | 6591 semicolon); |
| 6617 } else { | 6592 } else { |
| 6618 _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS); | 6593 _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS); |
| 6619 // Recovery: At the very least we should skip to the start of the next | 6594 // Recovery: At the very least we should skip to the start of the next |
| 6620 // valid compilation unit member, allowing for the possibility of finding | 6595 // valid compilation unit member, allowing for the possibility of finding |
| 6621 // the typedef parameters before that point. | 6596 // the typedef parameters before that point. |
| 6622 return astFactory.functionTypeAlias( | 6597 return new FunctionTypeAlias( |
| 6623 commentAndMetadata.comment, | 6598 commentAndMetadata.comment, |
| 6624 commentAndMetadata.metadata, | 6599 commentAndMetadata.metadata, |
| 6625 keyword, | 6600 keyword, |
| 6626 returnType, | 6601 returnType, |
| 6627 name, | 6602 name, |
| 6628 typeParameters, | 6603 typeParameters, |
| 6629 astFactory.formalParameterList( | 6604 new FormalParameterList(_createSyntheticToken(TokenType.OPEN_PAREN), |
| 6630 _createSyntheticToken(TokenType.OPEN_PAREN), | 6605 null, null, null, _createSyntheticToken(TokenType.CLOSE_PAREN)), |
| 6631 null, | |
| 6632 null, | |
| 6633 null, | |
| 6634 _createSyntheticToken(TokenType.CLOSE_PAREN)), | |
| 6635 _createSyntheticToken(TokenType.SEMICOLON)); | 6606 _createSyntheticToken(TokenType.SEMICOLON)); |
| 6636 } | 6607 } |
| 6637 } | 6608 } |
| 6638 | 6609 |
| 6639 /** | 6610 /** |
| 6640 * Parses generic type parameters from a comment. | 6611 * Parses generic type parameters from a comment. |
| 6641 * | 6612 * |
| 6642 * Normally this is handled by [_parseGenericMethodTypeParameters], but if the | 6613 * Normally this is handled by [_parseGenericMethodTypeParameters], but if the |
| 6643 * code already handles the normal generic type parameters, the comment | 6614 * code already handles the normal generic type parameters, the comment |
| 6644 * matcher can be called directly. For example, we may have already tried | 6615 * matcher can be called directly. For example, we may have already tried |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6680 if (_matchesIdentifier()) { | 6651 if (_matchesIdentifier()) { |
| 6681 return parseLibraryIdentifier(); | 6652 return parseLibraryIdentifier(); |
| 6682 } else if (_matches(TokenType.STRING)) { | 6653 } else if (_matches(TokenType.STRING)) { |
| 6683 // Recovery: This should be extended to handle arbitrary tokens until we | 6654 // Recovery: This should be extended to handle arbitrary tokens until we |
| 6684 // can find a token that can start a compilation unit member. | 6655 // can find a token that can start a compilation unit member. |
| 6685 StringLiteral string = parseStringLiteral(); | 6656 StringLiteral string = parseStringLiteral(); |
| 6686 _reportErrorForNode(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string); | 6657 _reportErrorForNode(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string); |
| 6687 } else { | 6658 } else { |
| 6688 _reportErrorForToken(missingNameError, missingNameToken); | 6659 _reportErrorForToken(missingNameError, missingNameToken); |
| 6689 } | 6660 } |
| 6690 return astFactory | 6661 return new LibraryIdentifier( |
| 6691 .libraryIdentifier(<SimpleIdentifier>[createSyntheticIdentifier()]); | 6662 <SimpleIdentifier>[createSyntheticIdentifier()]); |
| 6692 } | 6663 } |
| 6693 | 6664 |
| 6694 /** | 6665 /** |
| 6695 * Parse a method declaration. The [commentAndMetadata] is the documentation | 6666 * Parse a method declaration. The [commentAndMetadata] is the documentation |
| 6696 * comment and metadata to be associated with the declaration. The | 6667 * comment and metadata to be associated with the declaration. The |
| 6697 * [externalKeyword] is the 'external' token. The [staticKeyword] is the | 6668 * [externalKeyword] is the 'external' token. The [staticKeyword] is the |
| 6698 * static keyword, or `null` if the getter is not static. The [returnType] is | 6669 * static keyword, or `null` if the getter is not static. The [returnType] is |
| 6699 * the return type of the method. The [name] is the name of the method. The | 6670 * the return type of the method. The [name] is the name of the method. The |
| 6700 * [parameters] is the parameters to the method. Return the method declaration | 6671 * [parameters] is the parameters to the method. Return the method declaration |
| 6701 * that was parsed. | 6672 * that was parsed. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 6718 false); | 6689 false); |
| 6719 if (externalKeyword != null) { | 6690 if (externalKeyword != null) { |
| 6720 if (body is! EmptyFunctionBody) { | 6691 if (body is! EmptyFunctionBody) { |
| 6721 _reportErrorForNode(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body); | 6692 _reportErrorForNode(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body); |
| 6722 } | 6693 } |
| 6723 } else if (staticKeyword != null) { | 6694 } else if (staticKeyword != null) { |
| 6724 if (body is EmptyFunctionBody && _parseFunctionBodies) { | 6695 if (body is EmptyFunctionBody && _parseFunctionBodies) { |
| 6725 _reportErrorForNode(ParserErrorCode.ABSTRACT_STATIC_METHOD, body); | 6696 _reportErrorForNode(ParserErrorCode.ABSTRACT_STATIC_METHOD, body); |
| 6726 } | 6697 } |
| 6727 } | 6698 } |
| 6728 return astFactory.methodDeclaration( | 6699 return new MethodDeclaration( |
| 6729 commentAndMetadata.comment, | 6700 commentAndMetadata.comment, |
| 6730 commentAndMetadata.metadata, | 6701 commentAndMetadata.metadata, |
| 6731 externalKeyword, | 6702 externalKeyword, |
| 6732 staticKeyword, | 6703 staticKeyword, |
| 6733 returnType, | 6704 returnType, |
| 6734 null, | 6705 null, |
| 6735 null, | 6706 null, |
| 6736 name, | 6707 name, |
| 6737 typeParameters, | 6708 typeParameters, |
| 6738 parameters, | 6709 parameters, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6759 SimpleIdentifier methodName = parseSimpleIdentifier(isDeclaration: true); | 6730 SimpleIdentifier methodName = parseSimpleIdentifier(isDeclaration: true); |
| 6760 TypeParameterList typeParameters = _parseGenericMethodTypeParameters(); | 6731 TypeParameterList typeParameters = _parseGenericMethodTypeParameters(); |
| 6761 FormalParameterList parameters; | 6732 FormalParameterList parameters; |
| 6762 TokenType type = _currentToken.type; | 6733 TokenType type = _currentToken.type; |
| 6763 // TODO(brianwilkerson) Figure out why we care what the current token is if | 6734 // TODO(brianwilkerson) Figure out why we care what the current token is if |
| 6764 // it isn't a paren. | 6735 // it isn't a paren. |
| 6765 if (type != TokenType.OPEN_PAREN && | 6736 if (type != TokenType.OPEN_PAREN && |
| 6766 (type == TokenType.OPEN_CURLY_BRACKET || type == TokenType.FUNCTION)) { | 6737 (type == TokenType.OPEN_CURLY_BRACKET || type == TokenType.FUNCTION)) { |
| 6767 _reportErrorForToken( | 6738 _reportErrorForToken( |
| 6768 ParserErrorCode.MISSING_METHOD_PARAMETERS, _currentToken.previous); | 6739 ParserErrorCode.MISSING_METHOD_PARAMETERS, _currentToken.previous); |
| 6769 parameters = astFactory.formalParameterList( | 6740 parameters = new FormalParameterList( |
| 6770 _createSyntheticToken(TokenType.OPEN_PAREN), | 6741 _createSyntheticToken(TokenType.OPEN_PAREN), |
| 6771 null, | 6742 null, |
| 6772 null, | 6743 null, |
| 6773 null, | 6744 null, |
| 6774 _createSyntheticToken(TokenType.CLOSE_PAREN)); | 6745 _createSyntheticToken(TokenType.CLOSE_PAREN)); |
| 6775 } else { | 6746 } else { |
| 6776 parameters = parseFormalParameterList(); | 6747 parameters = parseFormalParameterList(); |
| 6777 } | 6748 } |
| 6778 _validateFormalParameterList(parameters); | 6749 _validateFormalParameterList(parameters); |
| 6779 return _parseMethodDeclarationAfterParameters( | 6750 return _parseMethodDeclarationAfterParameters( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6790 * Parse a class native clause. Return the native clause that was parsed. | 6761 * Parse a class native clause. Return the native clause that was parsed. |
| 6791 * | 6762 * |
| 6792 * This method assumes that the current token matches `_NATIVE`. | 6763 * This method assumes that the current token matches `_NATIVE`. |
| 6793 * | 6764 * |
| 6794 * classNativeClause ::= | 6765 * classNativeClause ::= |
| 6795 * 'native' name | 6766 * 'native' name |
| 6796 */ | 6767 */ |
| 6797 NativeClause _parseNativeClause() { | 6768 NativeClause _parseNativeClause() { |
| 6798 Token keyword = getAndAdvance(); | 6769 Token keyword = getAndAdvance(); |
| 6799 StringLiteral name = parseStringLiteral(); | 6770 StringLiteral name = parseStringLiteral(); |
| 6800 return astFactory.nativeClause(keyword, name); | 6771 return new NativeClause(keyword, name); |
| 6801 } | 6772 } |
| 6802 | 6773 |
| 6803 /** | 6774 /** |
| 6804 * Parse an operator declaration starting after the 'operator' keyword. The | 6775 * Parse an operator declaration starting after the 'operator' keyword. The |
| 6805 * [commentAndMetadata] is the documentation comment and metadata to be | 6776 * [commentAndMetadata] is the documentation comment and metadata to be |
| 6806 * associated with the declaration. The [externalKeyword] is the 'external' | 6777 * associated with the declaration. The [externalKeyword] is the 'external' |
| 6807 * token. The [returnType] is the return type that has already been parsed, or | 6778 * token. The [returnType] is the return type that has already been parsed, or |
| 6808 * `null` if there was no return type. The [operatorKeyword] is the 'operator' | 6779 * `null` if there was no return type. The [operatorKeyword] is the 'operator' |
| 6809 * keyword. Return the operator declaration that was parsed. | 6780 * keyword. Return the operator declaration that was parsed. |
| 6810 * | 6781 * |
| 6811 * operatorDeclaration ::= | 6782 * operatorDeclaration ::= |
| 6812 * operatorSignature (';' | functionBody) | 6783 * operatorSignature (';' | functionBody) |
| 6813 * | 6784 * |
| 6814 * operatorSignature ::= | 6785 * operatorSignature ::= |
| 6815 * 'external'? returnType? 'operator' operator formalParameterList | 6786 * 'external'? returnType? 'operator' operator formalParameterList |
| 6816 */ | 6787 */ |
| 6817 MethodDeclaration _parseOperatorAfterKeyword( | 6788 MethodDeclaration _parseOperatorAfterKeyword( |
| 6818 CommentAndMetadata commentAndMetadata, | 6789 CommentAndMetadata commentAndMetadata, |
| 6819 Token externalKeyword, | 6790 Token externalKeyword, |
| 6820 TypeName returnType, | 6791 TypeName returnType, |
| 6821 Token operatorKeyword) { | 6792 Token operatorKeyword) { |
| 6822 if (!_currentToken.isUserDefinableOperator) { | 6793 if (!_currentToken.isUserDefinableOperator) { |
| 6823 _reportErrorForCurrentToken( | 6794 _reportErrorForCurrentToken( |
| 6824 ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken.lexeme]); | 6795 ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken.lexeme]); |
| 6825 } | 6796 } |
| 6826 SimpleIdentifier name = | 6797 SimpleIdentifier name = |
| 6827 astFactory.simpleIdentifier(getAndAdvance(), isDeclaration: true); | 6798 new SimpleIdentifier(getAndAdvance(), isDeclaration: true); |
| 6828 if (_matches(TokenType.EQ)) { | 6799 if (_matches(TokenType.EQ)) { |
| 6829 Token previous = _currentToken.previous; | 6800 Token previous = _currentToken.previous; |
| 6830 if ((_tokenMatches(previous, TokenType.EQ_EQ) || | 6801 if ((_tokenMatches(previous, TokenType.EQ_EQ) || |
| 6831 _tokenMatches(previous, TokenType.BANG_EQ)) && | 6802 _tokenMatches(previous, TokenType.BANG_EQ)) && |
| 6832 _currentToken.offset == previous.offset + 2) { | 6803 _currentToken.offset == previous.offset + 2) { |
| 6833 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR, | 6804 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR, |
| 6834 ["${previous.lexeme}${_currentToken.lexeme}"]); | 6805 ["${previous.lexeme}${_currentToken.lexeme}"]); |
| 6835 _advance(); | 6806 _advance(); |
| 6836 } | 6807 } |
| 6837 } | 6808 } |
| 6838 FormalParameterList parameters = parseFormalParameterList(); | 6809 FormalParameterList parameters = parseFormalParameterList(); |
| 6839 _validateFormalParameterList(parameters); | 6810 _validateFormalParameterList(parameters); |
| 6840 FunctionBody body = | 6811 FunctionBody body = |
| 6841 parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, false); | 6812 parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, false); |
| 6842 if (externalKeyword != null && body is! EmptyFunctionBody) { | 6813 if (externalKeyword != null && body is! EmptyFunctionBody) { |
| 6843 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY); | 6814 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY); |
| 6844 } | 6815 } |
| 6845 return astFactory.methodDeclaration( | 6816 return new MethodDeclaration( |
| 6846 commentAndMetadata.comment, | 6817 commentAndMetadata.comment, |
| 6847 commentAndMetadata.metadata, | 6818 commentAndMetadata.metadata, |
| 6848 externalKeyword, | 6819 externalKeyword, |
| 6849 null, | 6820 null, |
| 6850 returnType, | 6821 returnType, |
| 6851 null, | 6822 null, |
| 6852 operatorKeyword, | 6823 operatorKeyword, |
| 6853 name, | 6824 name, |
| 6854 null, | 6825 null, |
| 6855 parameters, | 6826 parameters, |
| 6856 body); | 6827 body); |
| 6857 } | 6828 } |
| 6858 | 6829 |
| 6859 /** | 6830 /** |
| 6860 * Parse a return type if one is given, otherwise return `null` without | 6831 * Parse a return type if one is given, otherwise return `null` without |
| 6861 * advancing. Return the return type that was parsed. | 6832 * advancing. Return the return type that was parsed. |
| 6862 */ | 6833 */ |
| 6863 TypeName _parseOptionalReturnType() { | 6834 TypeName _parseOptionalReturnType() { |
| 6864 TypeName typeComment = _parseOptionalTypeNameComment(); | 6835 TypeName typeComment = _parseOptionalTypeNameComment(); |
| 6865 if (typeComment != null) { | 6836 if (typeComment != null) { |
| 6866 return typeComment; | 6837 return typeComment; |
| 6867 } | 6838 } |
| 6868 Keyword keyword = _currentToken.keyword; | 6839 Keyword keyword = _currentToken.keyword; |
| 6869 if (keyword == Keyword.VOID) { | 6840 if (keyword == Keyword.VOID) { |
| 6870 return astFactory.typeName( | 6841 return new TypeName(new SimpleIdentifier(getAndAdvance()), null); |
| 6871 astFactory.simpleIdentifier(getAndAdvance()), null); | |
| 6872 } else if (_matchesIdentifier()) { | 6842 } else if (_matchesIdentifier()) { |
| 6873 Token next = _peek(); | 6843 Token next = _peek(); |
| 6874 if (keyword != Keyword.GET && | 6844 if (keyword != Keyword.GET && |
| 6875 keyword != Keyword.SET && | 6845 keyword != Keyword.SET && |
| 6876 keyword != Keyword.OPERATOR && | 6846 keyword != Keyword.OPERATOR && |
| 6877 (_tokenMatchesIdentifier(next) || | 6847 (_tokenMatchesIdentifier(next) || |
| 6878 _tokenMatches(next, TokenType.LT))) { | 6848 _tokenMatches(next, TokenType.LT))) { |
| 6879 return parseReturnType(); | 6849 return parseReturnType(); |
| 6880 } | 6850 } |
| 6881 Token next2 = next.next; | 6851 Token next2 = next.next; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6915 * | 6885 * |
| 6916 * This method assumes that the current token matches `Keyword.PART`. | 6886 * This method assumes that the current token matches `Keyword.PART`. |
| 6917 * | 6887 * |
| 6918 * partDirective ::= | 6888 * partDirective ::= |
| 6919 * metadata 'part' stringLiteral ';' | 6889 * metadata 'part' stringLiteral ';' |
| 6920 */ | 6890 */ |
| 6921 Directive _parsePartDirective(CommentAndMetadata commentAndMetadata) { | 6891 Directive _parsePartDirective(CommentAndMetadata commentAndMetadata) { |
| 6922 Token partKeyword = getAndAdvance(); | 6892 Token partKeyword = getAndAdvance(); |
| 6923 StringLiteral partUri = _parseUri(); | 6893 StringLiteral partUri = _parseUri(); |
| 6924 Token semicolon = _expect(TokenType.SEMICOLON); | 6894 Token semicolon = _expect(TokenType.SEMICOLON); |
| 6925 return astFactory.partDirective(commentAndMetadata.comment, | 6895 return new PartDirective(commentAndMetadata.comment, |
| 6926 commentAndMetadata.metadata, partKeyword, partUri, semicolon); | 6896 commentAndMetadata.metadata, partKeyword, partUri, semicolon); |
| 6927 } | 6897 } |
| 6928 | 6898 |
| 6929 /** | 6899 /** |
| 6930 * Parse a part-of directive. The [commentAndMetadata] is the metadata to be | 6900 * Parse a part-of directive. The [commentAndMetadata] is the metadata to be |
| 6931 * associated with the directive. Return the part or part-of directive that | 6901 * associated with the directive. Return the part or part-of directive that |
| 6932 * was parsed. | 6902 * was parsed. |
| 6933 * | 6903 * |
| 6934 * This method assumes that the current token matches [Keyword.PART] and that | 6904 * This method assumes that the current token matches [Keyword.PART] and that |
| 6935 * the following token matches the identifier 'of'. | 6905 * the following token matches the identifier 'of'. |
| 6936 * | 6906 * |
| 6937 * partOfDirective ::= | 6907 * partOfDirective ::= |
| 6938 * metadata 'part' 'of' identifier ';' | 6908 * metadata 'part' 'of' identifier ';' |
| 6939 */ | 6909 */ |
| 6940 Directive _parsePartOfDirective(CommentAndMetadata commentAndMetadata) { | 6910 Directive _parsePartOfDirective(CommentAndMetadata commentAndMetadata) { |
| 6941 Token partKeyword = getAndAdvance(); | 6911 Token partKeyword = getAndAdvance(); |
| 6942 Token ofKeyword = getAndAdvance(); | 6912 Token ofKeyword = getAndAdvance(); |
| 6943 if (enableUriInPartOf && _matches(TokenType.STRING)) { | 6913 if (enableUriInPartOf && _matches(TokenType.STRING)) { |
| 6944 StringLiteral libraryUri = _parseUri(); | 6914 StringLiteral libraryUri = _parseUri(); |
| 6945 Token semicolon = _expect(TokenType.SEMICOLON); | 6915 Token semicolon = _expect(TokenType.SEMICOLON); |
| 6946 return astFactory.partOfDirective( | 6916 return new PartOfDirective( |
| 6947 commentAndMetadata.comment, | 6917 commentAndMetadata.comment, |
| 6948 commentAndMetadata.metadata, | 6918 commentAndMetadata.metadata, |
| 6949 partKeyword, | 6919 partKeyword, |
| 6950 ofKeyword, | 6920 ofKeyword, |
| 6951 libraryUri, | 6921 libraryUri, |
| 6952 null, | 6922 null, |
| 6953 semicolon); | 6923 semicolon); |
| 6954 } | 6924 } |
| 6955 LibraryIdentifier libraryName = _parseLibraryName( | 6925 LibraryIdentifier libraryName = _parseLibraryName( |
| 6956 ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE, ofKeyword); | 6926 ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE, ofKeyword); |
| 6957 Token semicolon = _expect(TokenType.SEMICOLON); | 6927 Token semicolon = _expect(TokenType.SEMICOLON); |
| 6958 return astFactory.partOfDirective( | 6928 return new PartOfDirective( |
| 6959 commentAndMetadata.comment, | 6929 commentAndMetadata.comment, |
| 6960 commentAndMetadata.metadata, | 6930 commentAndMetadata.metadata, |
| 6961 partKeyword, | 6931 partKeyword, |
| 6962 ofKeyword, | 6932 ofKeyword, |
| 6963 null, | 6933 null, |
| 6964 libraryName, | 6934 libraryName, |
| 6965 semicolon); | 6935 semicolon); |
| 6966 } | 6936 } |
| 6967 | 6937 |
| 6968 /** | 6938 /** |
| 6969 * Parse a prefixed identifier given that the given [qualifier] was already | 6939 * Parse a prefixed identifier given that the given [qualifier] was already |
| 6970 * parsed. Return the prefixed identifier that was parsed. | 6940 * parsed. Return the prefixed identifier that was parsed. |
| 6971 * | 6941 * |
| 6972 * prefixedIdentifier ::= | 6942 * prefixedIdentifier ::= |
| 6973 * identifier ('.' identifier)? | 6943 * identifier ('.' identifier)? |
| 6974 */ | 6944 */ |
| 6975 Identifier _parsePrefixedIdentifierAfterIdentifier( | 6945 Identifier _parsePrefixedIdentifierAfterIdentifier( |
| 6976 SimpleIdentifier qualifier) { | 6946 SimpleIdentifier qualifier) { |
| 6977 if (!_matches(TokenType.PERIOD) || _injectGenericCommentTypeList()) { | 6947 if (!_matches(TokenType.PERIOD) || _injectGenericCommentTypeList()) { |
| 6978 return qualifier; | 6948 return qualifier; |
| 6979 } | 6949 } |
| 6980 Token period = getAndAdvance(); | 6950 Token period = getAndAdvance(); |
| 6981 SimpleIdentifier qualified = parseSimpleIdentifier(); | 6951 SimpleIdentifier qualified = parseSimpleIdentifier(); |
| 6982 return astFactory.prefixedIdentifier(qualifier, period, qualified); | 6952 return new PrefixedIdentifier(qualifier, period, qualified); |
| 6983 } | 6953 } |
| 6984 | 6954 |
| 6985 /** | 6955 /** |
| 6986 * Parse a prefixed identifier. Return the prefixed identifier that was | 6956 * Parse a prefixed identifier. Return the prefixed identifier that was |
| 6987 * parsed. | 6957 * parsed. |
| 6988 * | 6958 * |
| 6989 * This method assumes that the current token matches an identifier. | 6959 * This method assumes that the current token matches an identifier. |
| 6990 * | 6960 * |
| 6991 * prefixedIdentifier ::= | 6961 * prefixedIdentifier ::= |
| 6992 * identifier ('.' identifier)? | 6962 * identifier ('.' identifier)? |
| (...skipping 12 matching lines...) Expand all Loading... |
| 7005 * IDENTIFIER | 6975 * IDENTIFIER |
| 7006 */ | 6976 */ |
| 7007 SimpleIdentifier _parseSimpleIdentifierUnchecked( | 6977 SimpleIdentifier _parseSimpleIdentifierUnchecked( |
| 7008 {bool isDeclaration: false}) { | 6978 {bool isDeclaration: false}) { |
| 7009 String lexeme = _currentToken.lexeme; | 6979 String lexeme = _currentToken.lexeme; |
| 7010 if ((_inAsync || _inGenerator) && | 6980 if ((_inAsync || _inGenerator) && |
| 7011 (lexeme == ASYNC || lexeme == _AWAIT || lexeme == _YIELD)) { | 6981 (lexeme == ASYNC || lexeme == _AWAIT || lexeme == _YIELD)) { |
| 7012 _reportErrorForCurrentToken( | 6982 _reportErrorForCurrentToken( |
| 7013 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER); | 6983 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER); |
| 7014 } | 6984 } |
| 7015 return astFactory.simpleIdentifier(getAndAdvance(), | 6985 return new SimpleIdentifier(getAndAdvance(), isDeclaration: isDeclaration); |
| 7016 isDeclaration: isDeclaration); | |
| 7017 } | 6986 } |
| 7018 | 6987 |
| 7019 /** | 6988 /** |
| 7020 * Parse a list of statements within a switch statement. Return the statements | 6989 * Parse a list of statements within a switch statement. Return the statements |
| 7021 * that were parsed. | 6990 * that were parsed. |
| 7022 * | 6991 * |
| 7023 * statements ::= | 6992 * statements ::= |
| 7024 * statement* | 6993 * statement* |
| 7025 */ | 6994 */ |
| 7026 List<Statement> _parseStatementList() { | 6995 List<Statement> _parseStatementList() { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 7045 /** | 7014 /** |
| 7046 * Parse a string literal that contains interpolations. Return the string | 7015 * Parse a string literal that contains interpolations. Return the string |
| 7047 * literal that was parsed. | 7016 * literal that was parsed. |
| 7048 * | 7017 * |
| 7049 * This method assumes that the current token matches either | 7018 * This method assumes that the current token matches either |
| 7050 * [TokenType.STRING_INTERPOLATION_EXPRESSION] or | 7019 * [TokenType.STRING_INTERPOLATION_EXPRESSION] or |
| 7051 * [TokenType.STRING_INTERPOLATION_IDENTIFIER]. | 7020 * [TokenType.STRING_INTERPOLATION_IDENTIFIER]. |
| 7052 */ | 7021 */ |
| 7053 StringInterpolation _parseStringInterpolation(Token string) { | 7022 StringInterpolation _parseStringInterpolation(Token string) { |
| 7054 List<InterpolationElement> elements = <InterpolationElement>[ | 7023 List<InterpolationElement> elements = <InterpolationElement>[ |
| 7055 astFactory.interpolationString( | 7024 new InterpolationString( |
| 7056 string, computeStringValue(string.lexeme, true, false)) | 7025 string, computeStringValue(string.lexeme, true, false)) |
| 7057 ]; | 7026 ]; |
| 7058 bool hasMore = true; | 7027 bool hasMore = true; |
| 7059 bool isExpression = _matches(TokenType.STRING_INTERPOLATION_EXPRESSION); | 7028 bool isExpression = _matches(TokenType.STRING_INTERPOLATION_EXPRESSION); |
| 7060 while (hasMore) { | 7029 while (hasMore) { |
| 7061 if (isExpression) { | 7030 if (isExpression) { |
| 7062 Token openToken = getAndAdvance(); | 7031 Token openToken = getAndAdvance(); |
| 7063 bool wasInInitializer = _inInitializer; | 7032 bool wasInInitializer = _inInitializer; |
| 7064 _inInitializer = false; | 7033 _inInitializer = false; |
| 7065 try { | 7034 try { |
| 7066 Expression expression = parseExpression2(); | 7035 Expression expression = parseExpression2(); |
| 7067 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); | 7036 Token rightBracket = _expect(TokenType.CLOSE_CURLY_BRACKET); |
| 7068 elements.add(astFactory.interpolationExpression( | 7037 elements.add( |
| 7069 openToken, expression, rightBracket)); | 7038 new InterpolationExpression(openToken, expression, rightBracket)); |
| 7070 } finally { | 7039 } finally { |
| 7071 _inInitializer = wasInInitializer; | 7040 _inInitializer = wasInInitializer; |
| 7072 } | 7041 } |
| 7073 } else { | 7042 } else { |
| 7074 Token openToken = getAndAdvance(); | 7043 Token openToken = getAndAdvance(); |
| 7075 Expression expression = null; | 7044 Expression expression = null; |
| 7076 if (_matchesKeyword(Keyword.THIS)) { | 7045 if (_matchesKeyword(Keyword.THIS)) { |
| 7077 expression = astFactory.thisExpression(getAndAdvance()); | 7046 expression = new ThisExpression(getAndAdvance()); |
| 7078 } else { | 7047 } else { |
| 7079 expression = parseSimpleIdentifier(); | 7048 expression = parseSimpleIdentifier(); |
| 7080 } | 7049 } |
| 7081 elements.add( | 7050 elements.add(new InterpolationExpression(openToken, expression, null)); |
| 7082 astFactory.interpolationExpression(openToken, expression, null)); | |
| 7083 } | 7051 } |
| 7084 if (_matches(TokenType.STRING)) { | 7052 if (_matches(TokenType.STRING)) { |
| 7085 string = getAndAdvance(); | 7053 string = getAndAdvance(); |
| 7086 isExpression = _matches(TokenType.STRING_INTERPOLATION_EXPRESSION); | 7054 isExpression = _matches(TokenType.STRING_INTERPOLATION_EXPRESSION); |
| 7087 hasMore = | 7055 hasMore = |
| 7088 isExpression || _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER); | 7056 isExpression || _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER); |
| 7089 elements.add(astFactory.interpolationString( | 7057 elements.add(new InterpolationString( |
| 7090 string, computeStringValue(string.lexeme, false, !hasMore))); | 7058 string, computeStringValue(string.lexeme, false, !hasMore))); |
| 7091 } else { | 7059 } else { |
| 7092 hasMore = false; | 7060 hasMore = false; |
| 7093 } | 7061 } |
| 7094 } | 7062 } |
| 7095 return astFactory.stringInterpolation(elements); | 7063 return new StringInterpolation(elements); |
| 7096 } | 7064 } |
| 7097 | 7065 |
| 7098 /** | 7066 /** |
| 7099 * Parse a string literal. Return the string literal that was parsed. | 7067 * Parse a string literal. Return the string literal that was parsed. |
| 7100 * | 7068 * |
| 7101 * This method assumes that the current token matches `TokenType.STRING`. | 7069 * This method assumes that the current token matches `TokenType.STRING`. |
| 7102 * | 7070 * |
| 7103 * stringLiteral ::= | 7071 * stringLiteral ::= |
| 7104 * MULTI_LINE_STRING+ | 7072 * MULTI_LINE_STRING+ |
| 7105 * | SINGLE_LINE_STRING+ | 7073 * | SINGLE_LINE_STRING+ |
| 7106 */ | 7074 */ |
| 7107 StringLiteral _parseStringLiteralUnchecked() { | 7075 StringLiteral _parseStringLiteralUnchecked() { |
| 7108 List<StringLiteral> strings = <StringLiteral>[]; | 7076 List<StringLiteral> strings = <StringLiteral>[]; |
| 7109 do { | 7077 do { |
| 7110 Token string = getAndAdvance(); | 7078 Token string = getAndAdvance(); |
| 7111 if (_matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || | 7079 if (_matches(TokenType.STRING_INTERPOLATION_EXPRESSION) || |
| 7112 _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER)) { | 7080 _matches(TokenType.STRING_INTERPOLATION_IDENTIFIER)) { |
| 7113 strings.add(_parseStringInterpolation(string)); | 7081 strings.add(_parseStringInterpolation(string)); |
| 7114 } else { | 7082 } else { |
| 7115 strings.add(astFactory.simpleStringLiteral( | 7083 strings.add(new SimpleStringLiteral( |
| 7116 string, computeStringValue(string.lexeme, true, true))); | 7084 string, computeStringValue(string.lexeme, true, true))); |
| 7117 } | 7085 } |
| 7118 } while (_matches(TokenType.STRING)); | 7086 } while (_matches(TokenType.STRING)); |
| 7119 return strings.length == 1 | 7087 return strings.length == 1 ? strings[0] : new AdjacentStrings(strings); |
| 7120 ? strings[0] | |
| 7121 : astFactory.adjacentStrings(strings); | |
| 7122 } | 7088 } |
| 7123 | 7089 |
| 7124 TypeName _parseTypeName(bool inExpression) { | 7090 TypeName _parseTypeName(bool inExpression) { |
| 7125 Identifier typeName; | 7091 Identifier typeName; |
| 7126 if (_matchesIdentifier()) { | 7092 if (_matchesIdentifier()) { |
| 7127 typeName = _parsePrefixedIdentifierUnchecked(); | 7093 typeName = _parsePrefixedIdentifierUnchecked(); |
| 7128 } else if (_matchesKeyword(Keyword.VAR)) { | 7094 } else if (_matchesKeyword(Keyword.VAR)) { |
| 7129 _reportErrorForCurrentToken(ParserErrorCode.VAR_AS_TYPE_NAME); | 7095 _reportErrorForCurrentToken(ParserErrorCode.VAR_AS_TYPE_NAME); |
| 7130 typeName = astFactory.simpleIdentifier(getAndAdvance()); | 7096 typeName = new SimpleIdentifier(getAndAdvance()); |
| 7131 } else { | 7097 } else { |
| 7132 typeName = createSyntheticIdentifier(); | 7098 typeName = createSyntheticIdentifier(); |
| 7133 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TYPE_NAME); | 7099 _reportErrorForCurrentToken(ParserErrorCode.EXPECTED_TYPE_NAME); |
| 7134 } | 7100 } |
| 7135 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); | 7101 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); |
| 7136 Token question = null; | 7102 Token question = null; |
| 7137 if (enableNnbd && _matches(TokenType.QUESTION)) { | 7103 if (enableNnbd && _matches(TokenType.QUESTION)) { |
| 7138 if (!inExpression || !_isConditionalOperator()) { | 7104 if (!inExpression || !_isConditionalOperator()) { |
| 7139 question = getAndAdvance(); | 7105 question = getAndAdvance(); |
| 7140 } | 7106 } |
| 7141 } | 7107 } |
| 7142 return astFactory.typeName(typeName, typeArguments, question: question); | 7108 return new TypeName(typeName, typeArguments, question: question); |
| 7143 } | 7109 } |
| 7144 | 7110 |
| 7145 /** | 7111 /** |
| 7146 * Parse a type name. Return the type name that was parsed. | 7112 * Parse a type name. Return the type name that was parsed. |
| 7147 * | 7113 * |
| 7148 * This method assumes that the current token is an identifier. | 7114 * This method assumes that the current token is an identifier. |
| 7149 * | 7115 * |
| 7150 * type ::= | 7116 * type ::= |
| 7151 * qualified typeArguments? | 7117 * qualified typeArguments? |
| 7152 */ | 7118 */ |
| 7153 TypeName _parseTypeNameAfterIdentifier() { | 7119 TypeName _parseTypeNameAfterIdentifier() { |
| 7154 Identifier typeName = _parsePrefixedIdentifierUnchecked(); | 7120 Identifier typeName = _parsePrefixedIdentifierUnchecked(); |
| 7155 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); | 7121 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); |
| 7156 // If this is followed by a generic method type comment, allow the comment | 7122 // If this is followed by a generic method type comment, allow the comment |
| 7157 // type to replace the real type name. | 7123 // type to replace the real type name. |
| 7158 // TODO(jmesserly): this feels like a big hammer. Can we restrict it to | 7124 // TODO(jmesserly): this feels like a big hammer. Can we restrict it to |
| 7159 // only work inside generic methods? | 7125 // only work inside generic methods? |
| 7160 TypeName typeFromComment = _parseOptionalTypeNameComment(); | 7126 TypeName typeFromComment = _parseOptionalTypeNameComment(); |
| 7161 return typeFromComment ?? astFactory.typeName(typeName, typeArguments); | 7127 return typeFromComment ?? new TypeName(typeName, typeArguments); |
| 7162 } | 7128 } |
| 7163 | 7129 |
| 7164 /** | 7130 /** |
| 7165 * Parse a string literal representing a URI. Return the string literal that | 7131 * Parse a string literal representing a URI. Return the string literal that |
| 7166 * was parsed. | 7132 * was parsed. |
| 7167 */ | 7133 */ |
| 7168 StringLiteral _parseUri() { | 7134 StringLiteral _parseUri() { |
| 7169 // TODO(brianwilkerson) Should this function also return true for valid | 7135 // TODO(brianwilkerson) Should this function also return true for valid |
| 7170 // top-level keywords? | 7136 // top-level keywords? |
| 7171 bool isKeywordAfterUri(Token token) => | 7137 bool isKeywordAfterUri(Token token) => |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7208 } | 7174 } |
| 7209 buffer.write(token.lexeme); | 7175 buffer.write(token.lexeme); |
| 7210 endOffset = token.end; | 7176 endOffset = token.end; |
| 7211 } | 7177 } |
| 7212 String value = buffer.toString(); | 7178 String value = buffer.toString(); |
| 7213 Token newToken = | 7179 Token newToken = |
| 7214 new StringToken(TokenType.STRING, "'$value'", _currentToken.offset); | 7180 new StringToken(TokenType.STRING, "'$value'", _currentToken.offset); |
| 7215 _reportErrorForToken( | 7181 _reportErrorForToken( |
| 7216 ParserErrorCode.NON_STRING_LITERAL_AS_URI, newToken); | 7182 ParserErrorCode.NON_STRING_LITERAL_AS_URI, newToken); |
| 7217 _currentToken = endToken.next; | 7183 _currentToken = endToken.next; |
| 7218 return astFactory.simpleStringLiteral(newToken, value); | 7184 return new SimpleStringLiteral(newToken, value); |
| 7219 } | 7185 } |
| 7220 } | 7186 } |
| 7221 return parseStringLiteral(); | 7187 return parseStringLiteral(); |
| 7222 } | 7188 } |
| 7223 | 7189 |
| 7224 /** | 7190 /** |
| 7225 * Parse a variable declaration statement. The [commentAndMetadata] is the | 7191 * Parse a variable declaration statement. The [commentAndMetadata] is the |
| 7226 * metadata to be associated with the variable declaration statement, or | 7192 * metadata to be associated with the variable declaration statement, or |
| 7227 * `null` if there is no attempt at parsing the comment and metadata. The | 7193 * `null` if there is no attempt at parsing the comment and metadata. The |
| 7228 * [keyword] is the token representing the 'final', 'const' or 'var' keyword, | 7194 * [keyword] is the token representing the 'final', 'const' or 'var' keyword, |
| 7229 * or `null` if there is no keyword. The [type] is the type of the variables | 7195 * or `null` if there is no keyword. The [type] is the type of the variables |
| 7230 * in the list. Return the variable declaration statement that was parsed. | 7196 * in the list. Return the variable declaration statement that was parsed. |
| 7231 * | 7197 * |
| 7232 * variableDeclarationStatement ::= | 7198 * variableDeclarationStatement ::= |
| 7233 * variableDeclarationList ';' | 7199 * variableDeclarationList ';' |
| 7234 */ | 7200 */ |
| 7235 VariableDeclarationStatement _parseVariableDeclarationStatementAfterType( | 7201 VariableDeclarationStatement _parseVariableDeclarationStatementAfterType( |
| 7236 CommentAndMetadata commentAndMetadata, Token keyword, TypeName type) { | 7202 CommentAndMetadata commentAndMetadata, Token keyword, TypeName type) { |
| 7237 VariableDeclarationList variableList = | 7203 VariableDeclarationList variableList = |
| 7238 parseVariableDeclarationListAfterType( | 7204 parseVariableDeclarationListAfterType( |
| 7239 commentAndMetadata, keyword, type); | 7205 commentAndMetadata, keyword, type); |
| 7240 Token semicolon = _expect(TokenType.SEMICOLON); | 7206 Token semicolon = _expect(TokenType.SEMICOLON); |
| 7241 return astFactory.variableDeclarationStatement(variableList, semicolon); | 7207 return new VariableDeclarationStatement(variableList, semicolon); |
| 7242 } | 7208 } |
| 7243 | 7209 |
| 7244 /** | 7210 /** |
| 7245 * Return the token that is immediately after the current token. This is | 7211 * Return the token that is immediately after the current token. This is |
| 7246 * equivalent to [_peekAt](1). | 7212 * equivalent to [_peekAt](1). |
| 7247 */ | 7213 */ |
| 7248 Token _peek() => _currentToken.next; | 7214 Token _peek() => _currentToken.next; |
| 7249 | 7215 |
| 7250 /** | 7216 /** |
| 7251 * Return the token that is the given [distance] after the current token, | 7217 * Return the token that is the given [distance] after the current token, |
| (...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8181 */ | 8147 */ |
| 8182 Parser_SyntheticKeywordToken(Keyword keyword, int offset) | 8148 Parser_SyntheticKeywordToken(Keyword keyword, int offset) |
| 8183 : super(keyword, offset); | 8149 : super(keyword, offset); |
| 8184 | 8150 |
| 8185 @override | 8151 @override |
| 8186 int get length => 0; | 8152 int get length => 0; |
| 8187 | 8153 |
| 8188 @override | 8154 @override |
| 8189 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); | 8155 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); |
| 8190 } | 8156 } |
| OLD | NEW |