Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 131233009: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.parser; 8 library engine.parser;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 if (identical(_oldNode, node.expression)) { 211 if (identical(_oldNode, node.expression)) {
212 return _parser.parseBitwiseOrExpression(); 212 return _parser.parseBitwiseOrExpression();
213 } else if (identical(_oldNode, node.type)) { 213 } else if (identical(_oldNode, node.type)) {
214 return _parser.parseTypeName(); 214 return _parser.parseTypeName();
215 } 215 }
216 return notAChild(node); 216 return notAChild(node);
217 } 217 }
218 218
219 ASTNode visitAssertStatement(AssertStatement node) { 219 ASTNode visitAssertStatement(AssertStatement node) {
220 if (identical(_oldNode, node.condition)) { 220 if (identical(_oldNode, node.condition)) {
221 return _parser.parseExpression4(); 221 return _parser.parseExpression2();
222 } 222 }
223 return notAChild(node); 223 return notAChild(node);
224 } 224 }
225 225
226 ASTNode visitAssignmentExpression(AssignmentExpression node) { 226 ASTNode visitAssignmentExpression(AssignmentExpression node) {
227 if (identical(_oldNode, node.leftHandSide)) { 227 if (identical(_oldNode, node.leftHandSide)) {
228 // TODO(brianwilkerson) If the assignment is part of a cascade section, th en we don't have a 228 // TODO(brianwilkerson) If the assignment is part of a cascade section, th en we don't have a
229 // single parse method that will work. Otherwise, we can parse a condition al expression, but 229 // single parse method that will work. Otherwise, we can parse a condition al expression, but
230 // need to ensure that the resulting expression is assignable. 230 // need to ensure that the resulting expression is assignable.
231 // return parser.parseConditionalExpression(); 231 // return parser.parseConditionalExpression();
232 throw new InsufficientContextException(); 232 throw new InsufficientContextException();
233 } else if (identical(_oldNode, node.rightHandSide)) { 233 } else if (identical(_oldNode, node.rightHandSide)) {
234 if (isCascadeAllowed(node)) { 234 if (isCascadeAllowed(node)) {
235 return _parser.parseExpression4(); 235 return _parser.parseExpression2();
236 } 236 }
237 return _parser.parseExpressionWithoutCascade(); 237 return _parser.parseExpressionWithoutCascade();
238 } 238 }
239 return notAChild(node); 239 return notAChild(node);
240 } 240 }
241 241
242 ASTNode visitBinaryExpression(BinaryExpression node) { 242 ASTNode visitBinaryExpression(BinaryExpression node) {
243 if (identical(_oldNode, node.leftOperand)) { 243 if (identical(_oldNode, node.leftOperand)) {
244 throw new InsufficientContextException(); 244 throw new InsufficientContextException();
245 } else if (identical(_oldNode, node.rightOperand)) { 245 } else if (identical(_oldNode, node.rightOperand)) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } else if (identical(_oldNode, node.identifier)) { 415 } else if (identical(_oldNode, node.identifier)) {
416 return _parser.parseSimpleIdentifier(); 416 return _parser.parseSimpleIdentifier();
417 } 417 }
418 return notAChild(node); 418 return notAChild(node);
419 } 419 }
420 420
421 ASTNode visitDefaultFormalParameter(DefaultFormalParameter node) { 421 ASTNode visitDefaultFormalParameter(DefaultFormalParameter node) {
422 if (identical(_oldNode, node.parameter)) { 422 if (identical(_oldNode, node.parameter)) {
423 return _parser.parseNormalFormalParameter(); 423 return _parser.parseNormalFormalParameter();
424 } else if (identical(_oldNode, node.defaultValue)) { 424 } else if (identical(_oldNode, node.defaultValue)) {
425 return _parser.parseExpression4(); 425 return _parser.parseExpression2();
426 } 426 }
427 return notAChild(node); 427 return notAChild(node);
428 } 428 }
429 429
430 ASTNode visitDoStatement(DoStatement node) { 430 ASTNode visitDoStatement(DoStatement node) {
431 if (identical(_oldNode, node.body)) { 431 if (identical(_oldNode, node.body)) {
432 return _parser.parseStatement2(); 432 return _parser.parseStatement2();
433 } else if (identical(_oldNode, node.condition)) { 433 } else if (identical(_oldNode, node.condition)) {
434 return _parser.parseExpression4(); 434 return _parser.parseExpression2();
435 } 435 }
436 return notAChild(node); 436 return notAChild(node);
437 } 437 }
438 438
439 ASTNode visitDoubleLiteral(DoubleLiteral node) => notAChild(node); 439 ASTNode visitDoubleLiteral(DoubleLiteral node) => notAChild(node);
440 440
441 ASTNode visitEmptyFunctionBody(EmptyFunctionBody node) => notAChild(node); 441 ASTNode visitEmptyFunctionBody(EmptyFunctionBody node) => notAChild(node);
442 442
443 ASTNode visitEmptyStatement(EmptyStatement node) => notAChild(node); 443 ASTNode visitEmptyStatement(EmptyStatement node) => notAChild(node);
444 444
445 ASTNode visitExportDirective(ExportDirective node) { 445 ASTNode visitExportDirective(ExportDirective node) {
446 if (identical(_oldNode, node.documentationComment)) { 446 if (identical(_oldNode, node.documentationComment)) {
447 throw new InsufficientContextException(); 447 throw new InsufficientContextException();
448 } else if (node.metadata.contains(_oldNode)) { 448 } else if (node.metadata.contains(_oldNode)) {
449 return _parser.parseAnnotation(); 449 return _parser.parseAnnotation();
450 } else if (identical(_oldNode, node.uri)) { 450 } else if (identical(_oldNode, node.uri)) {
451 return _parser.parseStringLiteral(); 451 return _parser.parseStringLiteral();
452 } else if (node.combinators.contains(_oldNode)) { 452 } else if (node.combinators.contains(_oldNode)) {
453 throw new IncrementalParseException(); 453 throw new IncrementalParseException();
454 } 454 }
455 return notAChild(node); 455 return notAChild(node);
456 } 456 }
457 457
458 ASTNode visitExpressionFunctionBody(ExpressionFunctionBody node) { 458 ASTNode visitExpressionFunctionBody(ExpressionFunctionBody node) {
459 if (identical(_oldNode, node.expression)) { 459 if (identical(_oldNode, node.expression)) {
460 return _parser.parseExpression4(); 460 return _parser.parseExpression2();
461 } 461 }
462 return notAChild(node); 462 return notAChild(node);
463 } 463 }
464 464
465 ASTNode visitExpressionStatement(ExpressionStatement node) { 465 ASTNode visitExpressionStatement(ExpressionStatement node) {
466 if (identical(_oldNode, node.expression)) { 466 if (identical(_oldNode, node.expression)) {
467 return _parser.parseExpression4(); 467 return _parser.parseExpression2();
468 } 468 }
469 return notAChild(node); 469 return notAChild(node);
470 } 470 }
471 471
472 ASTNode visitExtendsClause(ExtendsClause node) { 472 ASTNode visitExtendsClause(ExtendsClause node) {
473 if (identical(_oldNode, node.superclass)) { 473 if (identical(_oldNode, node.superclass)) {
474 return _parser.parseTypeName(); 474 return _parser.parseTypeName();
475 } 475 }
476 return notAChild(node); 476 return notAChild(node);
477 } 477 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 // We don't know which kind of parameter to parse. 517 // We don't know which kind of parameter to parse.
518 throw new InsufficientContextException(); 518 throw new InsufficientContextException();
519 } 519 }
520 520
521 ASTNode visitForStatement(ForStatement node) { 521 ASTNode visitForStatement(ForStatement node) {
522 if (identical(_oldNode, node.variables)) { 522 if (identical(_oldNode, node.variables)) {
523 throw new InsufficientContextException(); 523 throw new InsufficientContextException();
524 } else if (identical(_oldNode, node.initialization)) { 524 } else if (identical(_oldNode, node.initialization)) {
525 throw new InsufficientContextException(); 525 throw new InsufficientContextException();
526 } else if (identical(_oldNode, node.condition)) { 526 } else if (identical(_oldNode, node.condition)) {
527 return _parser.parseExpression4(); 527 return _parser.parseExpression2();
528 } else if (node.updaters.contains(_oldNode)) { 528 } else if (node.updaters.contains(_oldNode)) {
529 return _parser.parseExpression4(); 529 return _parser.parseExpression2();
530 } else if (identical(_oldNode, node.body)) { 530 } else if (identical(_oldNode, node.body)) {
531 return _parser.parseStatement2(); 531 return _parser.parseStatement2();
532 } 532 }
533 return notAChild(node); 533 return notAChild(node);
534 } 534 }
535 535
536 ASTNode visitFunctionDeclaration(FunctionDeclaration node) { 536 ASTNode visitFunctionDeclaration(FunctionDeclaration node) {
537 if (identical(_oldNode, node.documentationComment)) { 537 if (identical(_oldNode, node.documentationComment)) {
538 throw new InsufficientContextException(); 538 throw new InsufficientContextException();
539 } else if (node.metadata.contains(_oldNode)) { 539 } else if (node.metadata.contains(_oldNode)) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 607
608 ASTNode visitHideCombinator(HideCombinator node) { 608 ASTNode visitHideCombinator(HideCombinator node) {
609 if (node.hiddenNames.contains(_oldNode)) { 609 if (node.hiddenNames.contains(_oldNode)) {
610 return _parser.parseSimpleIdentifier(); 610 return _parser.parseSimpleIdentifier();
611 } 611 }
612 return notAChild(node); 612 return notAChild(node);
613 } 613 }
614 614
615 ASTNode visitIfStatement(IfStatement node) { 615 ASTNode visitIfStatement(IfStatement node) {
616 if (identical(_oldNode, node.condition)) { 616 if (identical(_oldNode, node.condition)) {
617 return _parser.parseExpression4(); 617 return _parser.parseExpression2();
618 } else if (identical(_oldNode, node.thenStatement)) { 618 } else if (identical(_oldNode, node.thenStatement)) {
619 return _parser.parseStatement2(); 619 return _parser.parseStatement2();
620 } else if (identical(_oldNode, node.elseStatement)) { 620 } else if (identical(_oldNode, node.elseStatement)) {
621 return _parser.parseStatement2(); 621 return _parser.parseStatement2();
622 } 622 }
623 return notAChild(node); 623 return notAChild(node);
624 } 624 }
625 625
626 ASTNode visitImplementsClause(ImplementsClause node) { 626 ASTNode visitImplementsClause(ImplementsClause node) {
627 if (node.interfaces.contains(node)) { 627 if (node.interfaces.contains(node)) {
(...skipping 14 matching lines...) Expand all
642 } else if (node.combinators.contains(_oldNode)) { 642 } else if (node.combinators.contains(_oldNode)) {
643 throw new IncrementalParseException(); 643 throw new IncrementalParseException();
644 } 644 }
645 return notAChild(node); 645 return notAChild(node);
646 } 646 }
647 647
648 ASTNode visitIndexExpression(IndexExpression node) { 648 ASTNode visitIndexExpression(IndexExpression node) {
649 if (identical(_oldNode, node.target)) { 649 if (identical(_oldNode, node.target)) {
650 throw new InsufficientContextException(); 650 throw new InsufficientContextException();
651 } else if (identical(_oldNode, node.index)) { 651 } else if (identical(_oldNode, node.index)) {
652 return _parser.parseExpression4(); 652 return _parser.parseExpression2();
653 } 653 }
654 return notAChild(node); 654 return notAChild(node);
655 } 655 }
656 656
657 ASTNode visitInstanceCreationExpression(InstanceCreationExpression node) { 657 ASTNode visitInstanceCreationExpression(InstanceCreationExpression node) {
658 if (identical(_oldNode, node.constructorName)) { 658 if (identical(_oldNode, node.constructorName)) {
659 return _parser.parseConstructorName(); 659 return _parser.parseConstructorName();
660 } else if (identical(_oldNode, node.argumentList)) { 660 } else if (identical(_oldNode, node.argumentList)) {
661 return _parser.parseArgumentList(); 661 return _parser.parseArgumentList();
662 } 662 }
663 return notAChild(node); 663 return notAChild(node);
664 } 664 }
665 665
666 ASTNode visitIntegerLiteral(IntegerLiteral node) => notAChild(node); 666 ASTNode visitIntegerLiteral(IntegerLiteral node) => notAChild(node);
667 667
668 ASTNode visitInterpolationExpression(InterpolationExpression node) { 668 ASTNode visitInterpolationExpression(InterpolationExpression node) {
669 if (identical(_oldNode, node.expression)) { 669 if (identical(_oldNode, node.expression)) {
670 if (node.leftBracket == null) { 670 if (node.leftBracket == null) {
671 throw new InsufficientContextException(); 671 throw new InsufficientContextException();
672 } 672 }
673 return _parser.parseExpression4(); 673 return _parser.parseExpression2();
674 } 674 }
675 return notAChild(node); 675 return notAChild(node);
676 } 676 }
677 677
678 ASTNode visitInterpolationString(InterpolationString node) { 678 ASTNode visitInterpolationString(InterpolationString node) {
679 throw new InsufficientContextException(); 679 throw new InsufficientContextException();
680 } 680 }
681 681
682 ASTNode visitIsExpression(IsExpression node) { 682 ASTNode visitIsExpression(IsExpression node) {
683 if (identical(_oldNode, node.expression)) { 683 if (identical(_oldNode, node.expression)) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 if (node.components.contains(_oldNode)) { 719 if (node.components.contains(_oldNode)) {
720 return _parser.parseSimpleIdentifier(); 720 return _parser.parseSimpleIdentifier();
721 } 721 }
722 return notAChild(node); 722 return notAChild(node);
723 } 723 }
724 724
725 ASTNode visitListLiteral(ListLiteral node) { 725 ASTNode visitListLiteral(ListLiteral node) {
726 if (identical(_oldNode, node.typeArguments)) { 726 if (identical(_oldNode, node.typeArguments)) {
727 return _parser.parseTypeArgumentList(); 727 return _parser.parseTypeArgumentList();
728 } else if (node.elements.contains(_oldNode)) { 728 } else if (node.elements.contains(_oldNode)) {
729 return _parser.parseExpression4(); 729 return _parser.parseExpression2();
730 } 730 }
731 return notAChild(node); 731 return notAChild(node);
732 } 732 }
733 733
734 ASTNode visitMapLiteral(MapLiteral node) { 734 ASTNode visitMapLiteral(MapLiteral node) {
735 if (identical(_oldNode, node.typeArguments)) { 735 if (identical(_oldNode, node.typeArguments)) {
736 return _parser.parseTypeArgumentList(); 736 return _parser.parseTypeArgumentList();
737 } else if (node.entries.contains(_oldNode)) { 737 } else if (node.entries.contains(_oldNode)) {
738 return _parser.parseMapLiteralEntry(); 738 return _parser.parseMapLiteralEntry();
739 } 739 }
740 return notAChild(node); 740 return notAChild(node);
741 } 741 }
742 742
743 ASTNode visitMapLiteralEntry(MapLiteralEntry node) { 743 ASTNode visitMapLiteralEntry(MapLiteralEntry node) {
744 if (identical(_oldNode, node.key)) { 744 if (identical(_oldNode, node.key)) {
745 return _parser.parseExpression4(); 745 return _parser.parseExpression2();
746 } else if (identical(_oldNode, node.value)) { 746 } else if (identical(_oldNode, node.value)) {
747 return _parser.parseExpression4(); 747 return _parser.parseExpression2();
748 } 748 }
749 return notAChild(node); 749 return notAChild(node);
750 } 750 }
751 751
752 ASTNode visitMethodDeclaration(MethodDeclaration node) { 752 ASTNode visitMethodDeclaration(MethodDeclaration node) {
753 if (identical(_oldNode, node.documentationComment)) { 753 if (identical(_oldNode, node.documentationComment)) {
754 throw new InsufficientContextException(); 754 throw new InsufficientContextException();
755 } else if (node.metadata.contains(_oldNode)) { 755 } else if (node.metadata.contains(_oldNode)) {
756 return _parser.parseAnnotation(); 756 return _parser.parseAnnotation();
757 } else if (identical(_oldNode, node.returnType)) { 757 } else if (identical(_oldNode, node.returnType)) {
(...skipping 18 matching lines...) Expand all
776 } else if (identical(_oldNode, node.argumentList)) { 776 } else if (identical(_oldNode, node.argumentList)) {
777 return _parser.parseArgumentList(); 777 return _parser.parseArgumentList();
778 } 778 }
779 return notAChild(node); 779 return notAChild(node);
780 } 780 }
781 781
782 ASTNode visitNamedExpression(NamedExpression node) { 782 ASTNode visitNamedExpression(NamedExpression node) {
783 if (identical(_oldNode, node.name)) { 783 if (identical(_oldNode, node.name)) {
784 return _parser.parseLabel(); 784 return _parser.parseLabel();
785 } else if (identical(_oldNode, node.expression)) { 785 } else if (identical(_oldNode, node.expression)) {
786 return _parser.parseExpression4(); 786 return _parser.parseExpression2();
787 } 787 }
788 return notAChild(node); 788 return notAChild(node);
789 } 789 }
790 790
791 ASTNode visitNativeClause(NativeClause node) { 791 ASTNode visitNativeClause(NativeClause node) {
792 if (identical(_oldNode, node.name)) { 792 if (identical(_oldNode, node.name)) {
793 return _parser.parseStringLiteral(); 793 return _parser.parseStringLiteral();
794 } 794 }
795 return notAChild(node); 795 return notAChild(node);
796 } 796 }
797 797
798 ASTNode visitNativeFunctionBody(NativeFunctionBody node) { 798 ASTNode visitNativeFunctionBody(NativeFunctionBody node) {
799 if (identical(_oldNode, node.stringLiteral)) { 799 if (identical(_oldNode, node.stringLiteral)) {
800 return _parser.parseStringLiteral(); 800 return _parser.parseStringLiteral();
801 } 801 }
802 return notAChild(node); 802 return notAChild(node);
803 } 803 }
804 804
805 ASTNode visitNullLiteral(NullLiteral node) => notAChild(node); 805 ASTNode visitNullLiteral(NullLiteral node) => notAChild(node);
806 806
807 ASTNode visitParenthesizedExpression(ParenthesizedExpression node) { 807 ASTNode visitParenthesizedExpression(ParenthesizedExpression node) {
808 if (identical(_oldNode, node.expression)) { 808 if (identical(_oldNode, node.expression)) {
809 return _parser.parseExpression4(); 809 return _parser.parseExpression2();
810 } 810 }
811 return notAChild(node); 811 return notAChild(node);
812 } 812 }
813 813
814 ASTNode visitPartDirective(PartDirective node) { 814 ASTNode visitPartDirective(PartDirective node) {
815 if (identical(_oldNode, node.documentationComment)) { 815 if (identical(_oldNode, node.documentationComment)) {
816 throw new InsufficientContextException(); 816 throw new InsufficientContextException();
817 } else if (node.metadata.contains(_oldNode)) { 817 } else if (node.metadata.contains(_oldNode)) {
818 return _parser.parseAnnotation(); 818 return _parser.parseAnnotation();
819 } else if (identical(_oldNode, node.uri)) { 819 } else if (identical(_oldNode, node.uri)) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 } else if (identical(_oldNode, node.argumentList)) { 871 } else if (identical(_oldNode, node.argumentList)) {
872 return _parser.parseArgumentList(); 872 return _parser.parseArgumentList();
873 } 873 }
874 return notAChild(node); 874 return notAChild(node);
875 } 875 }
876 876
877 ASTNode visitRethrowExpression(RethrowExpression node) => notAChild(node); 877 ASTNode visitRethrowExpression(RethrowExpression node) => notAChild(node);
878 878
879 ASTNode visitReturnStatement(ReturnStatement node) { 879 ASTNode visitReturnStatement(ReturnStatement node) {
880 if (identical(_oldNode, node.expression)) { 880 if (identical(_oldNode, node.expression)) {
881 return _parser.parseExpression4(); 881 return _parser.parseExpression2();
882 } 882 }
883 return notAChild(node); 883 return notAChild(node);
884 } 884 }
885 885
886 ASTNode visitScriptTag(ScriptTag node) => notAChild(node); 886 ASTNode visitScriptTag(ScriptTag node) => notAChild(node);
887 887
888 ASTNode visitShowCombinator(ShowCombinator node) { 888 ASTNode visitShowCombinator(ShowCombinator node) {
889 if (node.shownNames.contains(_oldNode)) { 889 if (node.shownNames.contains(_oldNode)) {
890 return _parser.parseSimpleIdentifier(); 890 return _parser.parseSimpleIdentifier();
891 } 891 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 } 924 }
925 return notAChild(node); 925 return notAChild(node);
926 } 926 }
927 927
928 ASTNode visitSuperExpression(SuperExpression node) => notAChild(node); 928 ASTNode visitSuperExpression(SuperExpression node) => notAChild(node);
929 929
930 ASTNode visitSwitchCase(SwitchCase node) { 930 ASTNode visitSwitchCase(SwitchCase node) {
931 if (node.labels.contains(_oldNode)) { 931 if (node.labels.contains(_oldNode)) {
932 return _parser.parseLabel(); 932 return _parser.parseLabel();
933 } else if (identical(_oldNode, node.expression)) { 933 } else if (identical(_oldNode, node.expression)) {
934 return _parser.parseExpression4(); 934 return _parser.parseExpression2();
935 } else if (node.statements.contains(_oldNode)) { 935 } else if (node.statements.contains(_oldNode)) {
936 return _parser.parseStatement2(); 936 return _parser.parseStatement2();
937 } 937 }
938 return notAChild(node); 938 return notAChild(node);
939 } 939 }
940 940
941 ASTNode visitSwitchDefault(SwitchDefault node) { 941 ASTNode visitSwitchDefault(SwitchDefault node) {
942 if (node.labels.contains(_oldNode)) { 942 if (node.labels.contains(_oldNode)) {
943 return _parser.parseLabel(); 943 return _parser.parseLabel();
944 } else if (node.statements.contains(_oldNode)) { 944 } else if (node.statements.contains(_oldNode)) {
945 return _parser.parseStatement2(); 945 return _parser.parseStatement2();
946 } 946 }
947 return notAChild(node); 947 return notAChild(node);
948 } 948 }
949 949
950 ASTNode visitSwitchStatement(SwitchStatement node) { 950 ASTNode visitSwitchStatement(SwitchStatement node) {
951 if (identical(_oldNode, node.expression)) { 951 if (identical(_oldNode, node.expression)) {
952 return _parser.parseExpression4(); 952 return _parser.parseExpression2();
953 } else if (node.members.contains(_oldNode)) { 953 } else if (node.members.contains(_oldNode)) {
954 throw new InsufficientContextException(); 954 throw new InsufficientContextException();
955 } 955 }
956 return notAChild(node); 956 return notAChild(node);
957 } 957 }
958 958
959 ASTNode visitSymbolLiteral(SymbolLiteral node) => notAChild(node); 959 ASTNode visitSymbolLiteral(SymbolLiteral node) => notAChild(node);
960 960
961 ASTNode visitThisExpression(ThisExpression node) => notAChild(node); 961 ASTNode visitThisExpression(ThisExpression node) => notAChild(node);
962 962
963 ASTNode visitThrowExpression(ThrowExpression node) { 963 ASTNode visitThrowExpression(ThrowExpression node) {
964 if (identical(_oldNode, node.expression)) { 964 if (identical(_oldNode, node.expression)) {
965 if (isCascadeAllowed2(node)) { 965 if (isCascadeAllowed2(node)) {
966 return _parser.parseExpression4(); 966 return _parser.parseExpression2();
967 } 967 }
968 return _parser.parseExpressionWithoutCascade(); 968 return _parser.parseExpressionWithoutCascade();
969 } 969 }
970 return notAChild(node); 970 return notAChild(node);
971 } 971 }
972 972
973 ASTNode visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 973 ASTNode visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
974 if (identical(_oldNode, node.documentationComment)) { 974 if (identical(_oldNode, node.documentationComment)) {
975 throw new InsufficientContextException(); 975 throw new InsufficientContextException();
976 } else if (node.metadata.contains(_oldNode)) { 976 } else if (node.metadata.contains(_oldNode)) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 1054
1055 ASTNode visitVariableDeclarationStatement(VariableDeclarationStatement node) { 1055 ASTNode visitVariableDeclarationStatement(VariableDeclarationStatement node) {
1056 if (identical(_oldNode, node.variables)) { 1056 if (identical(_oldNode, node.variables)) {
1057 throw new InsufficientContextException(); 1057 throw new InsufficientContextException();
1058 } 1058 }
1059 return notAChild(node); 1059 return notAChild(node);
1060 } 1060 }
1061 1061
1062 ASTNode visitWhileStatement(WhileStatement node) { 1062 ASTNode visitWhileStatement(WhileStatement node) {
1063 if (identical(_oldNode, node.condition)) { 1063 if (identical(_oldNode, node.condition)) {
1064 return _parser.parseExpression4(); 1064 return _parser.parseExpression2();
1065 } else if (identical(_oldNode, node.body)) { 1065 } else if (identical(_oldNode, node.body)) {
1066 return _parser.parseStatement2(); 1066 return _parser.parseStatement2();
1067 } 1067 }
1068 return notAChild(node); 1068 return notAChild(node);
1069 } 1069 }
1070 1070
1071 ASTNode visitWithClause(WithClause node) { 1071 ASTNode visitWithClause(WithClause node) {
1072 if (node.mixinTypes.contains(node)) { 1072 if (node.mixinTypes.contains(node)) {
1073 return _parser.parseTypeName(); 1073 return _parser.parseTypeName();
1074 } 1074 }
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 * Parse an expression, starting with the given token. 1408 * Parse an expression, starting with the given token.
1409 * 1409 *
1410 * @param token the first token of the expression 1410 * @param token the first token of the expression
1411 * @return the expression that was parsed, or `null` if the tokens do not repr esent a 1411 * @return the expression that was parsed, or `null` if the tokens do not repr esent a
1412 * recognizable expression 1412 * recognizable expression
1413 */ 1413 */
1414 Expression parseExpression(Token token) { 1414 Expression parseExpression(Token token) {
1415 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.Parser.parseExpression"); 1415 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.Parser.parseExpression");
1416 try { 1416 try {
1417 _currentToken = token; 1417 _currentToken = token;
1418 return parseExpression4(); 1418 return parseExpression2();
1419 } finally { 1419 } finally {
1420 instrumentation.log(); 1420 instrumentation.log();
1421 } 1421 }
1422 } 1422 }
1423 1423
1424 /** 1424 /**
1425 * Parse a statement, starting with the given token. 1425 * Parse a statement, starting with the given token.
1426 * 1426 *
1427 * @param token the first token of the statement 1427 * @param token the first token of the statement
1428 * @return the statement that was parsed, or `null` if the tokens do not repre sent a 1428 * @return the statement that was parsed, or `null` if the tokens do not repre sent a
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 * </pre> 1503 * </pre>
1504 * 1504 *
1505 * @return the argument that was parsed 1505 * @return the argument that was parsed
1506 */ 1506 */
1507 Expression parseArgument() { 1507 Expression parseArgument() {
1508 // 1508 //
1509 // Both namedArgument and expression can start with an identifier, but only namedArgument can 1509 // Both namedArgument and expression can start with an identifier, but only namedArgument can
1510 // have an identifier followed by a colon. 1510 // have an identifier followed by a colon.
1511 // 1511 //
1512 if (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 1512 if (matchesIdentifier() && matches4(peek(), TokenType.COLON)) {
1513 return new NamedExpression(parseLabel(), parseExpression4()); 1513 return new NamedExpression(parseLabel(), parseExpression2());
1514 } else { 1514 } else {
1515 return parseExpression4(); 1515 return parseExpression2();
1516 } 1516 }
1517 } 1517 }
1518 1518
1519 /** 1519 /**
1520 * Parse a list of arguments. 1520 * Parse a list of arguments.
1521 * 1521 *
1522 * <pre> 1522 * <pre>
1523 * arguments ::= 1523 * arguments ::=
1524 * '(' argumentList? ')' 1524 * '(' argumentList? ')'
1525 * 1525 *
(...skipping 17 matching lines...) Expand all
1543 Expression argument = parseArgument(); 1543 Expression argument = parseArgument();
1544 arguments.add(argument); 1544 arguments.add(argument);
1545 bool foundNamedArgument = argument is NamedExpression; 1545 bool foundNamedArgument = argument is NamedExpression;
1546 bool generatedError = false; 1546 bool generatedError = false;
1547 while (optional(TokenType.COMMA)) { 1547 while (optional(TokenType.COMMA)) {
1548 argument = parseArgument(); 1548 argument = parseArgument();
1549 arguments.add(argument); 1549 arguments.add(argument);
1550 if (foundNamedArgument) { 1550 if (foundNamedArgument) {
1551 if (!generatedError && argument is! NamedExpression) { 1551 if (!generatedError && argument is! NamedExpression) {
1552 // Report the error, once, but allow the arguments to be in any order in the AST. 1552 // Report the error, once, but allow the arguments to be in any order in the AST.
1553 reportError12(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT, []); 1553 reportError13(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT, []);
1554 generatedError = true; 1554 generatedError = true;
1555 } 1555 }
1556 } else if (argument is NamedExpression) { 1556 } else if (argument is NamedExpression) {
1557 foundNamedArgument = true; 1557 foundNamedArgument = true;
1558 } 1558 }
1559 } 1559 }
1560 // TODO(brianwilkerson) Recovery: Look at the left parenthesis to see whethe r there is a 1560 // TODO(brianwilkerson) Recovery: Look at the left parenthesis to see whethe r there is a
1561 // matching right parenthesis. If there is, then we're more likely missing a comma and should 1561 // matching right parenthesis. If there is, then we're more likely missing a comma and should
1562 // go back to parsing arguments. 1562 // go back to parsing arguments.
1563 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 1563 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 1603 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET);
1604 List<Statement> statements = new List<Statement>(); 1604 List<Statement> statements = new List<Statement>();
1605 Token statementStart = _currentToken; 1605 Token statementStart = _currentToken;
1606 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET)) { 1606 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET)) {
1607 Statement statement = parseStatement2(); 1607 Statement statement = parseStatement2();
1608 if (statement != null) { 1608 if (statement != null) {
1609 statements.add(statement); 1609 statements.add(statement);
1610 } 1610 }
1611 if (identical(_currentToken, statementStart)) { 1611 if (identical(_currentToken, statementStart)) {
1612 // Ensure that we are making progress and report an error if we're not. 1612 // Ensure that we are making progress and report an error if we're not.
1613 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 1613 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
1614 advance(); 1614 advance();
1615 } 1615 }
1616 statementStart = _currentToken; 1616 statementStart = _currentToken;
1617 } 1617 }
1618 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 1618 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
1619 return new Block(leftBracket, statements, rightBracket); 1619 return new Block(leftBracket, statements, rightBracket);
1620 } 1620 }
1621 1621
1622 /** 1622 /**
1623 * Parse a class member. 1623 * Parse a class member.
(...skipping 30 matching lines...) Expand all
1654 return parseMethodDeclaration(commentAndMetadata, modifiers.externalKeyw ord, modifiers.staticKeyword, returnType); 1654 return parseMethodDeclaration(commentAndMetadata, modifiers.externalKeyw ord, modifiers.staticKeyword, returnType);
1655 } else { 1655 } else {
1656 // 1656 //
1657 // We have found an error of some kind. Try to recover. 1657 // We have found an error of some kind. Try to recover.
1658 // 1658 //
1659 if (matchesIdentifier()) { 1659 if (matchesIdentifier()) {
1660 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) { 1660 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) {
1661 // 1661 //
1662 // We appear to have a variable declaration with a type of "void". 1662 // We appear to have a variable declaration with a type of "void".
1663 // 1663 //
1664 reportError11(ParserErrorCode.VOID_VARIABLE, returnType, []); 1664 reportError12(ParserErrorCode.VOID_VARIABLE, returnType, []);
1665 return parseInitializedIdentifierList(commentAndMetadata, modifiers. staticKeyword, validateModifiersForField(modifiers), returnType); 1665 return parseInitializedIdentifierList(commentAndMetadata, modifiers. staticKeyword, validateModifiersForField(modifiers), returnType);
1666 } 1666 }
1667 } 1667 }
1668 if (isOperator(_currentToken)) { 1668 if (isOperator(_currentToken)) {
1669 // 1669 //
1670 // We appear to have found an operator declaration without the 'operat or' keyword. 1670 // We appear to have found an operator declaration without the 'operat or' keyword.
1671 // 1671 //
1672 validateModifiersForOperator(modifiers); 1672 validateModifiersForOperator(modifiers);
1673 return parseOperator(commentAndMetadata, modifiers.externalKeyword, re turnType); 1673 return parseOperator(commentAndMetadata, modifiers.externalKeyword, re turnType);
1674 } 1674 }
1675 reportError13(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 1675 reportError14(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
1676 return null; 1676 return null;
1677 } 1677 }
1678 } else if (matches(Keyword.GET) && matchesIdentifier2(peek())) { 1678 } else if (matches(Keyword.GET) && matchesIdentifier2(peek())) {
1679 validateModifiersForGetterOrSetterOrMethod(modifiers); 1679 validateModifiersForGetterOrSetterOrMethod(modifiers);
1680 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null); 1680 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null);
1681 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { 1681 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) {
1682 validateModifiersForGetterOrSetterOrMethod(modifiers); 1682 validateModifiersForGetterOrSetterOrMethod(modifiers);
1683 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null); 1683 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null);
1684 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 1684 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) {
1685 validateModifiersForOperator(modifiers); 1685 validateModifiersForOperator(modifiers);
1686 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null); 1686 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null);
1687 } else if (!matchesIdentifier()) { 1687 } else if (!matchesIdentifier()) {
1688 if (isOperator(_currentToken)) { 1688 if (isOperator(_currentToken)) {
1689 // 1689 //
1690 // We appear to have found an operator declaration without the 'operator ' keyword. 1690 // We appear to have found an operator declaration without the 'operator ' keyword.
1691 // 1691 //
1692 validateModifiersForOperator(modifiers); 1692 validateModifiersForOperator(modifiers);
1693 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null ); 1693 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null );
1694 } 1694 }
1695 reportError13(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); 1695 reportError14(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []);
1696 return null; 1696 return null;
1697 } else if (matches4(peek(), TokenType.PERIOD) && matchesIdentifier2(peek2(2) ) && matches4(peek2(3), TokenType.OPEN_PAREN)) { 1697 } else if (matches4(peek(), TokenType.PERIOD) && matchesIdentifier2(peek2(2) ) && matches4(peek2(3), TokenType.OPEN_PAREN)) {
1698 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, val idateModifiersForConstructor(modifiers), modifiers.factoryKeyword, parseSimpleId entifier(), andAdvance, parseSimpleIdentifier(), parseFormalParameterList()); 1698 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, val idateModifiersForConstructor(modifiers), modifiers.factoryKeyword, parseSimpleId entifier(), andAdvance, parseSimpleIdentifier(), parseFormalParameterList());
1699 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { 1699 } else if (matches4(peek(), TokenType.OPEN_PAREN)) {
1700 SimpleIdentifier methodName = parseSimpleIdentifier(); 1700 SimpleIdentifier methodName = parseSimpleIdentifier();
1701 FormalParameterList parameters = parseFormalParameterList(); 1701 FormalParameterList parameters = parseFormalParameterList();
1702 if (matches5(TokenType.COLON) || modifiers.factoryKeyword != null || metho dName.name == className) { 1702 if (matches5(TokenType.COLON) || modifiers.factoryKeyword != null || metho dName.name == className) {
1703 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, v alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodName, null, null, parameters); 1703 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, v alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodName, null, null, parameters);
1704 } 1704 }
1705 validateModifiersForGetterOrSetterOrMethod(modifiers); 1705 validateModifiersForGetterOrSetterOrMethod(modifiers);
1706 validateFormalParameterList(parameters); 1706 validateFormalParameterList(parameters);
1707 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo rd, modifiers.staticKeyword, null, methodName, parameters); 1707 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo rd, modifiers.staticKeyword, null, methodName, parameters);
1708 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) { 1708 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) {
1709 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) { 1709 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) {
1710 reportError12(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); 1710 reportError13(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []);
1711 } 1711 }
1712 return parseInitializedIdentifierList(commentAndMetadata, modifiers.static Keyword, validateModifiersForField(modifiers), null); 1712 return parseInitializedIdentifierList(commentAndMetadata, modifiers.static Keyword, validateModifiersForField(modifiers), null);
1713 } 1713 }
1714 TypeName type = parseTypeName(); 1714 TypeName type = parseTypeName();
1715 if (matches(Keyword.GET) && matchesIdentifier2(peek())) { 1715 if (matches(Keyword.GET) && matchesIdentifier2(peek())) {
1716 validateModifiersForGetterOrSetterOrMethod(modifiers); 1716 validateModifiersForGetterOrSetterOrMethod(modifiers);
1717 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, type); 1717 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, type);
1718 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { 1718 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) {
1719 validateModifiersForGetterOrSetterOrMethod(modifiers); 1719 validateModifiersForGetterOrSetterOrMethod(modifiers);
1720 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, type); 1720 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, type);
(...skipping 14 matching lines...) Expand all
1735 // We appear to have found an operator declaration without the 'operator ' keyword. 1735 // We appear to have found an operator declaration without the 'operator ' keyword.
1736 // 1736 //
1737 validateModifiersForOperator(modifiers); 1737 validateModifiersForOperator(modifiers);
1738 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type ); 1738 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type );
1739 } 1739 }
1740 // 1740 //
1741 // We appear to have found an incomplete declaration before another declar ation. 1741 // We appear to have found an incomplete declaration before another declar ation.
1742 // At this point it consists of a type name, so we'll treat it as a field declaration 1742 // At this point it consists of a type name, so we'll treat it as a field declaration
1743 // with a missing field name and semicolon. 1743 // with a missing field name and semicolon.
1744 // 1744 //
1745 reportError13(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); 1745 reportError14(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []);
1746 try { 1746 try {
1747 lockErrorListener(); 1747 lockErrorListener();
1748 return parseInitializedIdentifierList(commentAndMetadata, modifiers.stat icKeyword, validateModifiersForField(modifiers), type); 1748 return parseInitializedIdentifierList(commentAndMetadata, modifiers.stat icKeyword, validateModifiersForField(modifiers), type);
1749 } finally { 1749 } finally {
1750 unlockErrorListener(); 1750 unlockErrorListener();
1751 } 1751 }
1752 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { 1752 } else if (matches4(peek(), TokenType.OPEN_PAREN)) {
1753 SimpleIdentifier methodName = parseSimpleIdentifier(); 1753 SimpleIdentifier methodName = parseSimpleIdentifier();
1754 FormalParameterList parameters = parseFormalParameterList(); 1754 FormalParameterList parameters = parseFormalParameterList();
1755 if (methodName.name == className) { 1755 if (methodName.name == className) {
1756 reportError11(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type, []); 1756 reportError12(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type, []);
1757 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, v alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodName, null, null, parameters); 1757 return parseConstructor(commentAndMetadata, modifiers.externalKeyword, v alidateModifiersForConstructor(modifiers), modifiers.factoryKeyword, methodName, null, null, parameters);
1758 } 1758 }
1759 validateModifiersForGetterOrSetterOrMethod(modifiers); 1759 validateModifiersForGetterOrSetterOrMethod(modifiers);
1760 validateFormalParameterList(parameters); 1760 validateFormalParameterList(parameters);
1761 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo rd, modifiers.staticKeyword, type, methodName, parameters); 1761 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo rd, modifiers.staticKeyword, type, methodName, parameters);
1762 } 1762 }
1763 return parseInitializedIdentifierList(commentAndMetadata, modifiers.staticKe yword, validateModifiersForField(modifiers), type); 1763 return parseInitializedIdentifierList(commentAndMetadata, modifiers.staticKe yword, validateModifiersForField(modifiers), type);
1764 } 1764 }
1765 1765
1766 /** 1766 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 bool partDirectiveFound = false; 1800 bool partDirectiveFound = false;
1801 bool directiveFoundAfterDeclaration = false; 1801 bool directiveFoundAfterDeclaration = false;
1802 List<Directive> directives = new List<Directive>(); 1802 List<Directive> directives = new List<Directive>();
1803 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ; 1803 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ;
1804 Token memberStart = _currentToken; 1804 Token memberStart = _currentToken;
1805 while (!matches5(TokenType.EOF)) { 1805 while (!matches5(TokenType.EOF)) {
1806 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 1806 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
1807 if ((matches(Keyword.IMPORT) || matches(Keyword.EXPORT) || matches(Keyword .LIBRARY) || matches(Keyword.PART)) && !matches4(peek(), TokenType.PERIOD) && !m atches4(peek(), TokenType.LT) && !matches4(peek(), TokenType.OPEN_PAREN)) { 1807 if ((matches(Keyword.IMPORT) || matches(Keyword.EXPORT) || matches(Keyword .LIBRARY) || matches(Keyword.PART)) && !matches4(peek(), TokenType.PERIOD) && !m atches4(peek(), TokenType.LT) && !matches4(peek(), TokenType.OPEN_PAREN)) {
1808 Directive directive = parseDirective(commentAndMetadata); 1808 Directive directive = parseDirective(commentAndMetadata);
1809 if (declarations.length > 0 && !directiveFoundAfterDeclaration) { 1809 if (declarations.length > 0 && !directiveFoundAfterDeclaration) {
1810 reportError12(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, []); 1810 reportError13(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, []);
1811 directiveFoundAfterDeclaration = true; 1811 directiveFoundAfterDeclaration = true;
1812 } 1812 }
1813 if (directive is LibraryDirective) { 1813 if (directive is LibraryDirective) {
1814 if (libraryDirectiveFound) { 1814 if (libraryDirectiveFound) {
1815 reportError12(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES, []); 1815 reportError13(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES, []);
1816 } else { 1816 } else {
1817 if (directives.length > 0) { 1817 if (directives.length > 0) {
1818 reportError13(ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST, directi ve.libraryToken, []); 1818 reportError14(ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST, directi ve.libraryToken, []);
1819 } 1819 }
1820 libraryDirectiveFound = true; 1820 libraryDirectiveFound = true;
1821 } 1821 }
1822 } else if (directive is PartDirective) { 1822 } else if (directive is PartDirective) {
1823 partDirectiveFound = true; 1823 partDirectiveFound = true;
1824 } else if (partDirectiveFound) { 1824 } else if (partDirectiveFound) {
1825 if (directive is ExportDirective) { 1825 if (directive is ExportDirective) {
1826 reportError13(ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, directive.keyword, []); 1826 reportError14(ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, directive.keyword, []);
1827 } else if (directive is ImportDirective) { 1827 } else if (directive is ImportDirective) {
1828 reportError13(ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, directive.keyword, []); 1828 reportError14(ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, directive.keyword, []);
1829 } 1829 }
1830 } 1830 }
1831 if (directive is PartOfDirective) { 1831 if (directive is PartOfDirective) {
1832 if (partOfDirectiveFound) { 1832 if (partOfDirectiveFound) {
1833 reportError12(ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES, []); 1833 reportError13(ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES, []);
1834 } else { 1834 } else {
1835 int directiveCount = directives.length; 1835 int directiveCount = directives.length;
1836 for (int i = 0; i < directiveCount; i++) { 1836 for (int i = 0; i < directiveCount; i++) {
1837 reportError13(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, direc tives[i].keyword, []); 1837 reportError14(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, direc tives[i].keyword, []);
1838 } 1838 }
1839 partOfDirectiveFound = true; 1839 partOfDirectiveFound = true;
1840 } 1840 }
1841 } else { 1841 } else {
1842 if (partOfDirectiveFound) { 1842 if (partOfDirectiveFound) {
1843 reportError13(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, directi ve.keyword, []); 1843 reportError14(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, directi ve.keyword, []);
1844 } 1844 }
1845 } 1845 }
1846 directives.add(directive); 1846 directives.add(directive);
1847 } else if (matches5(TokenType.SEMICOLON)) { 1847 } else if (matches5(TokenType.SEMICOLON)) {
1848 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 1848 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
1849 advance(); 1849 advance();
1850 } else { 1850 } else {
1851 CompilationUnitMember member = parseCompilationUnitMember(commentAndMeta data); 1851 CompilationUnitMember member = parseCompilationUnitMember(commentAndMeta data);
1852 if (member != null) { 1852 if (member != null) {
1853 declarations.add(member); 1853 declarations.add(member);
1854 } 1854 }
1855 } 1855 }
1856 if (identical(_currentToken, memberStart)) { 1856 if (identical(_currentToken, memberStart)) {
1857 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 1857 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
1858 advance(); 1858 advance();
1859 while (!matches5(TokenType.EOF) && !couldBeStartOfCompilationUnitMember( )) { 1859 while (!matches5(TokenType.EOF) && !couldBeStartOfCompilationUnitMember( )) {
1860 advance(); 1860 advance();
1861 } 1861 }
1862 } 1862 }
1863 memberStart = _currentToken; 1863 memberStart = _currentToken;
1864 } 1864 }
1865 return new CompilationUnit(firstToken, scriptTag, directives, declarations, _currentToken); 1865 return new CompilationUnit(firstToken, scriptTag, directives, declarations, _currentToken);
1866 } 1866 }
1867 1867
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 * 1913 *
1914 * <pre> 1914 * <pre>
1915 * expression ::= 1915 * expression ::=
1916 * assignableExpression assignmentOperator expression 1916 * assignableExpression assignmentOperator expression
1917 * | conditionalExpression cascadeSection* 1917 * | conditionalExpression cascadeSection*
1918 * | throwExpression 1918 * | throwExpression
1919 * </pre> 1919 * </pre>
1920 * 1920 *
1921 * @return the expression that was parsed 1921 * @return the expression that was parsed
1922 */ 1922 */
1923 Expression parseExpression4() { 1923 Expression parseExpression2() {
1924 if (matches(Keyword.THROW)) { 1924 if (matches(Keyword.THROW)) {
1925 return parseThrowExpression(); 1925 return parseThrowExpression();
1926 } else if (matches(Keyword.RETHROW)) { 1926 } else if (matches(Keyword.RETHROW)) {
1927 return parseRethrowExpression(); 1927 return parseRethrowExpression();
1928 } 1928 }
1929 // 1929 //
1930 // assignableExpression is a subset of conditionalExpression, so we can pars e a conditional 1930 // assignableExpression is a subset of conditionalExpression, so we can pars e a conditional
1931 // expression and then determine whether it is followed by an assignmentOper ator, checking for 1931 // expression and then determine whether it is followed by an assignmentOper ator, checking for
1932 // conformance to the restricted grammar after making that determination. 1932 // conformance to the restricted grammar after making that determination.
1933 // 1933 //
1934 Expression expression = parseConditionalExpression(); 1934 Expression expression = parseConditionalExpression();
1935 TokenType tokenType = _currentToken.type; 1935 TokenType tokenType = _currentToken.type;
1936 if (identical(tokenType, TokenType.PERIOD_PERIOD)) { 1936 if (identical(tokenType, TokenType.PERIOD_PERIOD)) {
1937 List<Expression> cascadeSections = new List<Expression>(); 1937 List<Expression> cascadeSections = new List<Expression>();
1938 while (identical(tokenType, TokenType.PERIOD_PERIOD)) { 1938 while (identical(tokenType, TokenType.PERIOD_PERIOD)) {
1939 Expression section = parseCascadeSection(); 1939 Expression section = parseCascadeSection();
1940 if (section != null) { 1940 if (section != null) {
1941 cascadeSections.add(section); 1941 cascadeSections.add(section);
1942 } 1942 }
1943 tokenType = _currentToken.type; 1943 tokenType = _currentToken.type;
1944 } 1944 }
1945 return new CascadeExpression(expression, cascadeSections); 1945 return new CascadeExpression(expression, cascadeSections);
1946 } else if (tokenType.isAssignmentOperator) { 1946 } else if (tokenType.isAssignmentOperator) {
1947 Token operator = andAdvance; 1947 Token operator = andAdvance;
1948 ensureAssignable(expression); 1948 ensureAssignable(expression);
1949 return new AssignmentExpression(expression, operator, parseExpression4()); 1949 return new AssignmentExpression(expression, operator, parseExpression2());
1950 } 1950 }
1951 return expression; 1951 return expression;
1952 } 1952 }
1953 1953
1954 /** 1954 /**
1955 * Parse an expression that does not contain any cascades. 1955 * Parse an expression that does not contain any cascades.
1956 * 1956 *
1957 * <pre> 1957 * <pre>
1958 * expressionWithoutCascade ::= 1958 * expressionWithoutCascade ::=
1959 * assignableExpression assignmentOperator expressionWithoutCascade 1959 * assignableExpression assignmentOperator expressionWithoutCascade
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 bool reportedMulipleNamedGroups = false; 2049 bool reportedMulipleNamedGroups = false;
2050 bool reportedMixedGroups = false; 2050 bool reportedMixedGroups = false;
2051 bool wasOptionalParameter = false; 2051 bool wasOptionalParameter = false;
2052 Token initialToken = null; 2052 Token initialToken = null;
2053 do { 2053 do {
2054 if (firstParameter) { 2054 if (firstParameter) {
2055 firstParameter = false; 2055 firstParameter = false;
2056 } else if (!optional(TokenType.COMMA)) { 2056 } else if (!optional(TokenType.COMMA)) {
2057 // TODO(brianwilkerson) The token is wrong, we need to recover from this case. 2057 // TODO(brianwilkerson) The token is wrong, we need to recover from this case.
2058 if (getEndToken(leftParenthesis) != null) { 2058 if (getEndToken(leftParenthesis) != null) {
2059 reportError12(ParserErrorCode.EXPECTED_TOKEN, [TokenType.COMMA.lexeme] ); 2059 reportError13(ParserErrorCode.EXPECTED_TOKEN, [TokenType.COMMA.lexeme] );
2060 } else { 2060 } else {
2061 reportError13(ParserErrorCode.MISSING_CLOSING_PARENTHESIS, _currentTok en.previous, []); 2061 reportError14(ParserErrorCode.MISSING_CLOSING_PARENTHESIS, _currentTok en.previous, []);
2062 break; 2062 break;
2063 } 2063 }
2064 } 2064 }
2065 initialToken = _currentToken; 2065 initialToken = _currentToken;
2066 // 2066 //
2067 // Handle the beginning of parameter groups. 2067 // Handle the beginning of parameter groups.
2068 // 2068 //
2069 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { 2069 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) {
2070 wasOptionalParameter = true; 2070 wasOptionalParameter = true;
2071 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) { 2071 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) {
2072 reportError12(ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS, [] ); 2072 reportError13(ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS, [] );
2073 reportedMuliplePositionalGroups = true; 2073 reportedMuliplePositionalGroups = true;
2074 } 2074 }
2075 if (leftCurlyBracket != null && !reportedMixedGroups) { 2075 if (leftCurlyBracket != null && !reportedMixedGroups) {
2076 reportError12(ParserErrorCode.MIXED_PARAMETER_GROUPS, []); 2076 reportError13(ParserErrorCode.MIXED_PARAMETER_GROUPS, []);
2077 reportedMixedGroups = true; 2077 reportedMixedGroups = true;
2078 } 2078 }
2079 leftSquareBracket = andAdvance; 2079 leftSquareBracket = andAdvance;
2080 currentParameters = positionalParameters; 2080 currentParameters = positionalParameters;
2081 kind = ParameterKind.POSITIONAL; 2081 kind = ParameterKind.POSITIONAL;
2082 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 2082 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
2083 wasOptionalParameter = true; 2083 wasOptionalParameter = true;
2084 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) { 2084 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) {
2085 reportError12(ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS, []); 2085 reportError13(ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS, []);
2086 reportedMulipleNamedGroups = true; 2086 reportedMulipleNamedGroups = true;
2087 } 2087 }
2088 if (leftSquareBracket != null && !reportedMixedGroups) { 2088 if (leftSquareBracket != null && !reportedMixedGroups) {
2089 reportError12(ParserErrorCode.MIXED_PARAMETER_GROUPS, []); 2089 reportError13(ParserErrorCode.MIXED_PARAMETER_GROUPS, []);
2090 reportedMixedGroups = true; 2090 reportedMixedGroups = true;
2091 } 2091 }
2092 leftCurlyBracket = andAdvance; 2092 leftCurlyBracket = andAdvance;
2093 currentParameters = namedParameters; 2093 currentParameters = namedParameters;
2094 kind = ParameterKind.NAMED; 2094 kind = ParameterKind.NAMED;
2095 } 2095 }
2096 // 2096 //
2097 // Parse and record the parameter. 2097 // Parse and record the parameter.
2098 // 2098 //
2099 FormalParameter parameter = parseFormalParameter(kind); 2099 FormalParameter parameter = parseFormalParameter(kind);
2100 parameters.add(parameter); 2100 parameters.add(parameter);
2101 currentParameters.add(parameter); 2101 currentParameters.add(parameter);
2102 if (identical(kind, ParameterKind.REQUIRED) && wasOptionalParameter) { 2102 if (identical(kind, ParameterKind.REQUIRED) && wasOptionalParameter) {
2103 reportError11(ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS, paramet er, []); 2103 reportError12(ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS, paramet er, []);
2104 } 2104 }
2105 // 2105 //
2106 // Handle the end of parameter groups. 2106 // Handle the end of parameter groups.
2107 // 2107 //
2108 // TODO(brianwilkerson) Improve the detection and reporting of missing and mismatched delimiters. 2108 // TODO(brianwilkerson) Improve the detection and reporting of missing and mismatched delimiters.
2109 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 2109 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) {
2110 rightSquareBracket = andAdvance; 2110 rightSquareBracket = andAdvance;
2111 currentParameters = normalParameters; 2111 currentParameters = normalParameters;
2112 if (leftSquareBracket == null) { 2112 if (leftSquareBracket == null) {
2113 if (leftCurlyBracket != null) { 2113 if (leftCurlyBracket != null) {
2114 reportError12(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["}"]); 2114 reportError13(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["}"]);
2115 rightCurlyBracket = rightSquareBracket; 2115 rightCurlyBracket = rightSquareBracket;
2116 rightSquareBracket = null; 2116 rightSquareBracket = null;
2117 } else { 2117 } else {
2118 reportError12(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GR OUP, ["["]); 2118 reportError13(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GR OUP, ["["]);
2119 } 2119 }
2120 } 2120 }
2121 kind = ParameterKind.REQUIRED; 2121 kind = ParameterKind.REQUIRED;
2122 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 2122 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
2123 rightCurlyBracket = andAdvance; 2123 rightCurlyBracket = andAdvance;
2124 currentParameters = normalParameters; 2124 currentParameters = normalParameters;
2125 if (leftCurlyBracket == null) { 2125 if (leftCurlyBracket == null) {
2126 if (leftSquareBracket != null) { 2126 if (leftSquareBracket != null) {
2127 reportError12(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["]"]); 2127 reportError13(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["]"]);
2128 rightSquareBracket = rightCurlyBracket; 2128 rightSquareBracket = rightCurlyBracket;
2129 rightCurlyBracket = null; 2129 rightCurlyBracket = null;
2130 } else { 2130 } else {
2131 reportError12(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GR OUP, ["{"]); 2131 reportError13(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GR OUP, ["{"]);
2132 } 2132 }
2133 } 2133 }
2134 kind = ParameterKind.REQUIRED; 2134 kind = ParameterKind.REQUIRED;
2135 } 2135 }
2136 } while (!matches5(TokenType.CLOSE_PAREN) && initialToken != _currentToken); 2136 } while (!matches5(TokenType.CLOSE_PAREN) && initialToken != _currentToken);
2137 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 2137 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
2138 // 2138 //
2139 // Check that the groups were closed correctly. 2139 // Check that the groups were closed correctly.
2140 // 2140 //
2141 if (leftSquareBracket != null && rightSquareBracket == null) { 2141 if (leftSquareBracket != null && rightSquareBracket == null) {
2142 reportError12(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["]" ]); 2142 reportError13(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["]" ]);
2143 } 2143 }
2144 if (leftCurlyBracket != null && rightCurlyBracket == null) { 2144 if (leftCurlyBracket != null && rightCurlyBracket == null) {
2145 reportError12(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["}" ]); 2145 reportError13(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["}" ]);
2146 } 2146 }
2147 // 2147 //
2148 // Build the parameter list. 2148 // Build the parameter list.
2149 // 2149 //
2150 if (leftSquareBracket == null) { 2150 if (leftSquareBracket == null) {
2151 leftSquareBracket = leftCurlyBracket; 2151 leftSquareBracket = leftCurlyBracket;
2152 } 2152 }
2153 if (rightSquareBracket == null) { 2153 if (rightSquareBracket == null) {
2154 rightSquareBracket = rightCurlyBracket; 2154 rightSquareBracket = rightCurlyBracket;
2155 } 2155 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2252 * Parse a map literal entry. 2252 * Parse a map literal entry.
2253 * 2253 *
2254 * <pre> 2254 * <pre>
2255 * mapLiteralEntry ::= 2255 * mapLiteralEntry ::=
2256 * expression ':' expression 2256 * expression ':' expression
2257 * </pre> 2257 * </pre>
2258 * 2258 *
2259 * @return the map literal entry that was parsed 2259 * @return the map literal entry that was parsed
2260 */ 2260 */
2261 MapLiteralEntry parseMapLiteralEntry() { 2261 MapLiteralEntry parseMapLiteralEntry() {
2262 Expression key = parseExpression4(); 2262 Expression key = parseExpression2();
2263 Token separator = expect2(TokenType.COLON); 2263 Token separator = expect2(TokenType.COLON);
2264 Expression value = parseExpression4(); 2264 Expression value = parseExpression2();
2265 return new MapLiteralEntry(key, separator, value); 2265 return new MapLiteralEntry(key, separator, value);
2266 } 2266 }
2267 2267
2268 /** 2268 /**
2269 * Parse a normal formal parameter. 2269 * Parse a normal formal parameter.
2270 * 2270 *
2271 * <pre> 2271 * <pre>
2272 * normalFormalParameter ::= 2272 * normalFormalParameter ::=
2273 * functionSignature 2273 * functionSignature
2274 * | fieldFormalParameter 2274 * | fieldFormalParameter
(...skipping 19 matching lines...) Expand all
2294 Token period = null; 2294 Token period = null;
2295 if (matches(Keyword.THIS)) { 2295 if (matches(Keyword.THIS)) {
2296 thisKeyword = andAdvance; 2296 thisKeyword = andAdvance;
2297 period = expect2(TokenType.PERIOD); 2297 period = expect2(TokenType.PERIOD);
2298 } 2298 }
2299 SimpleIdentifier identifier = parseSimpleIdentifier(); 2299 SimpleIdentifier identifier = parseSimpleIdentifier();
2300 if (matches5(TokenType.OPEN_PAREN)) { 2300 if (matches5(TokenType.OPEN_PAREN)) {
2301 FormalParameterList parameters = parseFormalParameterList(); 2301 FormalParameterList parameters = parseFormalParameterList();
2302 if (thisKeyword == null) { 2302 if (thisKeyword == null) {
2303 if (holder.keyword != null) { 2303 if (holder.keyword != null) {
2304 reportError13(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.key word, []); 2304 reportError14(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.key word, []);
2305 } 2305 }
2306 return new FunctionTypedFormalParameter(commentAndMetadata.comment, comm entAndMetadata.metadata, holder.type, identifier, parameters); 2306 return new FunctionTypedFormalParameter(commentAndMetadata.comment, comm entAndMetadata.metadata, holder.type, identifier, parameters);
2307 } else { 2307 } else {
2308 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMe tadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, p arameters); 2308 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMe tadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, p arameters);
2309 } 2309 }
2310 } 2310 }
2311 TypeName type = holder.type; 2311 TypeName type = holder.type;
2312 if (type != null) { 2312 if (type != null) {
2313 if (matches3(type.name.beginToken, Keyword.VOID)) { 2313 if (matches3(type.name.beginToken, Keyword.VOID)) {
2314 reportError13(ParserErrorCode.VOID_PARAMETER, type.name.beginToken, []); 2314 reportError14(ParserErrorCode.VOID_PARAMETER, type.name.beginToken, []);
2315 } else if (holder.keyword != null && matches3(holder.keyword, Keyword.VAR) ) { 2315 } else if (holder.keyword != null && matches3(holder.keyword, Keyword.VAR) ) {
2316 reportError13(ParserErrorCode.VAR_AND_TYPE, holder.keyword, []); 2316 reportError14(ParserErrorCode.VAR_AND_TYPE, holder.keyword, []);
2317 } 2317 }
2318 } 2318 }
2319 if (thisKeyword != null) { 2319 if (thisKeyword != null) {
2320 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMeta data.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, nul l); 2320 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMeta data.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, nul l);
2321 } 2321 }
2322 return new SimpleFormalParameter(commentAndMetadata.comment, commentAndMetad ata.metadata, holder.keyword, holder.type, identifier); 2322 return new SimpleFormalParameter(commentAndMetadata.comment, commentAndMetad ata.metadata, holder.keyword, holder.type, identifier);
2323 } 2323 }
2324 2324
2325 /** 2325 /**
2326 * Parse a prefixed identifier. 2326 * Parse a prefixed identifier.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 * identifier ::= 2368 * identifier ::=
2369 * IDENTIFIER 2369 * IDENTIFIER
2370 * </pre> 2370 * </pre>
2371 * 2371 *
2372 * @return the simple identifier that was parsed 2372 * @return the simple identifier that was parsed
2373 */ 2373 */
2374 SimpleIdentifier parseSimpleIdentifier() { 2374 SimpleIdentifier parseSimpleIdentifier() {
2375 if (matchesIdentifier()) { 2375 if (matchesIdentifier()) {
2376 return new SimpleIdentifier(andAdvance); 2376 return new SimpleIdentifier(andAdvance);
2377 } 2377 }
2378 reportError12(ParserErrorCode.MISSING_IDENTIFIER, []); 2378 reportError13(ParserErrorCode.MISSING_IDENTIFIER, []);
2379 return createSyntheticIdentifier(); 2379 return createSyntheticIdentifier();
2380 } 2380 }
2381 2381
2382 /** 2382 /**
2383 * Parse a statement. 2383 * Parse a statement.
2384 * 2384 *
2385 * <pre> 2385 * <pre>
2386 * statement ::= 2386 * statement ::=
2387 * label* nonLabeledStatement 2387 * label* nonLabeledStatement
2388 * </pre> 2388 * </pre>
(...skipping 27 matching lines...) Expand all
2416 List<StringLiteral> strings = new List<StringLiteral>(); 2416 List<StringLiteral> strings = new List<StringLiteral>();
2417 while (matches5(TokenType.STRING)) { 2417 while (matches5(TokenType.STRING)) {
2418 Token string = andAdvance; 2418 Token string = andAdvance;
2419 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(TokenT ype.STRING_INTERPOLATION_IDENTIFIER)) { 2419 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(TokenT ype.STRING_INTERPOLATION_IDENTIFIER)) {
2420 strings.add(parseStringInterpolation(string)); 2420 strings.add(parseStringInterpolation(string));
2421 } else { 2421 } else {
2422 strings.add(new SimpleStringLiteral(string, computeStringValue(string.le xeme, true, true))); 2422 strings.add(new SimpleStringLiteral(string, computeStringValue(string.le xeme, true, true)));
2423 } 2423 }
2424 } 2424 }
2425 if (strings.length < 1) { 2425 if (strings.length < 1) {
2426 reportError12(ParserErrorCode.EXPECTED_STRING_LITERAL, []); 2426 reportError13(ParserErrorCode.EXPECTED_STRING_LITERAL, []);
2427 return createSyntheticStringLiteral(); 2427 return createSyntheticStringLiteral();
2428 } else if (strings.length == 1) { 2428 } else if (strings.length == 1) {
2429 return strings[0]; 2429 return strings[0];
2430 } else { 2430 } else {
2431 return new AdjacentStrings(strings); 2431 return new AdjacentStrings(strings);
2432 } 2432 }
2433 } 2433 }
2434 2434
2435 /** 2435 /**
2436 * Parse a list of type arguments. 2436 * Parse a list of type arguments.
(...skipping 25 matching lines...) Expand all
2462 * <pre> 2462 * <pre>
2463 * type ::= 2463 * type ::=
2464 * qualified typeArguments? 2464 * qualified typeArguments?
2465 * </pre> 2465 * </pre>
2466 * 2466 *
2467 * @return the type name that was parsed 2467 * @return the type name that was parsed
2468 */ 2468 */
2469 TypeName parseTypeName() { 2469 TypeName parseTypeName() {
2470 Identifier typeName; 2470 Identifier typeName;
2471 if (matches(Keyword.VAR)) { 2471 if (matches(Keyword.VAR)) {
2472 reportError12(ParserErrorCode.VAR_AS_TYPE_NAME, []); 2472 reportError13(ParserErrorCode.VAR_AS_TYPE_NAME, []);
2473 typeName = new SimpleIdentifier(andAdvance); 2473 typeName = new SimpleIdentifier(andAdvance);
2474 } else if (matchesIdentifier()) { 2474 } else if (matchesIdentifier()) {
2475 typeName = parsePrefixedIdentifier(); 2475 typeName = parsePrefixedIdentifier();
2476 } else { 2476 } else {
2477 typeName = createSyntheticIdentifier(); 2477 typeName = createSyntheticIdentifier();
2478 reportError12(ParserErrorCode.EXPECTED_TYPE_NAME, []); 2478 reportError13(ParserErrorCode.EXPECTED_TYPE_NAME, []);
2479 } 2479 }
2480 TypeArgumentList typeArguments = null; 2480 TypeArgumentList typeArguments = null;
2481 if (matches5(TokenType.LT)) { 2481 if (matches5(TokenType.LT)) {
2482 typeArguments = parseTypeArgumentList(); 2482 typeArguments = parseTypeArgumentList();
2483 } 2483 }
2484 return new TypeName(typeName, typeArguments); 2484 return new TypeName(typeName, typeArguments);
2485 } 2485 }
2486 2486
2487 /** 2487 /**
2488 * Parse a type parameter. 2488 * Parse a type parameter.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 * value is invalid. 2563 * value is invalid.
2564 * 2564 *
2565 * @param builder the builder to which the scalar value is to be appended 2565 * @param builder the builder to which the scalar value is to be appended
2566 * @param escapeSequence the escape sequence that was parsed to produce the sc alar value 2566 * @param escapeSequence the escape sequence that was parsed to produce the sc alar value
2567 * @param scalarValue the value to be appended 2567 * @param scalarValue the value to be appended
2568 * @param startIndex the index of the first character representing the scalar value 2568 * @param startIndex the index of the first character representing the scalar value
2569 * @param endIndex the index of the last character representing the scalar val ue 2569 * @param endIndex the index of the last character representing the scalar val ue
2570 */ 2570 */
2571 void appendScalarValue(JavaStringBuilder builder, String escapeSequence, int s calarValue, int startIndex, int endIndex) { 2571 void appendScalarValue(JavaStringBuilder builder, String escapeSequence, int s calarValue, int startIndex, int endIndex) {
2572 if (scalarValue < 0 || scalarValue > Character.MAX_CODE_POINT || (scalarValu e >= 0xD800 && scalarValue <= 0xDFFF)) { 2572 if (scalarValue < 0 || scalarValue > Character.MAX_CODE_POINT || (scalarValu e >= 0xD800 && scalarValue <= 0xDFFF)) {
2573 reportError12(ParserErrorCode.INVALID_CODE_POINT, [escapeSequence]); 2573 reportError13(ParserErrorCode.INVALID_CODE_POINT, [escapeSequence]);
2574 return; 2574 return;
2575 } 2575 }
2576 if (scalarValue < Character.MAX_VALUE) { 2576 if (scalarValue < Character.MAX_VALUE) {
2577 builder.appendChar(scalarValue); 2577 builder.appendChar(scalarValue);
2578 } else { 2578 } else {
2579 builder.append(Character.toChars(scalarValue)); 2579 builder.append(Character.toChars(scalarValue));
2580 } 2580 }
2581 } 2581 }
2582 2582
2583 /** 2583 /**
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
2723 * 2723 *
2724 * assignableSelector ::= 2724 * assignableSelector ::=
2725 * '[' expression ']' 2725 * '[' expression ']'
2726 * | '.' identifier 2726 * | '.' identifier
2727 * </pre> 2727 * </pre>
2728 * 2728 *
2729 * @param expression the expression being checked 2729 * @param expression the expression being checked
2730 */ 2730 */
2731 void ensureAssignable(Expression expression) { 2731 void ensureAssignable(Expression expression) {
2732 if (expression != null && !expression.isAssignable) { 2732 if (expression != null && !expression.isAssignable) {
2733 reportError12(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE, []); 2733 reportError13(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE, []);
2734 } 2734 }
2735 } 2735 }
2736 2736
2737 /** 2737 /**
2738 * If the current token is a keyword matching the given string, return it afte r advancing to the 2738 * If the current token is a keyword matching the given string, return it afte r advancing to the
2739 * next token. Otherwise report an error and return the current token without advancing. 2739 * next token. Otherwise report an error and return the current token without advancing.
2740 * 2740 *
2741 * @param keyword the keyword that is expected 2741 * @param keyword the keyword that is expected
2742 * @return the token that matched the given type 2742 * @return the token that matched the given type
2743 */ 2743 */
2744 Token expect(Keyword keyword) { 2744 Token expect(Keyword keyword) {
2745 if (matches(keyword)) { 2745 if (matches(keyword)) {
2746 return andAdvance; 2746 return andAdvance;
2747 } 2747 }
2748 // Remove uses of this method in favor of matches? 2748 // Remove uses of this method in favor of matches?
2749 // Pass in the error code to use to report the error? 2749 // Pass in the error code to use to report the error?
2750 reportError12(ParserErrorCode.EXPECTED_TOKEN, [keyword.syntax]); 2750 reportError13(ParserErrorCode.EXPECTED_TOKEN, [keyword.syntax]);
2751 return _currentToken; 2751 return _currentToken;
2752 } 2752 }
2753 2753
2754 /** 2754 /**
2755 * If the current token has the expected type, return it after advancing to th e next token. 2755 * If the current token has the expected type, return it after advancing to th e next token.
2756 * Otherwise report an error and return the current token without advancing. 2756 * Otherwise report an error and return the current token without advancing.
2757 * 2757 *
2758 * @param type the type of token that is expected 2758 * @param type the type of token that is expected
2759 * @return the token that matched the given type 2759 * @return the token that matched the given type
2760 */ 2760 */
2761 Token expect2(TokenType type) { 2761 Token expect2(TokenType type) {
2762 if (matches5(type)) { 2762 if (matches5(type)) {
2763 return andAdvance; 2763 return andAdvance;
2764 } 2764 }
2765 // Remove uses of this method in favor of matches? 2765 // Remove uses of this method in favor of matches?
2766 // Pass in the error code to use to report the error? 2766 // Pass in the error code to use to report the error?
2767 if (identical(type, TokenType.SEMICOLON)) { 2767 if (identical(type, TokenType.SEMICOLON)) {
2768 reportError13(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [typ e.lexeme]); 2768 reportError14(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [typ e.lexeme]);
2769 } else { 2769 } else {
2770 reportError12(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]); 2770 reportError13(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]);
2771 } 2771 }
2772 return _currentToken; 2772 return _currentToken;
2773 } 2773 }
2774 2774
2775 /** 2775 /**
2776 * Search the given list of ranges for a range that contains the given index. Return the range 2776 * Search the given list of ranges for a range that contains the given index. Return the range
2777 * that was found, or `null` if none of the ranges contain the index. 2777 * that was found, or `null` if none of the ranges contain the index.
2778 * 2778 *
2779 * @param ranges the ranges to be searched 2779 * @param ranges the ranges to be searched
2780 * @param index the index contained in the returned range 2780 * @param index the index contained in the returned range
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
3301 * <pre> 3301 * <pre>
3302 * argumentDefinitionTest ::= 3302 * argumentDefinitionTest ::=
3303 * '?' identifier 3303 * '?' identifier
3304 * </pre> 3304 * </pre>
3305 * 3305 *
3306 * @return the argument definition test that was parsed 3306 * @return the argument definition test that was parsed
3307 */ 3307 */
3308 ArgumentDefinitionTest parseArgumentDefinitionTest() { 3308 ArgumentDefinitionTest parseArgumentDefinitionTest() {
3309 Token question = expect2(TokenType.QUESTION); 3309 Token question = expect2(TokenType.QUESTION);
3310 SimpleIdentifier identifier = parseSimpleIdentifier(); 3310 SimpleIdentifier identifier = parseSimpleIdentifier();
3311 reportError13(ParserErrorCode.DEPRECATED_ARGUMENT_DEFINITION_TEST, question, []); 3311 reportError14(ParserErrorCode.DEPRECATED_ARGUMENT_DEFINITION_TEST, question, []);
3312 return new ArgumentDefinitionTest(question, identifier); 3312 return new ArgumentDefinitionTest(question, identifier);
3313 } 3313 }
3314 3314
3315 /** 3315 /**
3316 * Parse an assert statement. 3316 * Parse an assert statement.
3317 * 3317 *
3318 * <pre> 3318 * <pre>
3319 * assertStatement ::= 3319 * assertStatement ::=
3320 * 'assert' '(' conditionalExpression ')' ';' 3320 * 'assert' '(' conditionalExpression ')' ';'
3321 * </pre> 3321 * </pre>
3322 * 3322 *
3323 * @return the assert statement 3323 * @return the assert statement
3324 */ 3324 */
3325 AssertStatement parseAssertStatement() { 3325 AssertStatement parseAssertStatement() {
3326 Token keyword = expect(Keyword.ASSERT); 3326 Token keyword = expect(Keyword.ASSERT);
3327 Token leftParen = expect2(TokenType.OPEN_PAREN); 3327 Token leftParen = expect2(TokenType.OPEN_PAREN);
3328 Expression expression = parseExpression4(); 3328 Expression expression = parseExpression2();
3329 if (expression is AssignmentExpression) { 3329 if (expression is AssignmentExpression) {
3330 reportError11(ParserErrorCode.ASSERT_DOES_NOT_TAKE_ASSIGNMENT, expression, []); 3330 reportError12(ParserErrorCode.ASSERT_DOES_NOT_TAKE_ASSIGNMENT, expression, []);
3331 } else if (expression is CascadeExpression) { 3331 } else if (expression is CascadeExpression) {
3332 reportError11(ParserErrorCode.ASSERT_DOES_NOT_TAKE_CASCADE, expression, [] ); 3332 reportError12(ParserErrorCode.ASSERT_DOES_NOT_TAKE_CASCADE, expression, [] );
3333 } else if (expression is ThrowExpression) { 3333 } else if (expression is ThrowExpression) {
3334 reportError11(ParserErrorCode.ASSERT_DOES_NOT_TAKE_THROW, expression, []); 3334 reportError12(ParserErrorCode.ASSERT_DOES_NOT_TAKE_THROW, expression, []);
3335 } else if (expression is RethrowExpression) { 3335 } else if (expression is RethrowExpression) {
3336 reportError11(ParserErrorCode.ASSERT_DOES_NOT_TAKE_RETHROW, expression, [] ); 3336 reportError12(ParserErrorCode.ASSERT_DOES_NOT_TAKE_RETHROW, expression, [] );
3337 } 3337 }
3338 Token rightParen = expect2(TokenType.CLOSE_PAREN); 3338 Token rightParen = expect2(TokenType.CLOSE_PAREN);
3339 Token semicolon = expect2(TokenType.SEMICOLON); 3339 Token semicolon = expect2(TokenType.SEMICOLON);
3340 return new AssertStatement(keyword, leftParen, expression, rightParen, semic olon); 3340 return new AssertStatement(keyword, leftParen, expression, rightParen, semic olon);
3341 } 3341 }
3342 3342
3343 /** 3343 /**
3344 * Parse an assignable expression. 3344 * Parse an assignable expression.
3345 * 3345 *
3346 * <pre> 3346 * <pre>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3405 * | '.' identifier 3405 * | '.' identifier
3406 * </pre> 3406 * </pre>
3407 * 3407 *
3408 * @param prefix the expression preceding the selector 3408 * @param prefix the expression preceding the selector
3409 * @param optional `true` if the selector is optional 3409 * @param optional `true` if the selector is optional
3410 * @return the assignable selector that was parsed 3410 * @return the assignable selector that was parsed
3411 */ 3411 */
3412 Expression parseAssignableSelector(Expression prefix, bool optional) { 3412 Expression parseAssignableSelector(Expression prefix, bool optional) {
3413 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { 3413 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) {
3414 Token leftBracket = andAdvance; 3414 Token leftBracket = andAdvance;
3415 Expression index = parseExpression4(); 3415 Expression index = parseExpression2();
3416 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 3416 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
3417 return new IndexExpression.forTarget(prefix, leftBracket, index, rightBrac ket); 3417 return new IndexExpression.forTarget(prefix, leftBracket, index, rightBrac ket);
3418 } else if (matches5(TokenType.PERIOD)) { 3418 } else if (matches5(TokenType.PERIOD)) {
3419 Token period = andAdvance; 3419 Token period = andAdvance;
3420 return new PropertyAccess(prefix, period, parseSimpleIdentifier()); 3420 return new PropertyAccess(prefix, period, parseSimpleIdentifier());
3421 } else { 3421 } else {
3422 if (!optional) { 3422 if (!optional) {
3423 // Report the missing selector. 3423 // Report the missing selector.
3424 reportError12(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); 3424 reportError13(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []);
3425 } 3425 }
3426 return prefix; 3426 return prefix;
3427 } 3427 }
3428 } 3428 }
3429 3429
3430 /** 3430 /**
3431 * Parse a bitwise and expression. 3431 * Parse a bitwise and expression.
3432 * 3432 *
3433 * <pre> 3433 * <pre>
3434 * bitwiseAndExpression ::= 3434 * bitwiseAndExpression ::=
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3487 * 3487 *
3488 * @return the break statement that was parsed 3488 * @return the break statement that was parsed
3489 */ 3489 */
3490 Statement parseBreakStatement() { 3490 Statement parseBreakStatement() {
3491 Token breakKeyword = expect(Keyword.BREAK); 3491 Token breakKeyword = expect(Keyword.BREAK);
3492 SimpleIdentifier label = null; 3492 SimpleIdentifier label = null;
3493 if (matchesIdentifier()) { 3493 if (matchesIdentifier()) {
3494 label = parseSimpleIdentifier(); 3494 label = parseSimpleIdentifier();
3495 } 3495 }
3496 if (!_inLoop && !_inSwitch && label == null) { 3496 if (!_inLoop && !_inSwitch && label == null) {
3497 reportError13(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []); 3497 reportError14(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []);
3498 } 3498 }
3499 Token semicolon = expect2(TokenType.SEMICOLON); 3499 Token semicolon = expect2(TokenType.SEMICOLON);
3500 return new BreakStatement(breakKeyword, label, semicolon); 3500 return new BreakStatement(breakKeyword, label, semicolon);
3501 } 3501 }
3502 3502
3503 /** 3503 /**
3504 * Parse a cascade section. 3504 * Parse a cascade section.
3505 * 3505 *
3506 * <pre> 3506 * <pre>
3507 * cascadeSection ::= 3507 * cascadeSection ::=
(...skipping 10 matching lines...) Expand all
3518 * @return the expression representing the cascaded method invocation 3518 * @return the expression representing the cascaded method invocation
3519 */ 3519 */
3520 Expression parseCascadeSection() { 3520 Expression parseCascadeSection() {
3521 Token period = expect2(TokenType.PERIOD_PERIOD); 3521 Token period = expect2(TokenType.PERIOD_PERIOD);
3522 Expression expression = null; 3522 Expression expression = null;
3523 SimpleIdentifier functionName = null; 3523 SimpleIdentifier functionName = null;
3524 if (matchesIdentifier()) { 3524 if (matchesIdentifier()) {
3525 functionName = parseSimpleIdentifier(); 3525 functionName = parseSimpleIdentifier();
3526 } else if (identical(_currentToken.type, TokenType.OPEN_SQUARE_BRACKET)) { 3526 } else if (identical(_currentToken.type, TokenType.OPEN_SQUARE_BRACKET)) {
3527 Token leftBracket = andAdvance; 3527 Token leftBracket = andAdvance;
3528 Expression index = parseExpression4(); 3528 Expression index = parseExpression2();
3529 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 3529 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
3530 expression = new IndexExpression.forCascade(period, leftBracket, index, ri ghtBracket); 3530 expression = new IndexExpression.forCascade(period, leftBracket, index, ri ghtBracket);
3531 period = null; 3531 period = null;
3532 } else { 3532 } else {
3533 reportError13(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, [_current Token.lexeme]); 3533 reportError14(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, [_current Token.lexeme]);
3534 functionName = createSyntheticIdentifier(); 3534 functionName = createSyntheticIdentifier();
3535 } 3535 }
3536 if (identical(_currentToken.type, TokenType.OPEN_PAREN)) { 3536 if (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
3537 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) { 3537 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
3538 if (functionName != null) { 3538 if (functionName != null) {
3539 expression = new MethodInvocation(expression, period, functionName, pa rseArgumentList()); 3539 expression = new MethodInvocation(expression, period, functionName, pa rseArgumentList());
3540 period = null; 3540 period = null;
3541 functionName = null; 3541 functionName = null;
3542 } else if (expression == null) { 3542 } else if (expression == null) {
3543 // It should not be possible to get here. 3543 // It should not be possible to get here.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
3614 // 3614 //
3615 ExtendsClause extendsClause = null; 3615 ExtendsClause extendsClause = null;
3616 WithClause withClause = null; 3616 WithClause withClause = null;
3617 ImplementsClause implementsClause = null; 3617 ImplementsClause implementsClause = null;
3618 bool foundClause = true; 3618 bool foundClause = true;
3619 while (foundClause) { 3619 while (foundClause) {
3620 if (matches(Keyword.EXTENDS)) { 3620 if (matches(Keyword.EXTENDS)) {
3621 if (extendsClause == null) { 3621 if (extendsClause == null) {
3622 extendsClause = parseExtendsClause(); 3622 extendsClause = parseExtendsClause();
3623 if (withClause != null) { 3623 if (withClause != null) {
3624 reportError13(ParserErrorCode.WITH_BEFORE_EXTENDS, withClause.withKe yword, []); 3624 reportError14(ParserErrorCode.WITH_BEFORE_EXTENDS, withClause.withKe yword, []);
3625 } else if (implementsClause != null) { 3625 } else if (implementsClause != null) {
3626 reportError13(ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS, implementsC lause.keyword, []); 3626 reportError14(ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS, implementsC lause.keyword, []);
3627 } 3627 }
3628 } else { 3628 } else {
3629 reportError13(ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES, extendsClause. keyword, []); 3629 reportError14(ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES, extendsClause. keyword, []);
3630 parseExtendsClause(); 3630 parseExtendsClause();
3631 } 3631 }
3632 } else if (matches(Keyword.WITH)) { 3632 } else if (matches(Keyword.WITH)) {
3633 if (withClause == null) { 3633 if (withClause == null) {
3634 withClause = parseWithClause(); 3634 withClause = parseWithClause();
3635 if (implementsClause != null) { 3635 if (implementsClause != null) {
3636 reportError13(ParserErrorCode.IMPLEMENTS_BEFORE_WITH, implementsClau se.keyword, []); 3636 reportError14(ParserErrorCode.IMPLEMENTS_BEFORE_WITH, implementsClau se.keyword, []);
3637 } 3637 }
3638 } else { 3638 } else {
3639 reportError13(ParserErrorCode.MULTIPLE_WITH_CLAUSES, withClause.withKe yword, []); 3639 reportError14(ParserErrorCode.MULTIPLE_WITH_CLAUSES, withClause.withKe yword, []);
3640 parseWithClause(); 3640 parseWithClause();
3641 } 3641 }
3642 } else if (matches(Keyword.IMPLEMENTS)) { 3642 } else if (matches(Keyword.IMPLEMENTS)) {
3643 if (implementsClause == null) { 3643 if (implementsClause == null) {
3644 implementsClause = parseImplementsClause(); 3644 implementsClause = parseImplementsClause();
3645 } else { 3645 } else {
3646 reportError13(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, implementsC lause.keyword, []); 3646 reportError14(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, implementsC lause.keyword, []);
3647 parseImplementsClause(); 3647 parseImplementsClause();
3648 } 3648 }
3649 } else { 3649 } else {
3650 foundClause = false; 3650 foundClause = false;
3651 } 3651 }
3652 } 3652 }
3653 if (withClause != null && extendsClause == null) { 3653 if (withClause != null && extendsClause == null) {
3654 reportError13(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withKeyword , []); 3654 reportError14(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withKeyword , []);
3655 } 3655 }
3656 // 3656 //
3657 // Look for and skip over the extra-lingual 'native' specification. 3657 // Look for and skip over the extra-lingual 'native' specification.
3658 // 3658 //
3659 NativeClause nativeClause = null; 3659 NativeClause nativeClause = null;
3660 if (matches2(_NATIVE) && matches4(peek(), TokenType.STRING)) { 3660 if (matches2(_NATIVE) && matches4(peek(), TokenType.STRING)) {
3661 nativeClause = parseNativeClause(); 3661 nativeClause = parseNativeClause();
3662 } 3662 }
3663 // 3663 //
3664 // Parse the body of the class. 3664 // Parse the body of the class.
3665 // 3665 //
3666 Token leftBracket = null; 3666 Token leftBracket = null;
3667 List<ClassMember> members = null; 3667 List<ClassMember> members = null;
3668 Token rightBracket = null; 3668 Token rightBracket = null;
3669 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 3669 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
3670 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 3670 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET);
3671 members = parseClassMembers(className, getEndToken(leftBracket)); 3671 members = parseClassMembers(className, getEndToken(leftBracket));
3672 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 3672 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
3673 } else { 3673 } else {
3674 leftBracket = createSyntheticToken2(TokenType.OPEN_CURLY_BRACKET); 3674 leftBracket = createSyntheticToken2(TokenType.OPEN_CURLY_BRACKET);
3675 rightBracket = createSyntheticToken2(TokenType.CLOSE_CURLY_BRACKET); 3675 rightBracket = createSyntheticToken2(TokenType.CLOSE_CURLY_BRACKET);
3676 reportError12(ParserErrorCode.MISSING_CLASS_BODY, []); 3676 reportError13(ParserErrorCode.MISSING_CLASS_BODY, []);
3677 } 3677 }
3678 ClassDeclaration classDeclaration = new ClassDeclaration(commentAndMetadata. comment, commentAndMetadata.metadata, abstractKeyword, keyword, name, typeParame ters, extendsClause, withClause, implementsClause, leftBracket, members, rightBr acket); 3678 ClassDeclaration classDeclaration = new ClassDeclaration(commentAndMetadata. comment, commentAndMetadata.metadata, abstractKeyword, keyword, name, typeParame ters, extendsClause, withClause, implementsClause, leftBracket, members, rightBr acket);
3679 classDeclaration.nativeClause = nativeClause; 3679 classDeclaration.nativeClause = nativeClause;
3680 return classDeclaration; 3680 return classDeclaration;
3681 } 3681 }
3682 3682
3683 /** 3683 /**
3684 * Parse a list of class members. 3684 * Parse a list of class members.
3685 * 3685 *
3686 * <pre> 3686 * <pre>
3687 * classMembers ::= 3687 * classMembers ::=
3688 * (metadata memberDefinition)* 3688 * (metadata memberDefinition)*
3689 * </pre> 3689 * </pre>
3690 * 3690 *
3691 * @param className the name of the class whose members are being parsed 3691 * @param className the name of the class whose members are being parsed
3692 * @param closingBracket the closing bracket for the class, or `null` if the c losing bracket 3692 * @param closingBracket the closing bracket for the class, or `null` if the c losing bracket
3693 * is missing 3693 * is missing
3694 * @return the list of class members that were parsed 3694 * @return the list of class members that were parsed
3695 */ 3695 */
3696 List<ClassMember> parseClassMembers(String className, Token closingBracket) { 3696 List<ClassMember> parseClassMembers(String className, Token closingBracket) {
3697 List<ClassMember> members = new List<ClassMember>(); 3697 List<ClassMember> members = new List<ClassMember>();
3698 Token memberStart = _currentToken; 3698 Token memberStart = _currentToken;
3699 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && (closingBracket != null || (!matches(Keyword.CLASS) && !matches(Keyword.TYPED EF)))) { 3699 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && (closingBracket != null || (!matches(Keyword.CLASS) && !matches(Keyword.TYPED EF)))) {
3700 if (matches5(TokenType.SEMICOLON)) { 3700 if (matches5(TokenType.SEMICOLON)) {
3701 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 3701 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
3702 advance(); 3702 advance();
3703 } else { 3703 } else {
3704 ClassMember member = parseClassMember(className); 3704 ClassMember member = parseClassMember(className);
3705 if (member != null) { 3705 if (member != null) {
3706 members.add(member); 3706 members.add(member);
3707 } 3707 }
3708 } 3708 }
3709 if (identical(_currentToken, memberStart)) { 3709 if (identical(_currentToken, memberStart)) {
3710 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 3710 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
3711 advance(); 3711 advance();
3712 } 3712 }
3713 memberStart = _currentToken; 3713 memberStart = _currentToken;
3714 } 3714 }
3715 return members; 3715 return members;
3716 } 3716 }
3717 3717
3718 /** 3718 /**
3719 * Parse a class type alias. 3719 * Parse a class type alias.
3720 * 3720 *
(...skipping 27 matching lines...) Expand all
3748 } 3748 }
3749 ImplementsClause implementsClause = null; 3749 ImplementsClause implementsClause = null;
3750 if (matches(Keyword.IMPLEMENTS)) { 3750 if (matches(Keyword.IMPLEMENTS)) {
3751 implementsClause = parseImplementsClause(); 3751 implementsClause = parseImplementsClause();
3752 } 3752 }
3753 Token semicolon; 3753 Token semicolon;
3754 if (matches5(TokenType.SEMICOLON)) { 3754 if (matches5(TokenType.SEMICOLON)) {
3755 semicolon = andAdvance; 3755 semicolon = andAdvance;
3756 } else { 3756 } else {
3757 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 3757 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
3758 reportError12(ParserErrorCode.EXPECTED_TOKEN, [TokenType.SEMICOLON.lexem e]); 3758 reportError13(ParserErrorCode.EXPECTED_TOKEN, [TokenType.SEMICOLON.lexem e]);
3759 Token leftBracket = andAdvance; 3759 Token leftBracket = andAdvance;
3760 parseClassMembers(className.name, getEndToken(leftBracket)); 3760 parseClassMembers(className.name, getEndToken(leftBracket));
3761 expect2(TokenType.CLOSE_CURLY_BRACKET); 3761 expect2(TokenType.CLOSE_CURLY_BRACKET);
3762 } else { 3762 } else {
3763 reportError13(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [T okenType.SEMICOLON.lexeme]); 3763 reportError14(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [T okenType.SEMICOLON.lexeme]);
3764 } 3764 }
3765 semicolon = createSyntheticToken2(TokenType.SEMICOLON); 3765 semicolon = createSyntheticToken2(TokenType.SEMICOLON);
3766 } 3766 }
3767 return new ClassTypeAlias(commentAndMetadata.comment, commentAndMetadata.met adata, classKeyword, className, typeParameters, equals, abstractKeyword, supercl ass, withClause, implementsClause, semicolon); 3767 return new ClassTypeAlias(commentAndMetadata.comment, commentAndMetadata.met adata, classKeyword, className, typeParameters, equals, abstractKeyword, supercl ass, withClause, implementsClause, semicolon);
3768 } 3768 }
3769 3769
3770 /** 3770 /**
3771 * Parse a list of combinators in a directive. 3771 * Parse a list of combinators in a directive.
3772 * 3772 *
3773 * <pre> 3773 * <pre>
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
3952 } else if (matches(Keyword.TYPEDEF) && !matches4(peek(), TokenType.PERIOD) & & !matches4(peek(), TokenType.LT) && !matches4(peek(), TokenType.OPEN_PAREN)) { 3952 } else if (matches(Keyword.TYPEDEF) && !matches4(peek(), TokenType.PERIOD) & & !matches4(peek(), TokenType.LT) && !matches4(peek(), TokenType.OPEN_PAREN)) {
3953 validateModifiersForTypedef(modifiers); 3953 validateModifiersForTypedef(modifiers);
3954 return parseTypeAlias(commentAndMetadata); 3954 return parseTypeAlias(commentAndMetadata);
3955 } 3955 }
3956 if (matches(Keyword.VOID)) { 3956 if (matches(Keyword.VOID)) {
3957 TypeName returnType = parseReturnType(); 3957 TypeName returnType = parseReturnType();
3958 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(p eek())) { 3958 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(p eek())) {
3959 validateModifiersForTopLevelFunction(modifiers); 3959 validateModifiersForTopLevelFunction(modifiers);
3960 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType); 3960 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType);
3961 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 3961 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) {
3962 reportError13(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 3962 reportError14(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []);
3963 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, mo difiers.externalKeyword, returnType)); 3963 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, mo difiers.externalKeyword, returnType));
3964 } else if (matchesIdentifier() && matchesAny(peek(), [ 3964 } else if (matchesIdentifier() && matchesAny(peek(), [
3965 TokenType.OPEN_PAREN, 3965 TokenType.OPEN_PAREN,
3966 TokenType.OPEN_CURLY_BRACKET, 3966 TokenType.OPEN_CURLY_BRACKET,
3967 TokenType.FUNCTION])) { 3967 TokenType.FUNCTION])) {
3968 validateModifiersForTopLevelFunction(modifiers); 3968 validateModifiersForTopLevelFunction(modifiers);
3969 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType); 3969 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType);
3970 } else { 3970 } else {
3971 // 3971 //
3972 // We have found an error of some kind. Try to recover. 3972 // We have found an error of some kind. Try to recover.
3973 // 3973 //
3974 if (matchesIdentifier()) { 3974 if (matchesIdentifier()) {
3975 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) { 3975 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) {
3976 // 3976 //
3977 // We appear to have a variable declaration with a type of "void". 3977 // We appear to have a variable declaration with a type of "void".
3978 // 3978 //
3979 reportError11(ParserErrorCode.VOID_VARIABLE, returnType, []); 3979 reportError12(ParserErrorCode.VOID_VARIABLE, returnType, []);
3980 return new TopLevelVariableDeclaration(commentAndMetadata.comment, c ommentAndMetadata.metadata, parseVariableDeclarationList2(null, validateModifier sForTopLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON)); 3980 return new TopLevelVariableDeclaration(commentAndMetadata.comment, c ommentAndMetadata.metadata, parseVariableDeclarationList2(null, validateModifier sForTopLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON));
3981 } 3981 }
3982 } 3982 }
3983 reportError13(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 3983 reportError14(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
3984 return null; 3984 return null;
3985 } 3985 }
3986 } else if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifi er2(peek())) { 3986 } else if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifi er2(peek())) {
3987 validateModifiersForTopLevelFunction(modifiers); 3987 validateModifiersForTopLevelFunction(modifiers);
3988 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null); 3988 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null);
3989 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 3989 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) {
3990 reportError13(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 3990 reportError14(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []);
3991 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, null)); 3991 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, null));
3992 } else if (!matchesIdentifier()) { 3992 } else if (!matchesIdentifier()) {
3993 reportError13(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 3993 reportError14(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
3994 return null; 3994 return null;
3995 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { 3995 } else if (matches4(peek(), TokenType.OPEN_PAREN)) {
3996 validateModifiersForTopLevelFunction(modifiers); 3996 validateModifiersForTopLevelFunction(modifiers);
3997 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null); 3997 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null);
3998 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) { 3998 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) {
3999 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) { 3999 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) {
4000 reportError12(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); 4000 reportError13(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []);
4001 } 4001 }
4002 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersForTo pLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON)); 4002 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersForTo pLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON));
4003 } 4003 }
4004 TypeName returnType = parseReturnType(); 4004 TypeName returnType = parseReturnType();
4005 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(pee k())) { 4005 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(pee k())) {
4006 validateModifiersForTopLevelFunction(modifiers); 4006 validateModifiersForTopLevelFunction(modifiers);
4007 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType); 4007 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType);
4008 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 4008 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) {
4009 reportError13(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 4009 reportError14(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []);
4010 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, returnType)); 4010 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, returnType));
4011 } else if (matches5(TokenType.AT)) { 4011 } else if (matches5(TokenType.AT)) {
4012 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersForTo pLevelVariable(modifiers), returnType), expect2(TokenType.SEMICOLON)); 4012 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersForTo pLevelVariable(modifiers), returnType), expect2(TokenType.SEMICOLON));
4013 } else if (!matchesIdentifier()) { 4013 } else if (!matchesIdentifier()) {
4014 // TODO(brianwilkerson) Generalize this error. We could also be parsing a top-level variable at this point. 4014 // TODO(brianwilkerson) Generalize this error. We could also be parsing a top-level variable at this point.
4015 reportError13(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 4015 reportError14(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
4016 Token semicolon; 4016 Token semicolon;
4017 if (matches5(TokenType.SEMICOLON)) { 4017 if (matches5(TokenType.SEMICOLON)) {
4018 semicolon = andAdvance; 4018 semicolon = andAdvance;
4019 } else { 4019 } else {
4020 semicolon = createSyntheticToken2(TokenType.SEMICOLON); 4020 semicolon = createSyntheticToken2(TokenType.SEMICOLON);
4021 } 4021 }
4022 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 4022 List<VariableDeclaration> variables = new List<VariableDeclaration>();
4023 variables.add(new VariableDeclaration(null, null, createSyntheticIdentifie r(), null, null)); 4023 variables.add(new VariableDeclaration(null, null, createSyntheticIdentifie r(), null, null));
4024 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, new VariableDeclarationList(null, null, null, returnType, variables), semicolon); 4024 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, new VariableDeclarationList(null, null, null, returnType, variables), semicolon);
4025 } 4025 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4082 } 4082 }
4083 } while (optional(TokenType.COMMA)); 4083 } while (optional(TokenType.COMMA));
4084 } 4084 }
4085 ConstructorName redirectedConstructor = null; 4085 ConstructorName redirectedConstructor = null;
4086 FunctionBody body; 4086 FunctionBody body;
4087 if (matches5(TokenType.EQ)) { 4087 if (matches5(TokenType.EQ)) {
4088 separator = andAdvance; 4088 separator = andAdvance;
4089 redirectedConstructor = parseConstructorName(); 4089 redirectedConstructor = parseConstructorName();
4090 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON)); 4090 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON));
4091 if (factoryKeyword == null) { 4091 if (factoryKeyword == null) {
4092 reportError11(ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, re directedConstructor, []); 4092 reportError12(ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, re directedConstructor, []);
4093 } 4093 }
4094 } else { 4094 } else {
4095 body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, fals e); 4095 body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, fals e);
4096 if (constKeyword != null && factoryKeyword != null && externalKeyword == n ull) { 4096 if (constKeyword != null && factoryKeyword != null && externalKeyword == n ull) {
4097 reportError13(ParserErrorCode.CONST_FACTORY, factoryKeyword, []); 4097 reportError14(ParserErrorCode.CONST_FACTORY, factoryKeyword, []);
4098 } else if (body is EmptyFunctionBody) { 4098 } else if (body is EmptyFunctionBody) {
4099 if (factoryKeyword != null && externalKeyword == null) { 4099 if (factoryKeyword != null && externalKeyword == null) {
4100 reportError13(ParserErrorCode.FACTORY_WITHOUT_BODY, factoryKeyword, [] ); 4100 reportError14(ParserErrorCode.FACTORY_WITHOUT_BODY, factoryKeyword, [] );
4101 } 4101 }
4102 } else { 4102 } else {
4103 if (constKeyword != null) { 4103 if (constKeyword != null) {
4104 reportError11(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body, []); 4104 reportError12(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body, []);
4105 } else if (!bodyAllowed) { 4105 } else if (!bodyAllowed) {
4106 reportError11(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, body, [] ); 4106 reportError12(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, body, [] );
4107 } 4107 }
4108 } 4108 }
4109 } 4109 }
4110 return new ConstructorDeclaration(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, period , name, parameters, separator, initializers, redirectedConstructor, body); 4110 return new ConstructorDeclaration(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, period , name, parameters, separator, initializers, redirectedConstructor, body);
4111 } 4111 }
4112 4112
4113 /** 4113 /**
4114 * Parse a field initializer within a constructor. 4114 * Parse a field initializer within a constructor.
4115 * 4115 *
4116 * <pre> 4116 * <pre>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4151 * <pre> 4151 * <pre>
4152 * continueStatement ::= 4152 * continueStatement ::=
4153 * 'continue' identifier? ';' 4153 * 'continue' identifier? ';'
4154 * </pre> 4154 * </pre>
4155 * 4155 *
4156 * @return the continue statement that was parsed 4156 * @return the continue statement that was parsed
4157 */ 4157 */
4158 Statement parseContinueStatement() { 4158 Statement parseContinueStatement() {
4159 Token continueKeyword = expect(Keyword.CONTINUE); 4159 Token continueKeyword = expect(Keyword.CONTINUE);
4160 if (!_inLoop && !_inSwitch) { 4160 if (!_inLoop && !_inSwitch) {
4161 reportError13(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword, [ ]); 4161 reportError14(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword, [ ]);
4162 } 4162 }
4163 SimpleIdentifier label = null; 4163 SimpleIdentifier label = null;
4164 if (matchesIdentifier()) { 4164 if (matchesIdentifier()) {
4165 label = parseSimpleIdentifier(); 4165 label = parseSimpleIdentifier();
4166 } 4166 }
4167 if (_inSwitch && !_inLoop && label == null) { 4167 if (_inSwitch && !_inLoop && label == null) {
4168 reportError13(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeyw ord, []); 4168 reportError14(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeyw ord, []);
4169 } 4169 }
4170 Token semicolon = expect2(TokenType.SEMICOLON); 4170 Token semicolon = expect2(TokenType.SEMICOLON);
4171 return new ContinueStatement(continueKeyword, label, semicolon); 4171 return new ContinueStatement(continueKeyword, label, semicolon);
4172 } 4172 }
4173 4173
4174 /** 4174 /**
4175 * Parse a directive. 4175 * Parse a directive.
4176 * 4176 *
4177 * <pre> 4177 * <pre>
4178 * directive ::= 4178 * directive ::=
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
4250 * @return the do statement that was parsed 4250 * @return the do statement that was parsed
4251 */ 4251 */
4252 Statement parseDoStatement() { 4252 Statement parseDoStatement() {
4253 bool wasInLoop = _inLoop; 4253 bool wasInLoop = _inLoop;
4254 _inLoop = true; 4254 _inLoop = true;
4255 try { 4255 try {
4256 Token doKeyword = expect(Keyword.DO); 4256 Token doKeyword = expect(Keyword.DO);
4257 Statement body = parseStatement2(); 4257 Statement body = parseStatement2();
4258 Token whileKeyword = expect(Keyword.WHILE); 4258 Token whileKeyword = expect(Keyword.WHILE);
4259 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 4259 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
4260 Expression condition = parseExpression4(); 4260 Expression condition = parseExpression2();
4261 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4261 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4262 Token semicolon = expect2(TokenType.SEMICOLON); 4262 Token semicolon = expect2(TokenType.SEMICOLON);
4263 return new DoStatement(doKeyword, body, whileKeyword, leftParenthesis, con dition, rightParenthesis, semicolon); 4263 return new DoStatement(doKeyword, body, whileKeyword, leftParenthesis, con dition, rightParenthesis, semicolon);
4264 } finally { 4264 } finally {
4265 _inLoop = wasInLoop; 4265 _inLoop = wasInLoop;
4266 } 4266 }
4267 } 4267 }
4268 4268
4269 /** 4269 /**
4270 * Parse an empty statement. 4270 * Parse an empty statement.
(...skipping 22 matching lines...) Expand all
4293 Expression expression; 4293 Expression expression;
4294 if (matches(Keyword.SUPER) && _currentToken.next.type.isEqualityOperator) { 4294 if (matches(Keyword.SUPER) && _currentToken.next.type.isEqualityOperator) {
4295 expression = new SuperExpression(andAdvance); 4295 expression = new SuperExpression(andAdvance);
4296 } else { 4296 } else {
4297 expression = parseRelationalExpression(); 4297 expression = parseRelationalExpression();
4298 } 4298 }
4299 bool leftEqualityExpression = false; 4299 bool leftEqualityExpression = false;
4300 while (_currentToken.type.isEqualityOperator) { 4300 while (_currentToken.type.isEqualityOperator) {
4301 Token operator = andAdvance; 4301 Token operator = andAdvance;
4302 if (leftEqualityExpression) { 4302 if (leftEqualityExpression) {
4303 reportError11(ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expre ssion, []); 4303 reportError12(ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expre ssion, []);
4304 } 4304 }
4305 expression = new BinaryExpression(expression, operator, parseRelationalExp ression()); 4305 expression = new BinaryExpression(expression, operator, parseRelationalExp ression());
4306 leftEqualityExpression = true; 4306 leftEqualityExpression = true;
4307 } 4307 }
4308 return expression; 4308 return expression;
4309 } 4309 }
4310 4310
4311 /** 4311 /**
4312 * Parse an export directive. 4312 * Parse an export directive.
4313 * 4313 *
(...skipping 18 matching lines...) Expand all
4332 * 4332 *
4333 * <pre> 4333 * <pre>
4334 * expressionList ::= 4334 * expressionList ::=
4335 * expression (',' expression)* 4335 * expression (',' expression)*
4336 * </pre> 4336 * </pre>
4337 * 4337 *
4338 * @return the expression that was parsed 4338 * @return the expression that was parsed
4339 */ 4339 */
4340 List<Expression> parseExpressionList() { 4340 List<Expression> parseExpressionList() {
4341 List<Expression> expressions = new List<Expression>(); 4341 List<Expression> expressions = new List<Expression>();
4342 expressions.add(parseExpression4()); 4342 expressions.add(parseExpression2());
4343 while (optional(TokenType.COMMA)) { 4343 while (optional(TokenType.COMMA)) {
4344 expressions.add(parseExpression4()); 4344 expressions.add(parseExpression2());
4345 } 4345 }
4346 return expressions; 4346 return expressions;
4347 } 4347 }
4348 4348
4349 /** 4349 /**
4350 * Parse the 'final', 'const', 'var' or type preceding a variable declaration. 4350 * Parse the 'final', 'const', 'var' or type preceding a variable declaration.
4351 * 4351 *
4352 * <pre> 4352 * <pre>
4353 * finalConstVarOrType ::= 4353 * finalConstVarOrType ::=
4354 * | 'final' type? 4354 * | 'final' type?
(...skipping 12 matching lines...) Expand all
4367 keyword = andAdvance; 4367 keyword = andAdvance;
4368 if (isTypedIdentifier(_currentToken)) { 4368 if (isTypedIdentifier(_currentToken)) {
4369 type = parseTypeName(); 4369 type = parseTypeName();
4370 } 4370 }
4371 } else if (matches(Keyword.VAR)) { 4371 } else if (matches(Keyword.VAR)) {
4372 keyword = andAdvance; 4372 keyword = andAdvance;
4373 } else { 4373 } else {
4374 if (isTypedIdentifier(_currentToken)) { 4374 if (isTypedIdentifier(_currentToken)) {
4375 type = parseReturnType(); 4375 type = parseReturnType();
4376 } else if (!optional) { 4376 } else if (!optional) {
4377 reportError12(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); 4377 reportError13(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []);
4378 } 4378 }
4379 } 4379 }
4380 return new FinalConstVarOrType(keyword, type); 4380 return new FinalConstVarOrType(keyword, type);
4381 } 4381 }
4382 4382
4383 /** 4383 /**
4384 * Parse a formal parameter. At most one of `isOptional` and `isNamed` can be 4384 * Parse a formal parameter. At most one of `isOptional` and `isNamed` can be
4385 * `true`. 4385 * `true`.
4386 * 4386 *
4387 * <pre> 4387 * <pre>
4388 * defaultFormalParameter ::= 4388 * defaultFormalParameter ::=
4389 * normalFormalParameter ('=' expression)? 4389 * normalFormalParameter ('=' expression)?
4390 * 4390 *
4391 * defaultNamedParameter ::= 4391 * defaultNamedParameter ::=
4392 * normalFormalParameter (':' expression)? 4392 * normalFormalParameter (':' expression)?
4393 * </pre> 4393 * </pre>
4394 * 4394 *
4395 * @param kind the kind of parameter being expected based on the presence or a bsence of group 4395 * @param kind the kind of parameter being expected based on the presence or a bsence of group
4396 * delimiters 4396 * delimiters
4397 * @return the formal parameter that was parsed 4397 * @return the formal parameter that was parsed
4398 */ 4398 */
4399 FormalParameter parseFormalParameter(ParameterKind kind) { 4399 FormalParameter parseFormalParameter(ParameterKind kind) {
4400 NormalFormalParameter parameter = parseNormalFormalParameter(); 4400 NormalFormalParameter parameter = parseNormalFormalParameter();
4401 if (matches5(TokenType.EQ)) { 4401 if (matches5(TokenType.EQ)) {
4402 Token seperator = andAdvance; 4402 Token seperator = andAdvance;
4403 Expression defaultValue = parseExpression4(); 4403 Expression defaultValue = parseExpression2();
4404 if (identical(kind, ParameterKind.NAMED)) { 4404 if (identical(kind, ParameterKind.NAMED)) {
4405 reportError13(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, seper ator, []); 4405 reportError14(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, seper ator, []);
4406 } else if (identical(kind, ParameterKind.REQUIRED)) { 4406 } else if (identical(kind, ParameterKind.REQUIRED)) {
4407 reportError11(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, parame ter, []); 4407 reportError12(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, parame ter, []);
4408 } 4408 }
4409 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue ); 4409 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue );
4410 } else if (matches5(TokenType.COLON)) { 4410 } else if (matches5(TokenType.COLON)) {
4411 Token seperator = andAdvance; 4411 Token seperator = andAdvance;
4412 Expression defaultValue = parseExpression4(); 4412 Expression defaultValue = parseExpression2();
4413 if (identical(kind, ParameterKind.POSITIONAL)) { 4413 if (identical(kind, ParameterKind.POSITIONAL)) {
4414 reportError13(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, seperator, []); 4414 reportError14(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, seperator, []);
4415 } else if (identical(kind, ParameterKind.REQUIRED)) { 4415 } else if (identical(kind, ParameterKind.REQUIRED)) {
4416 reportError11(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter, []); 4416 reportError12(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter, []);
4417 } 4417 }
4418 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue ); 4418 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue );
4419 } else if (kind != ParameterKind.REQUIRED) { 4419 } else if (kind != ParameterKind.REQUIRED) {
4420 return new DefaultFormalParameter(parameter, kind, null, null); 4420 return new DefaultFormalParameter(parameter, kind, null, null);
4421 } 4421 }
4422 return parameter; 4422 return parameter;
4423 } 4423 }
4424 4424
4425 /** 4425 /**
4426 * Parse a for statement. 4426 * Parse a for statement.
(...skipping 25 matching lines...) Expand all
4452 if (!matches5(TokenType.SEMICOLON)) { 4452 if (!matches5(TokenType.SEMICOLON)) {
4453 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 4453 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
4454 if (matchesIdentifier() && matches3(peek(), Keyword.IN)) { 4454 if (matchesIdentifier() && matches3(peek(), Keyword.IN)) {
4455 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 4455 List<VariableDeclaration> variables = new List<VariableDeclaration>();
4456 SimpleIdentifier variableName = parseSimpleIdentifier(); 4456 SimpleIdentifier variableName = parseSimpleIdentifier();
4457 variables.add(new VariableDeclaration(null, null, variableName, null, null)); 4457 variables.add(new VariableDeclaration(null, null, variableName, null, null));
4458 variableList = new VariableDeclarationList(commentAndMetadata.comment, commentAndMetadata.metadata, null, null, variables); 4458 variableList = new VariableDeclarationList(commentAndMetadata.comment, commentAndMetadata.metadata, null, null, variables);
4459 } else if (isInitializedVariableDeclaration()) { 4459 } else if (isInitializedVariableDeclaration()) {
4460 variableList = parseVariableDeclarationList(commentAndMetadata); 4460 variableList = parseVariableDeclarationList(commentAndMetadata);
4461 } else { 4461 } else {
4462 initialization = parseExpression4(); 4462 initialization = parseExpression2();
4463 } 4463 }
4464 if (matches(Keyword.IN)) { 4464 if (matches(Keyword.IN)) {
4465 DeclaredIdentifier loopVariable = null; 4465 DeclaredIdentifier loopVariable = null;
4466 SimpleIdentifier identifier = null; 4466 SimpleIdentifier identifier = null;
4467 if (variableList == null) { 4467 if (variableList == null) {
4468 // We found: <expression> 'in' 4468 // We found: <expression> 'in'
4469 reportError12(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH, []); 4469 reportError13(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH, []);
4470 } else { 4470 } else {
4471 NodeList<VariableDeclaration> variables = variableList.variables; 4471 NodeList<VariableDeclaration> variables = variableList.variables;
4472 if (variables.length > 1) { 4472 if (variables.length > 1) {
4473 reportError12(ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH, [var iables.length.toString()]); 4473 reportError13(ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH, [var iables.length.toString()]);
4474 } 4474 }
4475 VariableDeclaration variable = variables[0]; 4475 VariableDeclaration variable = variables[0];
4476 if (variable.initializer != null) { 4476 if (variable.initializer != null) {
4477 reportError12(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH, [] ); 4477 reportError13(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH, [] );
4478 } 4478 }
4479 Token keyword = variableList.keyword; 4479 Token keyword = variableList.keyword;
4480 TypeName type = variableList.type; 4480 TypeName type = variableList.type;
4481 if (keyword != null || type != null) { 4481 if (keyword != null || type != null) {
4482 loopVariable = new DeclaredIdentifier(commentAndMetadata.comment, commentAndMetadata.metadata, keyword, type, variable.name); 4482 loopVariable = new DeclaredIdentifier(commentAndMetadata.comment, commentAndMetadata.metadata, keyword, type, variable.name);
4483 } else { 4483 } else {
4484 if (!commentAndMetadata.metadata.isEmpty) { 4484 if (!commentAndMetadata.metadata.isEmpty) {
4485 } 4485 }
4486 identifier = variable.name; 4486 identifier = variable.name;
4487 } 4487 }
4488 } 4488 }
4489 Token inKeyword = expect(Keyword.IN); 4489 Token inKeyword = expect(Keyword.IN);
4490 Expression iterator = parseExpression4(); 4490 Expression iterator = parseExpression2();
4491 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4491 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4492 Statement body = parseStatement2(); 4492 Statement body = parseStatement2();
4493 if (loopVariable == null) { 4493 if (loopVariable == null) {
4494 return new ForEachStatement.con2(forKeyword, leftParenthesis, identi fier, inKeyword, iterator, rightParenthesis, body); 4494 return new ForEachStatement.con2(forKeyword, leftParenthesis, identi fier, inKeyword, iterator, rightParenthesis, body);
4495 } 4495 }
4496 return new ForEachStatement.con1(forKeyword, leftParenthesis, loopVari able, inKeyword, iterator, rightParenthesis, body); 4496 return new ForEachStatement.con1(forKeyword, leftParenthesis, loopVari able, inKeyword, iterator, rightParenthesis, body);
4497 } 4497 }
4498 } 4498 }
4499 Token leftSeparator = expect2(TokenType.SEMICOLON); 4499 Token leftSeparator = expect2(TokenType.SEMICOLON);
4500 Expression condition = null; 4500 Expression condition = null;
4501 if (!matches5(TokenType.SEMICOLON)) { 4501 if (!matches5(TokenType.SEMICOLON)) {
4502 condition = parseExpression4(); 4502 condition = parseExpression2();
4503 } 4503 }
4504 Token rightSeparator = expect2(TokenType.SEMICOLON); 4504 Token rightSeparator = expect2(TokenType.SEMICOLON);
4505 List<Expression> updaters = null; 4505 List<Expression> updaters = null;
4506 if (!matches5(TokenType.CLOSE_PAREN)) { 4506 if (!matches5(TokenType.CLOSE_PAREN)) {
4507 updaters = parseExpressionList(); 4507 updaters = parseExpressionList();
4508 } 4508 }
4509 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4509 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4510 Statement body = parseStatement2(); 4510 Statement body = parseStatement2();
4511 return new ForStatement(forKeyword, leftParenthesis, variableList, initial ization, leftSeparator, condition, rightSeparator, updaters, rightParenthesis, b ody); 4511 return new ForStatement(forKeyword, leftParenthesis, variableList, initial ization, leftSeparator, condition, rightSeparator, updaters, rightParenthesis, b ody);
4512 } finally { 4512 } finally {
(...skipping 21 matching lines...) Expand all
4534 * @return the function body that was parsed 4534 * @return the function body that was parsed
4535 */ 4535 */
4536 FunctionBody parseFunctionBody(bool mayBeEmpty, ParserErrorCode emptyErrorCode , bool inExpression) { 4536 FunctionBody parseFunctionBody(bool mayBeEmpty, ParserErrorCode emptyErrorCode , bool inExpression) {
4537 bool wasInLoop = _inLoop; 4537 bool wasInLoop = _inLoop;
4538 bool wasInSwitch = _inSwitch; 4538 bool wasInSwitch = _inSwitch;
4539 _inLoop = false; 4539 _inLoop = false;
4540 _inSwitch = false; 4540 _inSwitch = false;
4541 try { 4541 try {
4542 if (matches5(TokenType.SEMICOLON)) { 4542 if (matches5(TokenType.SEMICOLON)) {
4543 if (!mayBeEmpty) { 4543 if (!mayBeEmpty) {
4544 reportError12(emptyErrorCode, []); 4544 reportError13(emptyErrorCode, []);
4545 } 4545 }
4546 return new EmptyFunctionBody(andAdvance); 4546 return new EmptyFunctionBody(andAdvance);
4547 } else if (matches5(TokenType.FUNCTION)) { 4547 } else if (matches5(TokenType.FUNCTION)) {
4548 Token functionDefinition = andAdvance; 4548 Token functionDefinition = andAdvance;
4549 Expression expression = parseExpression4(); 4549 Expression expression = parseExpression2();
4550 Token semicolon = null; 4550 Token semicolon = null;
4551 if (!inExpression) { 4551 if (!inExpression) {
4552 semicolon = expect2(TokenType.SEMICOLON); 4552 semicolon = expect2(TokenType.SEMICOLON);
4553 } 4553 }
4554 if (!_parseFunctionBodies) { 4554 if (!_parseFunctionBodies) {
4555 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON )); 4555 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON ));
4556 } 4556 }
4557 return new ExpressionFunctionBody(functionDefinition, expression, semico lon); 4557 return new ExpressionFunctionBody(functionDefinition, expression, semico lon);
4558 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 4558 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
4559 if (!_parseFunctionBodies) { 4559 if (!_parseFunctionBodies) {
4560 skipBlock(); 4560 skipBlock();
4561 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON )); 4561 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON ));
4562 } 4562 }
4563 return new BlockFunctionBody(parseBlock()); 4563 return new BlockFunctionBody(parseBlock());
4564 } else if (matches2(_NATIVE)) { 4564 } else if (matches2(_NATIVE)) {
4565 Token nativeToken = andAdvance; 4565 Token nativeToken = andAdvance;
4566 StringLiteral stringLiteral = null; 4566 StringLiteral stringLiteral = null;
4567 if (matches5(TokenType.STRING)) { 4567 if (matches5(TokenType.STRING)) {
4568 stringLiteral = parseStringLiteral(); 4568 stringLiteral = parseStringLiteral();
4569 } 4569 }
4570 return new NativeFunctionBody(nativeToken, stringLiteral, expect2(TokenT ype.SEMICOLON)); 4570 return new NativeFunctionBody(nativeToken, stringLiteral, expect2(TokenT ype.SEMICOLON));
4571 } else { 4571 } else {
4572 // Invalid function body 4572 // Invalid function body
4573 reportError12(emptyErrorCode, []); 4573 reportError13(emptyErrorCode, []);
4574 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON)) ; 4574 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON)) ;
4575 } 4575 }
4576 } finally { 4576 } finally {
4577 _inLoop = wasInLoop; 4577 _inLoop = wasInLoop;
4578 _inSwitch = wasInSwitch; 4578 _inSwitch = wasInSwitch;
4579 } 4579 }
4580 } 4580 }
4581 4581
4582 /** 4582 /**
4583 * Parse a function declaration. 4583 * Parse a function declaration.
(...skipping 20 matching lines...) Expand all
4604 } else if (matches(Keyword.SET) && !matches4(peek(), TokenType.OPEN_PAREN)) { 4604 } else if (matches(Keyword.SET) && !matches4(peek(), TokenType.OPEN_PAREN)) {
4605 keyword = andAdvance; 4605 keyword = andAdvance;
4606 } 4606 }
4607 SimpleIdentifier name = parseSimpleIdentifier(); 4607 SimpleIdentifier name = parseSimpleIdentifier();
4608 FormalParameterList parameters = null; 4608 FormalParameterList parameters = null;
4609 if (!isGetter) { 4609 if (!isGetter) {
4610 if (matches5(TokenType.OPEN_PAREN)) { 4610 if (matches5(TokenType.OPEN_PAREN)) {
4611 parameters = parseFormalParameterList(); 4611 parameters = parseFormalParameterList();
4612 validateFormalParameterList(parameters); 4612 validateFormalParameterList(parameters);
4613 } else { 4613 } else {
4614 reportError12(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, []); 4614 reportError13(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, []);
4615 } 4615 }
4616 } else if (matches5(TokenType.OPEN_PAREN)) { 4616 } else if (matches5(TokenType.OPEN_PAREN)) {
4617 reportError12(ParserErrorCode.GETTER_WITH_PARAMETERS, []); 4617 reportError13(ParserErrorCode.GETTER_WITH_PARAMETERS, []);
4618 parseFormalParameterList(); 4618 parseFormalParameterList();
4619 } 4619 }
4620 FunctionBody body; 4620 FunctionBody body;
4621 if (externalKeyword == null) { 4621 if (externalKeyword == null) {
4622 body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, fal se); 4622 body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, fal se);
4623 } else { 4623 } else {
4624 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON)); 4624 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON));
4625 } 4625 }
4626 // if (!isStatement && matches(TokenType.SEMICOLON)) { 4626 // if (!isStatement && matches(TokenType.SEMICOLON)) {
4627 // // TODO(brianwilkerson) Improve this error message. 4627 // // TODO(brianwilkerson) Improve this error message.
(...skipping 30 matching lines...) Expand all
4658 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 4658 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
4659 * declaration 4659 * declaration
4660 * @param returnType the return type, or `null` if there is no return type 4660 * @param returnType the return type, or `null` if there is no return type
4661 * @return the function declaration statement that was parsed 4661 * @return the function declaration statement that was parsed
4662 */ 4662 */
4663 Statement parseFunctionDeclarationStatement2(CommentAndMetadata commentAndMeta data, TypeName returnType) { 4663 Statement parseFunctionDeclarationStatement2(CommentAndMetadata commentAndMeta data, TypeName returnType) {
4664 FunctionDeclaration declaration = parseFunctionDeclaration(commentAndMetadat a, null, returnType); 4664 FunctionDeclaration declaration = parseFunctionDeclaration(commentAndMetadat a, null, returnType);
4665 Token propertyKeyword = declaration.propertyKeyword; 4665 Token propertyKeyword = declaration.propertyKeyword;
4666 if (propertyKeyword != null) { 4666 if (propertyKeyword != null) {
4667 if (identical((propertyKeyword as KeywordToken).keyword, Keyword.GET)) { 4667 if (identical((propertyKeyword as KeywordToken).keyword, Keyword.GET)) {
4668 reportError13(ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword, []); 4668 reportError14(ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword, []);
4669 } else { 4669 } else {
4670 reportError13(ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword, []); 4670 reportError14(ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword, []);
4671 } 4671 }
4672 } 4672 }
4673 return new FunctionDeclarationStatement(declaration); 4673 return new FunctionDeclarationStatement(declaration);
4674 } 4674 }
4675 4675
4676 /** 4676 /**
4677 * Parse a function type alias. 4677 * Parse a function type alias.
4678 * 4678 *
4679 * <pre> 4679 * <pre>
4680 * functionTypeAlias ::= 4680 * functionTypeAlias ::=
(...skipping 11 matching lines...) Expand all
4692 TypeName returnType = null; 4692 TypeName returnType = null;
4693 if (hasReturnTypeInTypeAlias()) { 4693 if (hasReturnTypeInTypeAlias()) {
4694 returnType = parseReturnType(); 4694 returnType = parseReturnType();
4695 } 4695 }
4696 SimpleIdentifier name = parseSimpleIdentifier(); 4696 SimpleIdentifier name = parseSimpleIdentifier();
4697 TypeParameterList typeParameters = null; 4697 TypeParameterList typeParameters = null;
4698 if (matches5(TokenType.LT)) { 4698 if (matches5(TokenType.LT)) {
4699 typeParameters = parseTypeParameterList(); 4699 typeParameters = parseTypeParameterList();
4700 } 4700 }
4701 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.EOF)) { 4701 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.EOF)) {
4702 reportError12(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); 4702 reportError13(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []);
4703 FormalParameterList parameters = new FormalParameterList(createSyntheticTo ken2(TokenType.OPEN_PAREN), null, null, null, createSyntheticToken2(TokenType.CL OSE_PAREN)); 4703 FormalParameterList parameters = new FormalParameterList(createSyntheticTo ken2(TokenType.OPEN_PAREN), null, null, null, createSyntheticToken2(TokenType.CL OSE_PAREN));
4704 Token semicolon = expect2(TokenType.SEMICOLON); 4704 Token semicolon = expect2(TokenType.SEMICOLON);
4705 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, parameters, semicolon); 4705 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, parameters, semicolon);
4706 } else if (!matches5(TokenType.OPEN_PAREN)) { 4706 } else if (!matches5(TokenType.OPEN_PAREN)) {
4707 reportError12(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); 4707 reportError13(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []);
4708 // TODO(brianwilkerson) Recover from this error. At the very least we shou ld skip to the start 4708 // TODO(brianwilkerson) Recover from this error. At the very least we shou ld skip to the start
4709 // of the next valid compilation unit member, allowing for the possibility of finding the 4709 // of the next valid compilation unit member, allowing for the possibility of finding the
4710 // typedef parameters before that point. 4710 // typedef parameters before that point.
4711 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, new FormalParameterList(c reateSyntheticToken2(TokenType.OPEN_PAREN), null, null, null, createSyntheticTok en2(TokenType.CLOSE_PAREN)), createSyntheticToken2(TokenType.SEMICOLON)); 4711 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, new FormalParameterList(c reateSyntheticToken2(TokenType.OPEN_PAREN), null, null, null, createSyntheticTok en2(TokenType.CLOSE_PAREN)), createSyntheticToken2(TokenType.SEMICOLON));
4712 } 4712 }
4713 FormalParameterList parameters = parseFormalParameterList(); 4713 FormalParameterList parameters = parseFormalParameterList();
4714 validateFormalParameterList(parameters); 4714 validateFormalParameterList(parameters);
4715 Token semicolon = expect2(TokenType.SEMICOLON); 4715 Token semicolon = expect2(TokenType.SEMICOLON);
4716 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadata. metadata, keyword, returnType, name, typeParameters, parameters, semicolon); 4716 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadata. metadata, keyword, returnType, name, typeParameters, parameters, semicolon);
4717 } 4717 }
(...skipping 14 matching lines...) Expand all
4732 * @param externalKeyword the 'external' token 4732 * @param externalKeyword the 'external' token
4733 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic 4733 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic
4734 * @param the return type that has already been parsed, or `null` if there was no return 4734 * @param the return type that has already been parsed, or `null` if there was no return
4735 * type 4735 * type
4736 * @return the getter that was parsed 4736 * @return the getter that was parsed
4737 */ 4737 */
4738 MethodDeclaration parseGetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) { 4738 MethodDeclaration parseGetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) {
4739 Token propertyKeyword = expect(Keyword.GET); 4739 Token propertyKeyword = expect(Keyword.GET);
4740 SimpleIdentifier name = parseSimpleIdentifier(); 4740 SimpleIdentifier name = parseSimpleIdentifier();
4741 if (matches5(TokenType.OPEN_PAREN) && matches4(peek(), TokenType.CLOSE_PAREN )) { 4741 if (matches5(TokenType.OPEN_PAREN) && matches4(peek(), TokenType.CLOSE_PAREN )) {
4742 reportError12(ParserErrorCode.GETTER_WITH_PARAMETERS, []); 4742 reportError13(ParserErrorCode.GETTER_WITH_PARAMETERS, []);
4743 advance(); 4743 advance();
4744 advance(); 4744 advance();
4745 } 4745 }
4746 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, false); 4746 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, false);
4747 if (externalKeyword != null && body is! EmptyFunctionBody) { 4747 if (externalKeyword != null && body is! EmptyFunctionBody) {
4748 reportError12(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []); 4748 reportError13(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []);
4749 } 4749 }
4750 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, null, body); 4750 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, null, body);
4751 } 4751 }
4752 4752
4753 /** 4753 /**
4754 * Parse a list of identifiers. 4754 * Parse a list of identifiers.
4755 * 4755 *
4756 * <pre> 4756 * <pre>
4757 * identifierList ::= 4757 * identifierList ::=
4758 * identifier (',' identifier)* 4758 * identifier (',' identifier)*
(...skipping 17 matching lines...) Expand all
4776 * <pre> 4776 * <pre>
4777 * ifStatement ::= 4777 * ifStatement ::=
4778 * 'if' '(' expression ')' statement ('else' statement)? 4778 * 'if' '(' expression ')' statement ('else' statement)?
4779 * </pre> 4779 * </pre>
4780 * 4780 *
4781 * @return the if statement that was parsed 4781 * @return the if statement that was parsed
4782 */ 4782 */
4783 Statement parseIfStatement() { 4783 Statement parseIfStatement() {
4784 Token ifKeyword = expect(Keyword.IF); 4784 Token ifKeyword = expect(Keyword.IF);
4785 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 4785 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
4786 Expression condition = parseExpression4(); 4786 Expression condition = parseExpression2();
4787 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4787 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4788 Statement thenStatement = parseStatement2(); 4788 Statement thenStatement = parseStatement2();
4789 Token elseKeyword = null; 4789 Token elseKeyword = null;
4790 Statement elseStatement = null; 4790 Statement elseStatement = null;
4791 if (matches(Keyword.ELSE)) { 4791 if (matches(Keyword.ELSE)) {
4792 elseKeyword = andAdvance; 4792 elseKeyword = andAdvance;
4793 elseStatement = parseStatement2(); 4793 elseStatement = parseStatement2();
4794 } 4794 }
4795 return new IfStatement(ifKeyword, leftParenthesis, condition, rightParenthes is, thenStatement, elseKeyword, elseStatement); 4795 return new IfStatement(ifKeyword, leftParenthesis, condition, rightParenthes is, thenStatement, elseKeyword, elseStatement);
4796 } 4796 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
4896 * missing 4896 * missing
4897 * @return the library name that was parsed 4897 * @return the library name that was parsed
4898 */ 4898 */
4899 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis singNameToken) { 4899 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis singNameToken) {
4900 if (matchesIdentifier()) { 4900 if (matchesIdentifier()) {
4901 return parseLibraryIdentifier(); 4901 return parseLibraryIdentifier();
4902 } else if (matches5(TokenType.STRING)) { 4902 } else if (matches5(TokenType.STRING)) {
4903 // TODO(brianwilkerson) Recovery: This should be extended to handle arbitr ary tokens until we 4903 // TODO(brianwilkerson) Recovery: This should be extended to handle arbitr ary tokens until we
4904 // can find a token that can start a compilation unit member. 4904 // can find a token that can start a compilation unit member.
4905 StringLiteral string = parseStringLiteral(); 4905 StringLiteral string = parseStringLiteral();
4906 reportError11(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, []); 4906 reportError12(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, []);
4907 } else { 4907 } else {
4908 reportError13(missingNameError, missingNameToken, []); 4908 reportError14(missingNameError, missingNameToken, []);
4909 } 4909 }
4910 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); 4910 List<SimpleIdentifier> components = new List<SimpleIdentifier>();
4911 components.add(createSyntheticIdentifier()); 4911 components.add(createSyntheticIdentifier());
4912 return new LibraryIdentifier(components); 4912 return new LibraryIdentifier(components);
4913 } 4913 }
4914 4914
4915 /** 4915 /**
4916 * Parse a list literal. 4916 * Parse a list literal.
4917 * 4917 *
4918 * <pre> 4918 * <pre>
(...skipping 18 matching lines...) Expand all
4937 _currentToken.previous.setNext(leftBracket); 4937 _currentToken.previous.setNext(leftBracket);
4938 _currentToken = _currentToken.next; 4938 _currentToken = _currentToken.next;
4939 return new ListLiteral(modifier, typeArguments, leftBracket, null, rightBr acket); 4939 return new ListLiteral(modifier, typeArguments, leftBracket, null, rightBr acket);
4940 } 4940 }
4941 // open 4941 // open
4942 Token leftBracket = expect2(TokenType.OPEN_SQUARE_BRACKET); 4942 Token leftBracket = expect2(TokenType.OPEN_SQUARE_BRACKET);
4943 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 4943 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) {
4944 return new ListLiteral(modifier, typeArguments, leftBracket, null, andAdva nce); 4944 return new ListLiteral(modifier, typeArguments, leftBracket, null, andAdva nce);
4945 } 4945 }
4946 List<Expression> elements = new List<Expression>(); 4946 List<Expression> elements = new List<Expression>();
4947 elements.add(parseExpression4()); 4947 elements.add(parseExpression2());
4948 while (optional(TokenType.COMMA)) { 4948 while (optional(TokenType.COMMA)) {
4949 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 4949 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) {
4950 return new ListLiteral(modifier, typeArguments, leftBracket, elements, a ndAdvance); 4950 return new ListLiteral(modifier, typeArguments, leftBracket, elements, a ndAdvance);
4951 } 4951 }
4952 elements.add(parseExpression4()); 4952 elements.add(parseExpression2());
4953 } 4953 }
4954 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 4954 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
4955 return new ListLiteral(modifier, typeArguments, leftBracket, elements, right Bracket); 4955 return new ListLiteral(modifier, typeArguments, leftBracket, elements, right Bracket);
4956 } 4956 }
4957 4957
4958 /** 4958 /**
4959 * Parse a list or map literal. 4959 * Parse a list or map literal.
4960 * 4960 *
4961 * <pre> 4961 * <pre>
4962 * listOrMapLiteral ::= 4962 * listOrMapLiteral ::=
4963 * listLiteral 4963 * listLiteral
4964 * | mapLiteral 4964 * | mapLiteral
4965 * </pre> 4965 * </pre>
4966 * 4966 *
4967 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is 4967 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is
4968 * no modifier 4968 * no modifier
4969 * @return the list or map literal that was parsed 4969 * @return the list or map literal that was parsed
4970 */ 4970 */
4971 TypedLiteral parseListOrMapLiteral(Token modifier) { 4971 TypedLiteral parseListOrMapLiteral(Token modifier) {
4972 TypeArgumentList typeArguments = null; 4972 TypeArgumentList typeArguments = null;
4973 if (matches5(TokenType.LT)) { 4973 if (matches5(TokenType.LT)) {
4974 typeArguments = parseTypeArgumentList(); 4974 typeArguments = parseTypeArgumentList();
4975 } 4975 }
4976 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 4976 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
4977 return parseMapLiteral(modifier, typeArguments); 4977 return parseMapLiteral(modifier, typeArguments);
4978 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) { 4978 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) {
4979 return parseListLiteral(modifier, typeArguments); 4979 return parseListLiteral(modifier, typeArguments);
4980 } 4980 }
4981 reportError12(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []); 4981 reportError13(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []);
4982 return new ListLiteral(modifier, typeArguments, createSyntheticToken2(TokenT ype.OPEN_SQUARE_BRACKET), null, createSyntheticToken2(TokenType.CLOSE_SQUARE_BRA CKET)); 4982 return new ListLiteral(modifier, typeArguments, createSyntheticToken2(TokenT ype.OPEN_SQUARE_BRACKET), null, createSyntheticToken2(TokenType.CLOSE_SQUARE_BRA CKET));
4983 } 4983 }
4984 4984
4985 /** 4985 /**
4986 * Parse a logical and expression. 4986 * Parse a logical and expression.
4987 * 4987 *
4988 * <pre> 4988 * <pre>
4989 * logicalAndExpression ::= 4989 * logicalAndExpression ::=
4990 * equalityExpression ('&&' equalityExpression)* 4990 * equalityExpression ('&&' equalityExpression)*
4991 * </pre> 4991 * </pre>
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
5070 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic 5070 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic
5071 * @param returnType the return type of the method 5071 * @param returnType the return type of the method
5072 * @param name the name of the method 5072 * @param name the name of the method
5073 * @param parameters the parameters to the method 5073 * @param parameters the parameters to the method
5074 * @return the method declaration that was parsed 5074 * @return the method declaration that was parsed
5075 */ 5075 */
5076 MethodDeclaration parseMethodDeclaration2(CommentAndMetadata commentAndMetadat a, Token externalKeyword, Token staticKeyword, TypeName returnType, SimpleIdenti fier name, FormalParameterList parameters) { 5076 MethodDeclaration parseMethodDeclaration2(CommentAndMetadata commentAndMetadat a, Token externalKeyword, Token staticKeyword, TypeName returnType, SimpleIdenti fier name, FormalParameterList parameters) {
5077 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.MISSING_FUNCTION_BODY, false); 5077 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.MISSING_FUNCTION_BODY, false);
5078 if (externalKeyword != null) { 5078 if (externalKeyword != null) {
5079 if (body is! EmptyFunctionBody) { 5079 if (body is! EmptyFunctionBody) {
5080 reportError11(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []); 5080 reportError12(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []);
5081 } 5081 }
5082 } else if (staticKeyword != null) { 5082 } else if (staticKeyword != null) {
5083 if (body is EmptyFunctionBody) { 5083 if (body is EmptyFunctionBody) {
5084 reportError11(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []); 5084 reportError12(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []);
5085 } 5085 }
5086 } 5086 }
5087 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, null, null, name, paramete rs, body); 5087 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, null, null, name, paramete rs, body);
5088 } 5088 }
5089 5089
5090 /** 5090 /**
5091 * Parse the modifiers preceding a declaration. This method allows the modifie rs to appear in any 5091 * Parse the modifiers preceding a declaration. This method allows the modifie rs to appear in any
5092 * order but does generate errors for duplicated modifiers. Checks for other p roblems, such as 5092 * order but does generate errors for duplicated modifiers. Checks for other p roblems, such as
5093 * having the modifiers appear in the wrong order or specifying both 'const' a nd 'final', are 5093 * having the modifiers appear in the wrong order or specifying both 'const' a nd 'final', are
5094 * reported in one of the methods whose name is prefixed with `validateModifie rsFor`. 5094 * reported in one of the methods whose name is prefixed with `validateModifie rsFor`.
5095 * 5095 *
5096 * <pre> 5096 * <pre>
5097 * modifiers ::= 5097 * modifiers ::=
5098 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | ' var')* 5098 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | ' var')*
5099 * </pre> 5099 * </pre>
5100 * 5100 *
5101 * @return the modifiers that were parsed 5101 * @return the modifiers that were parsed
5102 */ 5102 */
5103 Modifiers parseModifiers() { 5103 Modifiers parseModifiers() {
5104 Modifiers modifiers = new Modifiers(); 5104 Modifiers modifiers = new Modifiers();
5105 bool progress = true; 5105 bool progress = true;
5106 while (progress) { 5106 while (progress) {
5107 if (matches4(peek(), TokenType.PERIOD) || matches4(peek(), TokenType.LT) | | matches4(peek(), TokenType.OPEN_PAREN)) { 5107 if (matches4(peek(), TokenType.PERIOD) || matches4(peek(), TokenType.LT) | | matches4(peek(), TokenType.OPEN_PAREN)) {
5108 return modifiers; 5108 return modifiers;
5109 } 5109 }
5110 if (matches(Keyword.ABSTRACT)) { 5110 if (matches(Keyword.ABSTRACT)) {
5111 if (modifiers.abstractKeyword != null) { 5111 if (modifiers.abstractKeyword != null) {
5112 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5112 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5113 advance(); 5113 advance();
5114 } else { 5114 } else {
5115 modifiers.abstractKeyword = andAdvance; 5115 modifiers.abstractKeyword = andAdvance;
5116 } 5116 }
5117 } else if (matches(Keyword.CONST)) { 5117 } else if (matches(Keyword.CONST)) {
5118 if (modifiers.constKeyword != null) { 5118 if (modifiers.constKeyword != null) {
5119 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5119 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5120 advance(); 5120 advance();
5121 } else { 5121 } else {
5122 modifiers.constKeyword = andAdvance; 5122 modifiers.constKeyword = andAdvance;
5123 } 5123 }
5124 } else if (matches(Keyword.EXTERNAL) && !matches4(peek(), TokenType.PERIOD ) && !matches4(peek(), TokenType.LT)) { 5124 } else if (matches(Keyword.EXTERNAL) && !matches4(peek(), TokenType.PERIOD ) && !matches4(peek(), TokenType.LT)) {
5125 if (modifiers.externalKeyword != null) { 5125 if (modifiers.externalKeyword != null) {
5126 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5126 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5127 advance(); 5127 advance();
5128 } else { 5128 } else {
5129 modifiers.externalKeyword = andAdvance; 5129 modifiers.externalKeyword = andAdvance;
5130 } 5130 }
5131 } else if (matches(Keyword.FACTORY) && !matches4(peek(), TokenType.PERIOD) && !matches4(peek(), TokenType.LT)) { 5131 } else if (matches(Keyword.FACTORY) && !matches4(peek(), TokenType.PERIOD) && !matches4(peek(), TokenType.LT)) {
5132 if (modifiers.factoryKeyword != null) { 5132 if (modifiers.factoryKeyword != null) {
5133 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5133 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5134 advance(); 5134 advance();
5135 } else { 5135 } else {
5136 modifiers.factoryKeyword = andAdvance; 5136 modifiers.factoryKeyword = andAdvance;
5137 } 5137 }
5138 } else if (matches(Keyword.FINAL)) { 5138 } else if (matches(Keyword.FINAL)) {
5139 if (modifiers.finalKeyword != null) { 5139 if (modifiers.finalKeyword != null) {
5140 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5140 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5141 advance(); 5141 advance();
5142 } else { 5142 } else {
5143 modifiers.finalKeyword = andAdvance; 5143 modifiers.finalKeyword = andAdvance;
5144 } 5144 }
5145 } else if (matches(Keyword.STATIC) && !matches4(peek(), TokenType.PERIOD) && !matches4(peek(), TokenType.LT)) { 5145 } else if (matches(Keyword.STATIC) && !matches4(peek(), TokenType.PERIOD) && !matches4(peek(), TokenType.LT)) {
5146 if (modifiers.staticKeyword != null) { 5146 if (modifiers.staticKeyword != null) {
5147 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5147 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5148 advance(); 5148 advance();
5149 } else { 5149 } else {
5150 modifiers.staticKeyword = andAdvance; 5150 modifiers.staticKeyword = andAdvance;
5151 } 5151 }
5152 } else if (matches(Keyword.VAR)) { 5152 } else if (matches(Keyword.VAR)) {
5153 if (modifiers.varKeyword != null) { 5153 if (modifiers.varKeyword != null) {
5154 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5154 reportError13(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5155 advance(); 5155 advance();
5156 } else { 5156 } else {
5157 modifiers.varKeyword = andAdvance; 5157 modifiers.varKeyword = andAdvance;
5158 } 5158 }
5159 } else { 5159 } else {
5160 progress = false; 5160 progress = false;
5161 } 5161 }
5162 } 5162 }
5163 return modifiers; 5163 return modifiers;
5164 } 5164 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
5239 * 5239 *
5240 * @return the non-labeled statement that was parsed 5240 * @return the non-labeled statement that was parsed
5241 */ 5241 */
5242 Statement parseNonLabeledStatement() { 5242 Statement parseNonLabeledStatement() {
5243 // TODO(brianwilkerson) Pass the comment and metadata on where appropriate. 5243 // TODO(brianwilkerson) Pass the comment and metadata on where appropriate.
5244 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 5244 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
5245 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 5245 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
5246 if (matches4(peek(), TokenType.STRING)) { 5246 if (matches4(peek(), TokenType.STRING)) {
5247 Token afterString = skipStringLiteral(_currentToken.next); 5247 Token afterString = skipStringLiteral(_currentToken.next);
5248 if (afterString != null && identical(afterString.type, TokenType.COLON)) { 5248 if (afterString != null && identical(afterString.type, TokenType.COLON)) {
5249 return new ExpressionStatement(parseExpression4(), expect2(TokenType.S EMICOLON)); 5249 return new ExpressionStatement(parseExpression2(), expect2(TokenType.S EMICOLON));
5250 } 5250 }
5251 } 5251 }
5252 return parseBlock(); 5252 return parseBlock();
5253 } else if (matches5(TokenType.KEYWORD) && !(_currentToken as KeywordToken).k eyword.isPseudoKeyword) { 5253 } else if (matches5(TokenType.KEYWORD) && !(_currentToken as KeywordToken).k eyword.isPseudoKeyword) {
5254 Keyword keyword = (_currentToken as KeywordToken).keyword; 5254 Keyword keyword = (_currentToken as KeywordToken).keyword;
5255 // TODO(jwren) compute some metrics to figure out a better order for this if-then sequence to optimize performance 5255 // TODO(jwren) compute some metrics to figure out a better order for this if-then sequence to optimize performance
5256 if (identical(keyword, Keyword.ASSERT)) { 5256 if (identical(keyword, Keyword.ASSERT)) {
5257 return parseAssertStatement(); 5257 return parseAssertStatement();
5258 } else if (identical(keyword, Keyword.BREAK)) { 5258 } else if (identical(keyword, Keyword.BREAK)) {
5259 return parseBreakStatement(); 5259 return parseBreakStatement();
(...skipping 28 matching lines...) Expand all
5288 return parseFunctionDeclarationStatement2(commentAndMetadata, returnTy pe); 5288 return parseFunctionDeclarationStatement2(commentAndMetadata, returnTy pe);
5289 } else { 5289 } else {
5290 // 5290 //
5291 // We have found an error of some kind. Try to recover. 5291 // We have found an error of some kind. Try to recover.
5292 // 5292 //
5293 if (matchesIdentifier()) { 5293 if (matchesIdentifier()) {
5294 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) { 5294 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) {
5295 // 5295 //
5296 // We appear to have a variable declaration with a type of "void". 5296 // We appear to have a variable declaration with a type of "void".
5297 // 5297 //
5298 reportError11(ParserErrorCode.VOID_VARIABLE, returnType, []); 5298 reportError12(ParserErrorCode.VOID_VARIABLE, returnType, []);
5299 return parseVariableDeclarationStatement(commentAndMetadata); 5299 return parseVariableDeclarationStatement(commentAndMetadata);
5300 } 5300 }
5301 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 5301 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
5302 // 5302 //
5303 // We appear to have found an incomplete statement at the end of a b lock. Parse it as a 5303 // We appear to have found an incomplete statement at the end of a b lock. Parse it as a
5304 // variable declaration. 5304 // variable declaration.
5305 // 5305 //
5306 return parseVariableDeclarationStatement2(commentAndMetadata, null, returnType); 5306 return parseVariableDeclarationStatement2(commentAndMetadata, null, returnType);
5307 } 5307 }
5308 reportError12(ParserErrorCode.MISSING_STATEMENT, []); 5308 reportError13(ParserErrorCode.MISSING_STATEMENT, []);
5309 // TODO(brianwilkerson) Recover from this error. 5309 // TODO(brianwilkerson) Recover from this error.
5310 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON)); 5310 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON));
5311 } 5311 }
5312 } else if (identical(keyword, Keyword.CONST)) { 5312 } else if (identical(keyword, Keyword.CONST)) {
5313 if (matchesAny(peek(), [ 5313 if (matchesAny(peek(), [
5314 TokenType.LT, 5314 TokenType.LT,
5315 TokenType.OPEN_CURLY_BRACKET, 5315 TokenType.OPEN_CURLY_BRACKET,
5316 TokenType.OPEN_SQUARE_BRACKET, 5316 TokenType.OPEN_SQUARE_BRACKET,
5317 TokenType.INDEX])) { 5317 TokenType.INDEX])) {
5318 return new ExpressionStatement(parseExpression4(), expect2(TokenType.S EMICOLON)); 5318 return new ExpressionStatement(parseExpression2(), expect2(TokenType.S EMICOLON));
5319 } else if (matches4(peek(), TokenType.IDENTIFIER)) { 5319 } else if (matches4(peek(), TokenType.IDENTIFIER)) {
5320 Token afterType = skipTypeName(peek()); 5320 Token afterType = skipTypeName(peek());
5321 if (afterType != null) { 5321 if (afterType != null) {
5322 if (matches4(afterType, TokenType.OPEN_PAREN) || (matches4(afterType , TokenType.PERIOD) && matches4(afterType.next, TokenType.IDENTIFIER) && matches 4(afterType.next.next, TokenType.OPEN_PAREN))) { 5322 if (matches4(afterType, TokenType.OPEN_PAREN) || (matches4(afterType , TokenType.PERIOD) && matches4(afterType.next, TokenType.IDENTIFIER) && matches 4(afterType.next.next, TokenType.OPEN_PAREN))) {
5323 return new ExpressionStatement(parseExpression4(), expect2(TokenTy pe.SEMICOLON)); 5323 return new ExpressionStatement(parseExpression2(), expect2(TokenTy pe.SEMICOLON));
5324 } 5324 }
5325 } 5325 }
5326 } 5326 }
5327 return parseVariableDeclarationStatement(commentAndMetadata); 5327 return parseVariableDeclarationStatement(commentAndMetadata);
5328 } else if (identical(keyword, Keyword.NEW) || identical(keyword, Keyword.T RUE) || identical(keyword, Keyword.FALSE) || identical(keyword, Keyword.NULL) || identical(keyword, Keyword.SUPER) || identical(keyword, Keyword.THIS)) { 5328 } else if (identical(keyword, Keyword.NEW) || identical(keyword, Keyword.T RUE) || identical(keyword, Keyword.FALSE) || identical(keyword, Keyword.NULL) || identical(keyword, Keyword.SUPER) || identical(keyword, Keyword.THIS)) {
5329 return new ExpressionStatement(parseExpression4(), expect2(TokenType.SEM ICOLON)); 5329 return new ExpressionStatement(parseExpression2(), expect2(TokenType.SEM ICOLON));
5330 } else { 5330 } else {
5331 // 5331 //
5332 // We have found an error of some kind. Try to recover. 5332 // We have found an error of some kind. Try to recover.
5333 // 5333 //
5334 reportError12(ParserErrorCode.MISSING_STATEMENT, []); 5334 reportError13(ParserErrorCode.MISSING_STATEMENT, []);
5335 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON)); 5335 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON));
5336 } 5336 }
5337 } else if (matches5(TokenType.SEMICOLON)) { 5337 } else if (matches5(TokenType.SEMICOLON)) {
5338 return parseEmptyStatement(); 5338 return parseEmptyStatement();
5339 } else if (isInitializedVariableDeclaration()) { 5339 } else if (isInitializedVariableDeclaration()) {
5340 return parseVariableDeclarationStatement(commentAndMetadata); 5340 return parseVariableDeclarationStatement(commentAndMetadata);
5341 } else if (isFunctionDeclaration()) { 5341 } else if (isFunctionDeclaration()) {
5342 return parseFunctionDeclarationStatement(); 5342 return parseFunctionDeclarationStatement();
5343 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 5343 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
5344 reportError12(ParserErrorCode.MISSING_STATEMENT, []); 5344 reportError13(ParserErrorCode.MISSING_STATEMENT, []);
5345 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON)); 5345 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON));
5346 } else { 5346 } else {
5347 return new ExpressionStatement(parseExpression4(), expect2(TokenType.SEMIC OLON)); 5347 return new ExpressionStatement(parseExpression2(), expect2(TokenType.SEMIC OLON));
5348 } 5348 }
5349 } 5349 }
5350 5350
5351 /** 5351 /**
5352 * Parse an operator declaration. 5352 * Parse an operator declaration.
5353 * 5353 *
5354 * <pre> 5354 * <pre>
5355 * operatorDeclaration ::= 5355 * operatorDeclaration ::=
5356 * operatorSignature (';' | functionBody) 5356 * operatorSignature (';' | functionBody)
5357 * 5357 *
5358 * operatorSignature ::= 5358 * operatorSignature ::=
5359 * 'external'? returnType? 'operator' operator formalParameterList 5359 * 'external'? returnType? 'operator' operator formalParameterList
5360 * </pre> 5360 * </pre>
5361 * 5361 *
5362 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 5362 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
5363 * declaration 5363 * declaration
5364 * @param externalKeyword the 'external' token 5364 * @param externalKeyword the 'external' token
5365 * @param the return type that has already been parsed, or `null` if there was no return 5365 * @param the return type that has already been parsed, or `null` if there was no return
5366 * type 5366 * type
5367 * @return the operator declaration that was parsed 5367 * @return the operator declaration that was parsed
5368 */ 5368 */
5369 MethodDeclaration parseOperator(CommentAndMetadata commentAndMetadata, Token e xternalKeyword, TypeName returnType) { 5369 MethodDeclaration parseOperator(CommentAndMetadata commentAndMetadata, Token e xternalKeyword, TypeName returnType) {
5370 Token operatorKeyword; 5370 Token operatorKeyword;
5371 if (matches(Keyword.OPERATOR)) { 5371 if (matches(Keyword.OPERATOR)) {
5372 operatorKeyword = andAdvance; 5372 operatorKeyword = andAdvance;
5373 } else { 5373 } else {
5374 reportError13(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToken, []) ; 5374 reportError14(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToken, []) ;
5375 operatorKeyword = createSyntheticToken(Keyword.OPERATOR); 5375 operatorKeyword = createSyntheticToken(Keyword.OPERATOR);
5376 } 5376 }
5377 if (!_currentToken.isUserDefinableOperator) { 5377 if (!_currentToken.isUserDefinableOperator) {
5378 reportError12(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken. lexeme]); 5378 reportError13(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken. lexeme]);
5379 } 5379 }
5380 SimpleIdentifier name = new SimpleIdentifier(andAdvance); 5380 SimpleIdentifier name = new SimpleIdentifier(andAdvance);
5381 if (matches5(TokenType.EQ)) { 5381 if (matches5(TokenType.EQ)) {
5382 Token previous = _currentToken.previous; 5382 Token previous = _currentToken.previous;
5383 if ((matches4(previous, TokenType.EQ_EQ) || matches4(previous, TokenType.B ANG_EQ)) && _currentToken.offset == previous.offset + 2) { 5383 if ((matches4(previous, TokenType.EQ_EQ) || matches4(previous, TokenType.B ANG_EQ)) && _currentToken.offset == previous.offset + 2) {
5384 reportError12(ParserErrorCode.INVALID_OPERATOR, ["${previous.lexeme}${_c urrentToken.lexeme}"]); 5384 reportError13(ParserErrorCode.INVALID_OPERATOR, ["${previous.lexeme}${_c urrentToken.lexeme}"]);
5385 advance(); 5385 advance();
5386 } 5386 }
5387 } 5387 }
5388 FormalParameterList parameters = parseFormalParameterList(); 5388 FormalParameterList parameters = parseFormalParameterList();
5389 validateFormalParameterList(parameters); 5389 validateFormalParameterList(parameters);
5390 FunctionBody body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION _BODY, false); 5390 FunctionBody body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION _BODY, false);
5391 if (externalKeyword != null && body is! EmptyFunctionBody) { 5391 if (externalKeyword != null && body is! EmptyFunctionBody) {
5392 reportError12(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, []); 5392 reportError13(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, []);
5393 } 5393 }
5394 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, null, returnType, null, operatorKeyword, name, parame ters, body); 5394 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, null, returnType, null, operatorKeyword, name, parame ters, body);
5395 } 5395 }
5396 5396
5397 /** 5397 /**
5398 * Parse a return type if one is given, otherwise return `null` without advanc ing. 5398 * Parse a return type if one is given, otherwise return `null` without advanc ing.
5399 * 5399 *
5400 * @return the return type that was parsed 5400 * @return the return type that was parsed
5401 */ 5401 */
5402 TypeName parseOptionalReturnType() { 5402 TypeName parseOptionalReturnType() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
5467 } else { 5467 } else {
5468 operand = parseAssignableSelector(operand, true); 5468 operand = parseAssignableSelector(operand, true);
5469 } 5469 }
5470 } while (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PER IOD) || matches5(TokenType.OPEN_PAREN)); 5470 } while (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PER IOD) || matches5(TokenType.OPEN_PAREN));
5471 return operand; 5471 return operand;
5472 } 5472 }
5473 if (!_currentToken.type.isIncrementOperator) { 5473 if (!_currentToken.type.isIncrementOperator) {
5474 return operand; 5474 return operand;
5475 } 5475 }
5476 if (operand is Literal || operand is FunctionExpressionInvocation) { 5476 if (operand is Literal || operand is FunctionExpressionInvocation) {
5477 reportError12(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); 5477 reportError13(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []);
5478 } 5478 }
5479 Token operator = andAdvance; 5479 Token operator = andAdvance;
5480 return new PostfixExpression(operand, operator); 5480 return new PostfixExpression(operand, operator);
5481 } 5481 }
5482 5482
5483 /** 5483 /**
5484 * Parse a primary expression. 5484 * Parse a primary expression.
5485 * 5485 *
5486 * <pre> 5486 * <pre>
5487 * primary ::= 5487 * primary ::=
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
5562 return parsePrefixedIdentifier(); 5562 return parsePrefixedIdentifier();
5563 } else if (matches(Keyword.NEW)) { 5563 } else if (matches(Keyword.NEW)) {
5564 return parseNewExpression(); 5564 return parseNewExpression();
5565 } else if (matches(Keyword.CONST)) { 5565 } else if (matches(Keyword.CONST)) {
5566 return parseConstExpression(); 5566 return parseConstExpression();
5567 } else if (matches5(TokenType.OPEN_PAREN)) { 5567 } else if (matches5(TokenType.OPEN_PAREN)) {
5568 if (isFunctionExpression(_currentToken)) { 5568 if (isFunctionExpression(_currentToken)) {
5569 return parseFunctionExpression(); 5569 return parseFunctionExpression();
5570 } 5570 }
5571 Token leftParenthesis = andAdvance; 5571 Token leftParenthesis = andAdvance;
5572 Expression expression = parseExpression4(); 5572 Expression expression = parseExpression2();
5573 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 5573 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
5574 return new ParenthesizedExpression(leftParenthesis, expression, rightParen thesis); 5574 return new ParenthesizedExpression(leftParenthesis, expression, rightParen thesis);
5575 } else if (matches5(TokenType.LT)) { 5575 } else if (matches5(TokenType.LT)) {
5576 return parseListOrMapLiteral(null); 5576 return parseListOrMapLiteral(null);
5577 } else if (matches5(TokenType.QUESTION)) { 5577 } else if (matches5(TokenType.QUESTION)) {
5578 return parseArgumentDefinitionTest(); 5578 return parseArgumentDefinitionTest();
5579 } else if (matches(Keyword.VOID)) { 5579 } else if (matches(Keyword.VOID)) {
5580 // 5580 //
5581 // Recover from having a return type of "void" where a return type is not expected. 5581 // Recover from having a return type of "void" where a return type is not expected.
5582 // 5582 //
5583 // TODO(brianwilkerson) Improve this error message. 5583 // TODO(brianwilkerson) Improve this error message.
5584 reportError12(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]); 5584 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]);
5585 advance(); 5585 advance();
5586 return parsePrimaryExpression(); 5586 return parsePrimaryExpression();
5587 } else if (matches5(TokenType.HASH)) { 5587 } else if (matches5(TokenType.HASH)) {
5588 return parseSymbolLiteral(); 5588 return parseSymbolLiteral();
5589 } else { 5589 } else {
5590 reportError12(ParserErrorCode.MISSING_IDENTIFIER, []); 5590 reportError13(ParserErrorCode.MISSING_IDENTIFIER, []);
5591 return createSyntheticIdentifier(); 5591 return createSyntheticIdentifier();
5592 } 5592 }
5593 } 5593 }
5594 5594
5595 /** 5595 /**
5596 * Parse a redirecting constructor invocation. 5596 * Parse a redirecting constructor invocation.
5597 * 5597 *
5598 * <pre> 5598 * <pre>
5599 * redirectingConstructorInvocation ::= 5599 * redirectingConstructorInvocation ::=
5600 * 'this' ('.' identifier)? arguments 5600 * 'this' ('.' identifier)? arguments
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
5670 * 'return' expression? ';' 5670 * 'return' expression? ';'
5671 * </pre> 5671 * </pre>
5672 * 5672 *
5673 * @return the return statement that was parsed 5673 * @return the return statement that was parsed
5674 */ 5674 */
5675 Statement parseReturnStatement() { 5675 Statement parseReturnStatement() {
5676 Token returnKeyword = expect(Keyword.RETURN); 5676 Token returnKeyword = expect(Keyword.RETURN);
5677 if (matches5(TokenType.SEMICOLON)) { 5677 if (matches5(TokenType.SEMICOLON)) {
5678 return new ReturnStatement(returnKeyword, null, andAdvance); 5678 return new ReturnStatement(returnKeyword, null, andAdvance);
5679 } 5679 }
5680 Expression expression = parseExpression4(); 5680 Expression expression = parseExpression2();
5681 Token semicolon = expect2(TokenType.SEMICOLON); 5681 Token semicolon = expect2(TokenType.SEMICOLON);
5682 return new ReturnStatement(returnKeyword, expression, semicolon); 5682 return new ReturnStatement(returnKeyword, expression, semicolon);
5683 } 5683 }
5684 5684
5685 /** 5685 /**
5686 * Parse a setter. 5686 * Parse a setter.
5687 * 5687 *
5688 * <pre> 5688 * <pre>
5689 * setter ::= 5689 * setter ::=
5690 * setterSignature functionBody? 5690 * setterSignature functionBody?
(...skipping 10 matching lines...) Expand all
5701 * type 5701 * type
5702 * @return the setter that was parsed 5702 * @return the setter that was parsed
5703 */ 5703 */
5704 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) { 5704 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) {
5705 Token propertyKeyword = expect(Keyword.SET); 5705 Token propertyKeyword = expect(Keyword.SET);
5706 SimpleIdentifier name = parseSimpleIdentifier(); 5706 SimpleIdentifier name = parseSimpleIdentifier();
5707 FormalParameterList parameters = parseFormalParameterList(); 5707 FormalParameterList parameters = parseFormalParameterList();
5708 validateFormalParameterList(parameters); 5708 validateFormalParameterList(parameters);
5709 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, false); 5709 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, false);
5710 if (externalKeyword != null && body is! EmptyFunctionBody) { 5710 if (externalKeyword != null && body is! EmptyFunctionBody) {
5711 reportError12(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []); 5711 reportError13(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []);
5712 } 5712 }
5713 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, parameters, body); 5713 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, parameters, body);
5714 } 5714 }
5715 5715
5716 /** 5716 /**
5717 * Parse a shift expression. 5717 * Parse a shift expression.
5718 * 5718 *
5719 * <pre> 5719 * <pre>
5720 * shiftExpression ::= 5720 * shiftExpression ::=
5721 * additiveExpression (shiftOperator additiveExpression)* 5721 * additiveExpression (shiftOperator additiveExpression)*
(...skipping 25 matching lines...) Expand all
5747 * </pre> 5747 * </pre>
5748 * 5748 *
5749 * @return the statements that were parsed 5749 * @return the statements that were parsed
5750 */ 5750 */
5751 List<Statement> parseStatements2() { 5751 List<Statement> parseStatements2() {
5752 List<Statement> statements = new List<Statement>(); 5752 List<Statement> statements = new List<Statement>();
5753 Token statementStart = _currentToken; 5753 Token statementStart = _currentToken;
5754 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && !isSwitchMember()) { 5754 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && !isSwitchMember()) {
5755 statements.add(parseStatement2()); 5755 statements.add(parseStatement2());
5756 if (identical(_currentToken, statementStart)) { 5756 if (identical(_currentToken, statementStart)) {
5757 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 5757 reportError14(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
5758 advance(); 5758 advance();
5759 } 5759 }
5760 statementStart = _currentToken; 5760 statementStart = _currentToken;
5761 } 5761 }
5762 return statements; 5762 return statements;
5763 } 5763 }
5764 5764
5765 /** 5765 /**
5766 * Parse a string literal that contains interpolations. 5766 * Parse a string literal that contains interpolations.
5767 * 5767 *
5768 * @return the string literal that was parsed 5768 * @return the string literal that was parsed
5769 */ 5769 */
5770 StringInterpolation parseStringInterpolation(Token string) { 5770 StringInterpolation parseStringInterpolation(Token string) {
5771 List<InterpolationElement> elements = new List<InterpolationElement>(); 5771 List<InterpolationElement> elements = new List<InterpolationElement>();
5772 bool hasMore = matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matche s5(TokenType.STRING_INTERPOLATION_IDENTIFIER); 5772 bool hasMore = matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matche s5(TokenType.STRING_INTERPOLATION_IDENTIFIER);
5773 elements.add(new InterpolationString(string, computeStringValue(string.lexem e, true, !hasMore))); 5773 elements.add(new InterpolationString(string, computeStringValue(string.lexem e, true, !hasMore)));
5774 while (hasMore) { 5774 while (hasMore) {
5775 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION)) { 5775 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION)) {
5776 Token openToken = andAdvance; 5776 Token openToken = andAdvance;
5777 Expression expression = parseExpression4(); 5777 Expression expression = parseExpression2();
5778 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 5778 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
5779 elements.add(new InterpolationExpression(openToken, expression, rightBra cket)); 5779 elements.add(new InterpolationExpression(openToken, expression, rightBra cket));
5780 } else { 5780 } else {
5781 Token openToken = andAdvance; 5781 Token openToken = andAdvance;
5782 Expression expression = null; 5782 Expression expression = null;
5783 if (matches(Keyword.THIS)) { 5783 if (matches(Keyword.THIS)) {
5784 expression = new ThisExpression(andAdvance); 5784 expression = new ThisExpression(andAdvance);
5785 } else { 5785 } else {
5786 expression = parseSimpleIdentifier(); 5786 expression = parseSimpleIdentifier();
5787 } 5787 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
5834 * 5834 *
5835 * @return the switch statement that was parsed 5835 * @return the switch statement that was parsed
5836 */ 5836 */
5837 SwitchStatement parseSwitchStatement() { 5837 SwitchStatement parseSwitchStatement() {
5838 bool wasInSwitch = _inSwitch; 5838 bool wasInSwitch = _inSwitch;
5839 _inSwitch = true; 5839 _inSwitch = true;
5840 try { 5840 try {
5841 Set<String> definedLabels = new Set<String>(); 5841 Set<String> definedLabels = new Set<String>();
5842 Token keyword = expect(Keyword.SWITCH); 5842 Token keyword = expect(Keyword.SWITCH);
5843 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 5843 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
5844 Expression expression = parseExpression4(); 5844 Expression expression = parseExpression2();
5845 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 5845 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
5846 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 5846 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET);
5847 Token defaultKeyword = null; 5847 Token defaultKeyword = null;
5848 List<SwitchMember> members = new List<SwitchMember>(); 5848 List<SwitchMember> members = new List<SwitchMember>();
5849 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET )) { 5849 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET )) {
5850 List<Label> labels = new List<Label>(); 5850 List<Label> labels = new List<Label>();
5851 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 5851 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) {
5852 SimpleIdentifier identifier = parseSimpleIdentifier(); 5852 SimpleIdentifier identifier = parseSimpleIdentifier();
5853 String label = identifier.token.lexeme; 5853 String label = identifier.token.lexeme;
5854 if (definedLabels.contains(label)) { 5854 if (definedLabels.contains(label)) {
5855 reportError13(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, i dentifier.token, [label]); 5855 reportError14(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, i dentifier.token, [label]);
5856 } else { 5856 } else {
5857 definedLabels.add(label); 5857 definedLabels.add(label);
5858 } 5858 }
5859 Token colon = expect2(TokenType.COLON); 5859 Token colon = expect2(TokenType.COLON);
5860 labels.add(new Label(identifier, colon)); 5860 labels.add(new Label(identifier, colon));
5861 } 5861 }
5862 if (matches(Keyword.CASE)) { 5862 if (matches(Keyword.CASE)) {
5863 Token caseKeyword = andAdvance; 5863 Token caseKeyword = andAdvance;
5864 Expression caseExpression = parseExpression4(); 5864 Expression caseExpression = parseExpression2();
5865 Token colon = expect2(TokenType.COLON); 5865 Token colon = expect2(TokenType.COLON);
5866 members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon, parseStatements2())); 5866 members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon, parseStatements2()));
5867 if (defaultKeyword != null) { 5867 if (defaultKeyword != null) {
5868 reportError13(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, ca seKeyword, []); 5868 reportError14(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, ca seKeyword, []);
5869 } 5869 }
5870 } else if (matches(Keyword.DEFAULT)) { 5870 } else if (matches(Keyword.DEFAULT)) {
5871 if (defaultKeyword != null) { 5871 if (defaultKeyword != null) {
5872 reportError13(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, pee k(), []); 5872 reportError14(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, pee k(), []);
5873 } 5873 }
5874 defaultKeyword = andAdvance; 5874 defaultKeyword = andAdvance;
5875 Token colon = expect2(TokenType.COLON); 5875 Token colon = expect2(TokenType.COLON);
5876 members.add(new SwitchDefault(labels, defaultKeyword, colon, parseStat ements2())); 5876 members.add(new SwitchDefault(labels, defaultKeyword, colon, parseStat ements2()));
5877 } else { 5877 } else {
5878 // We need to advance, otherwise we could end up in an infinite loop, but this could be a 5878 // We need to advance, otherwise we could end up in an infinite loop, but this could be a
5879 // lot smarter about recovering from the error. 5879 // lot smarter about recovering from the error.
5880 reportError12(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []); 5880 reportError13(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []);
5881 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRA CKET) && !matches(Keyword.CASE) && !matches(Keyword.DEFAULT)) { 5881 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRA CKET) && !matches(Keyword.CASE) && !matches(Keyword.DEFAULT)) {
5882 advance(); 5882 advance();
5883 } 5883 }
5884 } 5884 }
5885 } 5885 }
5886 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 5886 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
5887 return new SwitchStatement(keyword, leftParenthesis, expression, rightPare nthesis, leftBracket, members, rightBracket); 5887 return new SwitchStatement(keyword, leftParenthesis, expression, rightPare nthesis, leftBracket, members, rightBracket);
5888 } finally { 5888 } finally {
5889 _inSwitch = wasInSwitch; 5889 _inSwitch = wasInSwitch;
5890 } 5890 }
(...skipping 12 matching lines...) Expand all
5903 SymbolLiteral parseSymbolLiteral() { 5903 SymbolLiteral parseSymbolLiteral() {
5904 Token poundSign = andAdvance; 5904 Token poundSign = andAdvance;
5905 List<Token> components = new List<Token>(); 5905 List<Token> components = new List<Token>();
5906 if (matchesIdentifier()) { 5906 if (matchesIdentifier()) {
5907 components.add(andAdvance); 5907 components.add(andAdvance);
5908 while (matches5(TokenType.PERIOD)) { 5908 while (matches5(TokenType.PERIOD)) {
5909 advance(); 5909 advance();
5910 if (matchesIdentifier()) { 5910 if (matchesIdentifier()) {
5911 components.add(andAdvance); 5911 components.add(andAdvance);
5912 } else { 5912 } else {
5913 reportError12(ParserErrorCode.MISSING_IDENTIFIER, []); 5913 reportError13(ParserErrorCode.MISSING_IDENTIFIER, []);
5914 components.add(createSyntheticToken2(TokenType.IDENTIFIER)); 5914 components.add(createSyntheticToken2(TokenType.IDENTIFIER));
5915 break; 5915 break;
5916 } 5916 }
5917 } 5917 }
5918 } else if (_currentToken.isOperator) { 5918 } else if (_currentToken.isOperator) {
5919 components.add(andAdvance); 5919 components.add(andAdvance);
5920 } else { 5920 } else {
5921 reportError12(ParserErrorCode.MISSING_IDENTIFIER, []); 5921 reportError13(ParserErrorCode.MISSING_IDENTIFIER, []);
5922 components.add(createSyntheticToken2(TokenType.IDENTIFIER)); 5922 components.add(createSyntheticToken2(TokenType.IDENTIFIER));
5923 } 5923 }
5924 return new SymbolLiteral(poundSign, new List.from(components)); 5924 return new SymbolLiteral(poundSign, new List.from(components));
5925 } 5925 }
5926 5926
5927 /** 5927 /**
5928 * Parse a throw expression. 5928 * Parse a throw expression.
5929 * 5929 *
5930 * <pre> 5930 * <pre>
5931 * throwExpression ::= 5931 * throwExpression ::=
5932 * 'throw' expression 5932 * 'throw' expression
5933 * </pre> 5933 * </pre>
5934 * 5934 *
5935 * @return the throw expression that was parsed 5935 * @return the throw expression that was parsed
5936 */ 5936 */
5937 Expression parseThrowExpression() { 5937 Expression parseThrowExpression() {
5938 Token keyword = expect(Keyword.THROW); 5938 Token keyword = expect(Keyword.THROW);
5939 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { 5939 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) {
5940 reportError13(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []); 5940 reportError14(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []);
5941 return new ThrowExpression(keyword, createSyntheticIdentifier()); 5941 return new ThrowExpression(keyword, createSyntheticIdentifier());
5942 } 5942 }
5943 Expression expression = parseExpression4(); 5943 Expression expression = parseExpression2();
5944 return new ThrowExpression(keyword, expression); 5944 return new ThrowExpression(keyword, expression);
5945 } 5945 }
5946 5946
5947 /** 5947 /**
5948 * Parse a throw expression. 5948 * Parse a throw expression.
5949 * 5949 *
5950 * <pre> 5950 * <pre>
5951 * throwExpressionWithoutCascade ::= 5951 * throwExpressionWithoutCascade ::=
5952 * 'throw' expressionWithoutCascade 5952 * 'throw' expressionWithoutCascade
5953 * </pre> 5953 * </pre>
5954 * 5954 *
5955 * @return the throw expression that was parsed 5955 * @return the throw expression that was parsed
5956 */ 5956 */
5957 Expression parseThrowExpressionWithoutCascade() { 5957 Expression parseThrowExpressionWithoutCascade() {
5958 Token keyword = expect(Keyword.THROW); 5958 Token keyword = expect(Keyword.THROW);
5959 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { 5959 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) {
5960 reportError13(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []); 5960 reportError14(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []);
5961 return new ThrowExpression(keyword, createSyntheticIdentifier()); 5961 return new ThrowExpression(keyword, createSyntheticIdentifier());
5962 } 5962 }
5963 Expression expression = parseExpressionWithoutCascade(); 5963 Expression expression = parseExpressionWithoutCascade();
5964 return new ThrowExpression(keyword, expression); 5964 return new ThrowExpression(keyword, expression);
5965 } 5965 }
5966 5966
5967 /** 5967 /**
5968 * Parse a try statement. 5968 * Parse a try statement.
5969 * 5969 *
5970 * <pre> 5970 * <pre>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
6014 } 6014 }
6015 Block catchBody = parseBlock(); 6015 Block catchBody = parseBlock();
6016 catchClauses.add(new CatchClause(onKeyword, exceptionType, catchKeyword, l eftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParenthesis , catchBody)); 6016 catchClauses.add(new CatchClause(onKeyword, exceptionType, catchKeyword, l eftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParenthesis , catchBody));
6017 } 6017 }
6018 Token finallyKeyword = null; 6018 Token finallyKeyword = null;
6019 if (matches(Keyword.FINALLY)) { 6019 if (matches(Keyword.FINALLY)) {
6020 finallyKeyword = andAdvance; 6020 finallyKeyword = andAdvance;
6021 finallyClause = parseBlock(); 6021 finallyClause = parseBlock();
6022 } else { 6022 } else {
6023 if (catchClauses.isEmpty) { 6023 if (catchClauses.isEmpty) {
6024 reportError12(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []); 6024 reportError13(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []);
6025 } 6025 }
6026 } 6026 }
6027 return new TryStatement(tryKeyword, body, catchClauses, finallyKeyword, fina llyClause); 6027 return new TryStatement(tryKeyword, body, catchClauses, finallyKeyword, fina llyClause);
6028 } 6028 }
6029 6029
6030 /** 6030 /**
6031 * Parse a type alias. 6031 * Parse a type alias.
6032 * 6032 *
6033 * <pre> 6033 * <pre>
6034 * typeAlias ::= 6034 * typeAlias ::=
(...skipping 20 matching lines...) Expand all
6055 * @return the type alias that was parsed 6055 * @return the type alias that was parsed
6056 */ 6056 */
6057 TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) { 6057 TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) {
6058 Token keyword = expect(Keyword.TYPEDEF); 6058 Token keyword = expect(Keyword.TYPEDEF);
6059 if (matchesIdentifier()) { 6059 if (matchesIdentifier()) {
6060 Token next = peek(); 6060 Token next = peek();
6061 if (matches4(next, TokenType.LT)) { 6061 if (matches4(next, TokenType.LT)) {
6062 next = skipTypeParameterList(next); 6062 next = skipTypeParameterList(next);
6063 if (next != null && matches4(next, TokenType.EQ)) { 6063 if (next != null && matches4(next, TokenType.EQ)) {
6064 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, ke yword); 6064 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, ke yword);
6065 reportError13(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword, [] ); 6065 reportError14(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword, [] );
6066 return typeAlias; 6066 return typeAlias;
6067 } 6067 }
6068 } else if (matches4(next, TokenType.EQ)) { 6068 } else if (matches4(next, TokenType.EQ)) {
6069 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, keyw ord); 6069 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, keyw ord);
6070 reportError13(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword, []); 6070 reportError14(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword, []);
6071 return typeAlias; 6071 return typeAlias;
6072 } 6072 }
6073 } 6073 }
6074 return parseFunctionTypeAlias(commentAndMetadata, keyword); 6074 return parseFunctionTypeAlias(commentAndMetadata, keyword);
6075 } 6075 }
6076 6076
6077 /** 6077 /**
6078 * Parse a unary expression. 6078 * Parse a unary expression.
6079 * 6079 *
6080 * <pre> 6080 * <pre>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
6117 if (identical(operator.type, TokenType.MINUS_MINUS)) { 6117 if (identical(operator.type, TokenType.MINUS_MINUS)) {
6118 int offset = operator.offset; 6118 int offset = operator.offset;
6119 Token firstOperator = new Token(TokenType.MINUS, offset); 6119 Token firstOperator = new Token(TokenType.MINUS, offset);
6120 Token secondOperator = new Token(TokenType.MINUS, offset + 1); 6120 Token secondOperator = new Token(TokenType.MINUS, offset + 1);
6121 secondOperator.setNext(_currentToken); 6121 secondOperator.setNext(_currentToken);
6122 firstOperator.setNext(secondOperator); 6122 firstOperator.setNext(secondOperator);
6123 operator.previous.setNext(firstOperator); 6123 operator.previous.setNext(firstOperator);
6124 return new PrefixExpression(firstOperator, new PrefixExpression(second Operator, new SuperExpression(andAdvance))); 6124 return new PrefixExpression(firstOperator, new PrefixExpression(second Operator, new SuperExpression(andAdvance)));
6125 } else { 6125 } else {
6126 // Invalid operator before 'super' 6126 // Invalid operator before 'super'
6127 reportError12(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.le xeme]); 6127 reportError13(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.le xeme]);
6128 return new PrefixExpression(operator, new SuperExpression(andAdvance)) ; 6128 return new PrefixExpression(operator, new SuperExpression(andAdvance)) ;
6129 } 6129 }
6130 } 6130 }
6131 return new PrefixExpression(operator, parseAssignableExpression(false)); 6131 return new PrefixExpression(operator, parseAssignableExpression(false));
6132 } else if (matches5(TokenType.PLUS)) { 6132 } else if (matches5(TokenType.PLUS)) {
6133 reportError12(ParserErrorCode.MISSING_IDENTIFIER, []); 6133 reportError13(ParserErrorCode.MISSING_IDENTIFIER, []);
6134 return createSyntheticIdentifier(); 6134 return createSyntheticIdentifier();
6135 } 6135 }
6136 return parsePostfixExpression(); 6136 return parsePostfixExpression();
6137 } 6137 }
6138 6138
6139 /** 6139 /**
6140 * Parse a variable declaration. 6140 * Parse a variable declaration.
6141 * 6141 *
6142 * <pre> 6142 * <pre>
6143 * variableDeclaration ::= 6143 * variableDeclaration ::=
6144 * identifier ('=' expression)? 6144 * identifier ('=' expression)?
6145 * </pre> 6145 * </pre>
6146 * 6146 *
6147 * @return the variable declaration that was parsed 6147 * @return the variable declaration that was parsed
6148 */ 6148 */
6149 VariableDeclaration parseVariableDeclaration() { 6149 VariableDeclaration parseVariableDeclaration() {
6150 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 6150 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
6151 SimpleIdentifier name = parseSimpleIdentifier(); 6151 SimpleIdentifier name = parseSimpleIdentifier();
6152 Token equals = null; 6152 Token equals = null;
6153 Expression initializer = null; 6153 Expression initializer = null;
6154 if (matches5(TokenType.EQ)) { 6154 if (matches5(TokenType.EQ)) {
6155 equals = andAdvance; 6155 equals = andAdvance;
6156 initializer = parseExpression4(); 6156 initializer = parseExpression2();
6157 } 6157 }
6158 return new VariableDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, name, equals, initializer); 6158 return new VariableDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, name, equals, initializer);
6159 } 6159 }
6160 6160
6161 /** 6161 /**
6162 * Parse a variable declaration list. 6162 * Parse a variable declaration list.
6163 * 6163 *
6164 * <pre> 6164 * <pre>
6165 * variableDeclarationList ::= 6165 * variableDeclarationList ::=
6166 * finalConstVarOrType variableDeclaration (',' variableDeclaration)* 6166 * finalConstVarOrType variableDeclaration (',' variableDeclaration)*
(...skipping 17 matching lines...) Expand all
6184 * 6184 *
6185 * @param commentAndMetadata the metadata to be associated with the variable d eclaration list, or 6185 * @param commentAndMetadata the metadata to be associated with the variable d eclaration list, or
6186 * `null` if there is no attempt at parsing the comment and metadata 6186 * `null` if there is no attempt at parsing the comment and metadata
6187 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if 6187 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if
6188 * there is no keyword 6188 * there is no keyword
6189 * @param type the type of the variables in the list 6189 * @param type the type of the variables in the list
6190 * @return the variable declaration list that was parsed 6190 * @return the variable declaration list that was parsed
6191 */ 6191 */
6192 VariableDeclarationList parseVariableDeclarationList2(CommentAndMetadata comme ntAndMetadata, Token keyword, TypeName type) { 6192 VariableDeclarationList parseVariableDeclarationList2(CommentAndMetadata comme ntAndMetadata, Token keyword, TypeName type) {
6193 if (type != null && keyword != null && matches3(keyword, Keyword.VAR)) { 6193 if (type != null && keyword != null && matches3(keyword, Keyword.VAR)) {
6194 reportError13(ParserErrorCode.VAR_AND_TYPE, keyword, []); 6194 reportError14(ParserErrorCode.VAR_AND_TYPE, keyword, []);
6195 } 6195 }
6196 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 6196 List<VariableDeclaration> variables = new List<VariableDeclaration>();
6197 variables.add(parseVariableDeclaration()); 6197 variables.add(parseVariableDeclaration());
6198 while (matches5(TokenType.COMMA)) { 6198 while (matches5(TokenType.COMMA)) {
6199 advance(); 6199 advance();
6200 variables.add(parseVariableDeclaration()); 6200 variables.add(parseVariableDeclaration());
6201 } 6201 }
6202 return new VariableDeclarationList(commentAndMetadata != null ? commentAndMe tadata.comment : null, commentAndMetadata != null ? commentAndMetadata.metadata : null, keyword, type, variables); 6202 return new VariableDeclarationList(commentAndMetadata != null ? commentAndMe tadata.comment : null, commentAndMetadata != null ? commentAndMetadata.metadata : null, keyword, type, variables);
6203 } 6203 }
6204 6204
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
6257 * </pre> 6257 * </pre>
6258 * 6258 *
6259 * @return the while statement that was parsed 6259 * @return the while statement that was parsed
6260 */ 6260 */
6261 Statement parseWhileStatement() { 6261 Statement parseWhileStatement() {
6262 bool wasInLoop = _inLoop; 6262 bool wasInLoop = _inLoop;
6263 _inLoop = true; 6263 _inLoop = true;
6264 try { 6264 try {
6265 Token keyword = expect(Keyword.WHILE); 6265 Token keyword = expect(Keyword.WHILE);
6266 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 6266 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
6267 Expression condition = parseExpression4(); 6267 Expression condition = parseExpression2();
6268 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 6268 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
6269 Statement body = parseStatement2(); 6269 Statement body = parseStatement2();
6270 return new WhileStatement(keyword, leftParenthesis, condition, rightParent hesis, body); 6270 return new WhileStatement(keyword, leftParenthesis, condition, rightParent hesis, body);
6271 } finally { 6271 } finally {
6272 _inLoop = wasInLoop; 6272 _inLoop = wasInLoop;
6273 } 6273 }
6274 } 6274 }
6275 6275
6276 /** 6276 /**
6277 * Return the token that is immediately after the current token. This is equiv alent to 6277 * Return the token that is immediately after the current token. This is equiv alent to
(...skipping 30 matching lines...) Expand all
6308 _errorListener.onError(error); 6308 _errorListener.onError(error);
6309 } 6309 }
6310 6310
6311 /** 6311 /**
6312 * Report an error with the given error code and arguments. 6312 * Report an error with the given error code and arguments.
6313 * 6313 *
6314 * @param errorCode the error code of the error to be reported 6314 * @param errorCode the error code of the error to be reported
6315 * @param node the node specifying the location of the error 6315 * @param node the node specifying the location of the error
6316 * @param arguments the arguments to the error, used to compose the error mess age 6316 * @param arguments the arguments to the error, used to compose the error mess age
6317 */ 6317 */
6318 void reportError11(ParserErrorCode errorCode, ASTNode node, List<Object> argum ents) { 6318 void reportError12(ParserErrorCode errorCode, ASTNode node, List<Object> argum ents) {
6319 reportError(new AnalysisError.con2(_source, node.offset, node.length, errorC ode, arguments)); 6319 reportError(new AnalysisError.con2(_source, node.offset, node.length, errorC ode, arguments));
6320 } 6320 }
6321 6321
6322 /** 6322 /**
6323 * Report an error with the given error code and arguments. 6323 * Report an error with the given error code and arguments.
6324 * 6324 *
6325 * @param errorCode the error code of the error to be reported 6325 * @param errorCode the error code of the error to be reported
6326 * @param arguments the arguments to the error, used to compose the error mess age 6326 * @param arguments the arguments to the error, used to compose the error mess age
6327 */ 6327 */
6328 void reportError12(ParserErrorCode errorCode, List<Object> arguments) { 6328 void reportError13(ParserErrorCode errorCode, List<Object> arguments) {
6329 reportError13(errorCode, _currentToken, arguments); 6329 reportError14(errorCode, _currentToken, arguments);
6330 } 6330 }
6331 6331
6332 /** 6332 /**
6333 * Report an error with the given error code and arguments. 6333 * Report an error with the given error code and arguments.
6334 * 6334 *
6335 * @param errorCode the error code of the error to be reported 6335 * @param errorCode the error code of the error to be reported
6336 * @param token the token specifying the location of the error 6336 * @param token the token specifying the location of the error
6337 * @param arguments the arguments to the error, used to compose the error mess age 6337 * @param arguments the arguments to the error, used to compose the error mess age
6338 */ 6338 */
6339 void reportError13(ParserErrorCode errorCode, Token token, List<Object> argume nts) { 6339 void reportError14(ParserErrorCode errorCode, Token token, List<Object> argume nts) {
6340 reportError(new AnalysisError.con2(_source, token.offset, token.length, erro rCode, arguments)); 6340 reportError(new AnalysisError.con2(_source, token.offset, token.length, erro rCode, arguments));
6341 } 6341 }
6342 6342
6343 /** 6343 /**
6344 * Skips a block with all containing blocks. 6344 * Skips a block with all containing blocks.
6345 */ 6345 */
6346 void skipBlock() { 6346 void skipBlock() {
6347 _currentToken = (_currentToken as BeginToken).endToken.next; 6347 _currentToken = (_currentToken as BeginToken).endToken.next;
6348 } 6348 }
6349 6349
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
6810 builder.appendChar(0xC); 6810 builder.appendChar(0xC);
6811 } else if (currentChar == 0x62) { 6811 } else if (currentChar == 0x62) {
6812 builder.appendChar(0x8); 6812 builder.appendChar(0x8);
6813 } else if (currentChar == 0x74) { 6813 } else if (currentChar == 0x74) {
6814 builder.appendChar(0x9); 6814 builder.appendChar(0x9);
6815 } else if (currentChar == 0x76) { 6815 } else if (currentChar == 0x76) {
6816 builder.appendChar(0xB); 6816 builder.appendChar(0xB);
6817 } else if (currentChar == 0x78) { 6817 } else if (currentChar == 0x78) {
6818 if (currentIndex + 2 >= length) { 6818 if (currentIndex + 2 >= length) {
6819 // Illegal escape sequence: not enough hex digits 6819 // Illegal escape sequence: not enough hex digits
6820 reportError12(ParserErrorCode.INVALID_HEX_ESCAPE, []); 6820 reportError13(ParserErrorCode.INVALID_HEX_ESCAPE, []);
6821 return length; 6821 return length;
6822 } 6822 }
6823 int firstDigit = lexeme.codeUnitAt(currentIndex + 1); 6823 int firstDigit = lexeme.codeUnitAt(currentIndex + 1);
6824 int secondDigit = lexeme.codeUnitAt(currentIndex + 2); 6824 int secondDigit = lexeme.codeUnitAt(currentIndex + 2);
6825 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit)) { 6825 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit)) {
6826 // Illegal escape sequence: invalid hex digit 6826 // Illegal escape sequence: invalid hex digit
6827 reportError12(ParserErrorCode.INVALID_HEX_ESCAPE, []); 6827 reportError13(ParserErrorCode.INVALID_HEX_ESCAPE, []);
6828 } else { 6828 } else {
6829 builder.appendChar(((Character.digit(firstDigit, 16) << 4) + Character.d igit(secondDigit, 16))); 6829 builder.appendChar(((Character.digit(firstDigit, 16) << 4) + Character.d igit(secondDigit, 16)));
6830 } 6830 }
6831 return currentIndex + 3; 6831 return currentIndex + 3;
6832 } else if (currentChar == 0x75) { 6832 } else if (currentChar == 0x75) {
6833 currentIndex++; 6833 currentIndex++;
6834 if (currentIndex >= length) { 6834 if (currentIndex >= length) {
6835 // Illegal escape sequence: not enough hex digits 6835 // Illegal escape sequence: not enough hex digits
6836 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6836 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6837 return length; 6837 return length;
6838 } 6838 }
6839 currentChar = lexeme.codeUnitAt(currentIndex); 6839 currentChar = lexeme.codeUnitAt(currentIndex);
6840 if (currentChar == 0x7B) { 6840 if (currentChar == 0x7B) {
6841 currentIndex++; 6841 currentIndex++;
6842 if (currentIndex >= length) { 6842 if (currentIndex >= length) {
6843 // Illegal escape sequence: incomplete escape 6843 // Illegal escape sequence: incomplete escape
6844 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6844 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6845 return length; 6845 return length;
6846 } 6846 }
6847 currentChar = lexeme.codeUnitAt(currentIndex); 6847 currentChar = lexeme.codeUnitAt(currentIndex);
6848 int digitCount = 0; 6848 int digitCount = 0;
6849 int value = 0; 6849 int value = 0;
6850 while (currentChar != 0x7D) { 6850 while (currentChar != 0x7D) {
6851 if (!isHexDigit(currentChar)) { 6851 if (!isHexDigit(currentChar)) {
6852 // Illegal escape sequence: invalid hex digit 6852 // Illegal escape sequence: invalid hex digit
6853 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6853 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6854 currentIndex++; 6854 currentIndex++;
6855 while (currentIndex < length && lexeme.codeUnitAt(currentIndex) != 0 x7D) { 6855 while (currentIndex < length && lexeme.codeUnitAt(currentIndex) != 0 x7D) {
6856 currentIndex++; 6856 currentIndex++;
6857 } 6857 }
6858 return currentIndex + 1; 6858 return currentIndex + 1;
6859 } 6859 }
6860 digitCount++; 6860 digitCount++;
6861 value = (value << 4) + Character.digit(currentChar, 16); 6861 value = (value << 4) + Character.digit(currentChar, 16);
6862 currentIndex++; 6862 currentIndex++;
6863 if (currentIndex >= length) { 6863 if (currentIndex >= length) {
6864 // Illegal escape sequence: incomplete escape 6864 // Illegal escape sequence: incomplete escape
6865 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6865 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6866 return length; 6866 return length;
6867 } 6867 }
6868 currentChar = lexeme.codeUnitAt(currentIndex); 6868 currentChar = lexeme.codeUnitAt(currentIndex);
6869 } 6869 }
6870 if (digitCount < 1 || digitCount > 6) { 6870 if (digitCount < 1 || digitCount > 6) {
6871 // Illegal escape sequence: not enough or too many hex digits 6871 // Illegal escape sequence: not enough or too many hex digits
6872 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6872 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6873 } 6873 }
6874 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), va lue, index, currentIndex); 6874 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), va lue, index, currentIndex);
6875 return currentIndex + 1; 6875 return currentIndex + 1;
6876 } else { 6876 } else {
6877 if (currentIndex + 3 >= length) { 6877 if (currentIndex + 3 >= length) {
6878 // Illegal escape sequence: not enough hex digits 6878 // Illegal escape sequence: not enough hex digits
6879 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6879 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6880 return length; 6880 return length;
6881 } 6881 }
6882 int firstDigit = currentChar; 6882 int firstDigit = currentChar;
6883 int secondDigit = lexeme.codeUnitAt(currentIndex + 1); 6883 int secondDigit = lexeme.codeUnitAt(currentIndex + 1);
6884 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2); 6884 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2);
6885 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3); 6885 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3);
6886 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit) || !isHexDigit(t hirdDigit) || !isHexDigit(fourthDigit)) { 6886 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit) || !isHexDigit(t hirdDigit) || !isHexDigit(fourthDigit)) {
6887 // Illegal escape sequence: invalid hex digits 6887 // Illegal escape sequence: invalid hex digits
6888 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6888 reportError13(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6889 } else { 6889 } else {
6890 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), (((((Character.digit(firstDigit, 16) << 4) + Character.digit(secondDigit, 16)) < < 4) + Character.digit(thirdDigit, 16)) << 4) + Character.digit(fourthDigit, 16) , index, currentIndex + 3); 6890 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), (((((Character.digit(firstDigit, 16) << 4) + Character.digit(secondDigit, 16)) < < 4) + Character.digit(thirdDigit, 16)) << 4) + Character.digit(fourthDigit, 16) , index, currentIndex + 3);
6891 } 6891 }
6892 return currentIndex + 4; 6892 return currentIndex + 4;
6893 } 6893 }
6894 } else { 6894 } else {
6895 builder.appendChar(currentChar); 6895 builder.appendChar(currentChar);
6896 } 6896 }
6897 return currentIndex + 1; 6897 return currentIndex + 1;
6898 } 6898 }
(...skipping 10 matching lines...) Expand all
6909 } 6909 }
6910 6910
6911 /** 6911 /**
6912 * Validate that the given parameter list does not contain any field initializ ers. 6912 * Validate that the given parameter list does not contain any field initializ ers.
6913 * 6913 *
6914 * @param parameterList the parameter list to be validated 6914 * @param parameterList the parameter list to be validated
6915 */ 6915 */
6916 void validateFormalParameterList(FormalParameterList parameterList) { 6916 void validateFormalParameterList(FormalParameterList parameterList) {
6917 for (FormalParameter parameter in parameterList.parameters) { 6917 for (FormalParameter parameter in parameterList.parameters) {
6918 if (parameter is FieldFormalParameter) { 6918 if (parameter is FieldFormalParameter) {
6919 reportError11(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, par ameter.identifier, []); 6919 reportError12(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, par ameter.identifier, []);
6920 } 6920 }
6921 } 6921 }
6922 } 6922 }
6923 6923
6924 /** 6924 /**
6925 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract' 6925 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract'
6926 * keyword if there is one. 6926 * keyword if there is one.
6927 * 6927 *
6928 * @param modifiers the modifiers being validated 6928 * @param modifiers the modifiers being validated
6929 */ 6929 */
6930 Token validateModifiersForClass(Modifiers modifiers) { 6930 Token validateModifiersForClass(Modifiers modifiers) {
6931 validateModifiersForTopLevelDeclaration(modifiers); 6931 validateModifiersForTopLevelDeclaration(modifiers);
6932 if (modifiers.constKeyword != null) { 6932 if (modifiers.constKeyword != null) {
6933 reportError13(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); 6933 reportError14(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []);
6934 } 6934 }
6935 if (modifiers.externalKeyword != null) { 6935 if (modifiers.externalKeyword != null) {
6936 reportError13(ParserErrorCode.EXTERNAL_CLASS, modifiers.externalKeyword, [ ]); 6936 reportError14(ParserErrorCode.EXTERNAL_CLASS, modifiers.externalKeyword, [ ]);
6937 } 6937 }
6938 if (modifiers.finalKeyword != null) { 6938 if (modifiers.finalKeyword != null) {
6939 reportError13(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); 6939 reportError14(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []);
6940 } 6940 }
6941 if (modifiers.varKeyword != null) { 6941 if (modifiers.varKeyword != null) {
6942 reportError13(ParserErrorCode.VAR_CLASS, modifiers.varKeyword, []); 6942 reportError14(ParserErrorCode.VAR_CLASS, modifiers.varKeyword, []);
6943 } 6943 }
6944 return modifiers.abstractKeyword; 6944 return modifiers.abstractKeyword;
6945 } 6945 }
6946 6946
6947 /** 6947 /**
6948 * Validate that the given set of modifiers is appropriate for a constructor a nd return the 6948 * Validate that the given set of modifiers is appropriate for a constructor a nd return the
6949 * 'const' keyword if there is one. 6949 * 'const' keyword if there is one.
6950 * 6950 *
6951 * @param modifiers the modifiers being validated 6951 * @param modifiers the modifiers being validated
6952 * @return the 'const' or 'final' keyword associated with the constructor 6952 * @return the 'const' or 'final' keyword associated with the constructor
6953 */ 6953 */
6954 Token validateModifiersForConstructor(Modifiers modifiers) { 6954 Token validateModifiersForConstructor(Modifiers modifiers) {
6955 if (modifiers.abstractKeyword != null) { 6955 if (modifiers.abstractKeyword != null) {
6956 reportError12(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 6956 reportError13(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []);
6957 } 6957 }
6958 if (modifiers.finalKeyword != null) { 6958 if (modifiers.finalKeyword != null) {
6959 reportError13(ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKeyword, [ ]); 6959 reportError14(ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKeyword, [ ]);
6960 } 6960 }
6961 if (modifiers.staticKeyword != null) { 6961 if (modifiers.staticKeyword != null) {
6962 reportError13(ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticKeyword, []); 6962 reportError14(ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticKeyword, []);
6963 } 6963 }
6964 if (modifiers.varKeyword != null) { 6964 if (modifiers.varKeyword != null) {
6965 reportError13(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, modifiers.varK eyword, []); 6965 reportError14(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, modifiers.varK eyword, []);
6966 } 6966 }
6967 Token externalKeyword = modifiers.externalKeyword; 6967 Token externalKeyword = modifiers.externalKeyword;
6968 Token constKeyword = modifiers.constKeyword; 6968 Token constKeyword = modifiers.constKeyword;
6969 Token factoryKeyword = modifiers.factoryKeyword; 6969 Token factoryKeyword = modifiers.factoryKeyword;
6970 if (externalKeyword != null && constKeyword != null && constKeyword.offset < externalKeyword.offset) { 6970 if (externalKeyword != null && constKeyword != null && constKeyword.offset < externalKeyword.offset) {
6971 reportError13(ParserErrorCode.EXTERNAL_AFTER_CONST, externalKeyword, []); 6971 reportError14(ParserErrorCode.EXTERNAL_AFTER_CONST, externalKeyword, []);
6972 } 6972 }
6973 if (externalKeyword != null && factoryKeyword != null && factoryKeyword.offs et < externalKeyword.offset) { 6973 if (externalKeyword != null && factoryKeyword != null && factoryKeyword.offs et < externalKeyword.offset) {
6974 reportError13(ParserErrorCode.EXTERNAL_AFTER_FACTORY, externalKeyword, []) ; 6974 reportError14(ParserErrorCode.EXTERNAL_AFTER_FACTORY, externalKeyword, []) ;
6975 } 6975 }
6976 return constKeyword; 6976 return constKeyword;
6977 } 6977 }
6978 6978
6979 /** 6979 /**
6980 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final', 6980 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final',
6981 * 'const' or 'var' keyword if there is one. 6981 * 'const' or 'var' keyword if there is one.
6982 * 6982 *
6983 * @param modifiers the modifiers being validated 6983 * @param modifiers the modifiers being validated
6984 * @return the 'final', 'const' or 'var' keyword associated with the field 6984 * @return the 'final', 'const' or 'var' keyword associated with the field
6985 */ 6985 */
6986 Token validateModifiersForField(Modifiers modifiers) { 6986 Token validateModifiersForField(Modifiers modifiers) {
6987 if (modifiers.abstractKeyword != null) { 6987 if (modifiers.abstractKeyword != null) {
6988 reportError12(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 6988 reportError13(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []);
6989 } 6989 }
6990 if (modifiers.externalKeyword != null) { 6990 if (modifiers.externalKeyword != null) {
6991 reportError13(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, [ ]); 6991 reportError14(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, [ ]);
6992 } 6992 }
6993 if (modifiers.factoryKeyword != null) { 6993 if (modifiers.factoryKeyword != null) {
6994 reportError13(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []); 6994 reportError14(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []);
6995 } 6995 }
6996 Token staticKeyword = modifiers.staticKeyword; 6996 Token staticKeyword = modifiers.staticKeyword;
6997 Token constKeyword = modifiers.constKeyword; 6997 Token constKeyword = modifiers.constKeyword;
6998 Token finalKeyword = modifiers.finalKeyword; 6998 Token finalKeyword = modifiers.finalKeyword;
6999 Token varKeyword = modifiers.varKeyword; 6999 Token varKeyword = modifiers.varKeyword;
7000 if (constKeyword != null) { 7000 if (constKeyword != null) {
7001 if (finalKeyword != null) { 7001 if (finalKeyword != null) {
7002 reportError13(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []); 7002 reportError14(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []);
7003 } 7003 }
7004 if (varKeyword != null) { 7004 if (varKeyword != null) {
7005 reportError13(ParserErrorCode.CONST_AND_VAR, varKeyword, []); 7005 reportError14(ParserErrorCode.CONST_AND_VAR, varKeyword, []);
7006 } 7006 }
7007 if (staticKeyword != null && constKeyword.offset < staticKeyword.offset) { 7007 if (staticKeyword != null && constKeyword.offset < staticKeyword.offset) {
7008 reportError13(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword, []); 7008 reportError14(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword, []);
7009 } 7009 }
7010 } else if (finalKeyword != null) { 7010 } else if (finalKeyword != null) {
7011 if (varKeyword != null) { 7011 if (varKeyword != null) {
7012 reportError13(ParserErrorCode.FINAL_AND_VAR, varKeyword, []); 7012 reportError14(ParserErrorCode.FINAL_AND_VAR, varKeyword, []);
7013 } 7013 }
7014 if (staticKeyword != null && finalKeyword.offset < staticKeyword.offset) { 7014 if (staticKeyword != null && finalKeyword.offset < staticKeyword.offset) {
7015 reportError13(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword, []); 7015 reportError14(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword, []);
7016 } 7016 }
7017 } else if (varKeyword != null && staticKeyword != null && varKeyword.offset < staticKeyword.offset) { 7017 } else if (varKeyword != null && staticKeyword != null && varKeyword.offset < staticKeyword.offset) {
7018 reportError13(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword, []); 7018 reportError14(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword, []);
7019 } 7019 }
7020 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]); 7020 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]);
7021 } 7021 }
7022 7022
7023 /** 7023 /**
7024 * Validate that the given set of modifiers is appropriate for a local functio n. 7024 * Validate that the given set of modifiers is appropriate for a local functio n.
7025 * 7025 *
7026 * @param modifiers the modifiers being validated 7026 * @param modifiers the modifiers being validated
7027 */ 7027 */
7028 void validateModifiersForFunctionDeclarationStatement(Modifiers modifiers) { 7028 void validateModifiersForFunctionDeclarationStatement(Modifiers modifiers) {
7029 if (modifiers.abstractKeyword != null || modifiers.constKeyword != null || m odifiers.externalKeyword != null || modifiers.factoryKeyword != null || modifier s.finalKeyword != null || modifiers.staticKeyword != null || modifiers.varKeywor d != null) { 7029 if (modifiers.abstractKeyword != null || modifiers.constKeyword != null || m odifiers.externalKeyword != null || modifiers.factoryKeyword != null || modifier s.finalKeyword != null || modifiers.staticKeyword != null || modifiers.varKeywor d != null) {
7030 reportError12(ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER, []); 7030 reportError13(ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER, []);
7031 } 7031 }
7032 } 7032 }
7033 7033
7034 /** 7034 /**
7035 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method. 7035 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method.
7036 * 7036 *
7037 * @param modifiers the modifiers being validated 7037 * @param modifiers the modifiers being validated
7038 */ 7038 */
7039 void validateModifiersForGetterOrSetterOrMethod(Modifiers modifiers) { 7039 void validateModifiersForGetterOrSetterOrMethod(Modifiers modifiers) {
7040 if (modifiers.abstractKeyword != null) { 7040 if (modifiers.abstractKeyword != null) {
7041 reportError12(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 7041 reportError13(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []);
7042 } 7042 }
7043 if (modifiers.constKeyword != null) { 7043 if (modifiers.constKeyword != null) {
7044 reportError13(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); 7044 reportError14(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []);
7045 } 7045 }
7046 if (modifiers.factoryKeyword != null) { 7046 if (modifiers.factoryKeyword != null) {
7047 reportError13(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []); 7047 reportError14(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []);
7048 } 7048 }
7049 if (modifiers.finalKeyword != null) { 7049 if (modifiers.finalKeyword != null) {
7050 reportError13(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); 7050 reportError14(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []);
7051 } 7051 }
7052 if (modifiers.varKeyword != null) { 7052 if (modifiers.varKeyword != null) {
7053 reportError13(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); 7053 reportError14(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []);
7054 } 7054 }
7055 Token externalKeyword = modifiers.externalKeyword; 7055 Token externalKeyword = modifiers.externalKeyword;
7056 Token staticKeyword = modifiers.staticKeyword; 7056 Token staticKeyword = modifiers.staticKeyword;
7057 if (externalKeyword != null && staticKeyword != null && staticKeyword.offset < externalKeyword.offset) { 7057 if (externalKeyword != null && staticKeyword != null && staticKeyword.offset < externalKeyword.offset) {
7058 reportError13(ParserErrorCode.EXTERNAL_AFTER_STATIC, externalKeyword, []); 7058 reportError14(ParserErrorCode.EXTERNAL_AFTER_STATIC, externalKeyword, []);
7059 } 7059 }
7060 } 7060 }
7061 7061
7062 /** 7062 /**
7063 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method. 7063 * Validate that the given set of modifiers is appropriate for a getter, sette r, or method.
7064 * 7064 *
7065 * @param modifiers the modifiers being validated 7065 * @param modifiers the modifiers being validated
7066 */ 7066 */
7067 void validateModifiersForOperator(Modifiers modifiers) { 7067 void validateModifiersForOperator(Modifiers modifiers) {
7068 if (modifiers.abstractKeyword != null) { 7068 if (modifiers.abstractKeyword != null) {
7069 reportError12(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 7069 reportError13(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []);
7070 } 7070 }
7071 if (modifiers.constKeyword != null) { 7071 if (modifiers.constKeyword != null) {
7072 reportError13(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); 7072 reportError14(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []);
7073 } 7073 }
7074 if (modifiers.factoryKeyword != null) { 7074 if (modifiers.factoryKeyword != null) {
7075 reportError13(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []); 7075 reportError14(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []);
7076 } 7076 }
7077 if (modifiers.finalKeyword != null) { 7077 if (modifiers.finalKeyword != null) {
7078 reportError13(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); 7078 reportError14(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []);
7079 } 7079 }
7080 if (modifiers.staticKeyword != null) { 7080 if (modifiers.staticKeyword != null) {
7081 reportError13(ParserErrorCode.STATIC_OPERATOR, modifiers.staticKeyword, [] ); 7081 reportError14(ParserErrorCode.STATIC_OPERATOR, modifiers.staticKeyword, [] );
7082 } 7082 }
7083 if (modifiers.varKeyword != null) { 7083 if (modifiers.varKeyword != null) {
7084 reportError13(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); 7084 reportError14(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []);
7085 } 7085 }
7086 } 7086 }
7087 7087
7088 /** 7088 /**
7089 * Validate that the given set of modifiers is appropriate for a top-level dec laration. 7089 * Validate that the given set of modifiers is appropriate for a top-level dec laration.
7090 * 7090 *
7091 * @param modifiers the modifiers being validated 7091 * @param modifiers the modifiers being validated
7092 */ 7092 */
7093 void validateModifiersForTopLevelDeclaration(Modifiers modifiers) { 7093 void validateModifiersForTopLevelDeclaration(Modifiers modifiers) {
7094 if (modifiers.factoryKeyword != null) { 7094 if (modifiers.factoryKeyword != null) {
7095 reportError13(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION, modifiers.fac toryKeyword, []); 7095 reportError14(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION, modifiers.fac toryKeyword, []);
7096 } 7096 }
7097 if (modifiers.staticKeyword != null) { 7097 if (modifiers.staticKeyword != null) {
7098 reportError13(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION, modifiers.stat icKeyword, []); 7098 reportError14(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION, modifiers.stat icKeyword, []);
7099 } 7099 }
7100 } 7100 }
7101 7101
7102 /** 7102 /**
7103 * Validate that the given set of modifiers is appropriate for a top-level fun ction. 7103 * Validate that the given set of modifiers is appropriate for a top-level fun ction.
7104 * 7104 *
7105 * @param modifiers the modifiers being validated 7105 * @param modifiers the modifiers being validated
7106 */ 7106 */
7107 void validateModifiersForTopLevelFunction(Modifiers modifiers) { 7107 void validateModifiersForTopLevelFunction(Modifiers modifiers) {
7108 validateModifiersForTopLevelDeclaration(modifiers); 7108 validateModifiersForTopLevelDeclaration(modifiers);
7109 if (modifiers.abstractKeyword != null) { 7109 if (modifiers.abstractKeyword != null) {
7110 reportError12(ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION, []); 7110 reportError13(ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION, []);
7111 } 7111 }
7112 if (modifiers.constKeyword != null) { 7112 if (modifiers.constKeyword != null) {
7113 reportError13(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); 7113 reportError14(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []);
7114 } 7114 }
7115 if (modifiers.finalKeyword != null) { 7115 if (modifiers.finalKeyword != null) {
7116 reportError13(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); 7116 reportError14(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []);
7117 } 7117 }
7118 if (modifiers.varKeyword != null) { 7118 if (modifiers.varKeyword != null) {
7119 reportError13(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); 7119 reportError14(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []);
7120 } 7120 }
7121 } 7121 }
7122 7122
7123 /** 7123 /**
7124 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final', 7124 * Validate that the given set of modifiers is appropriate for a field and ret urn the 'final',
7125 * 'const' or 'var' keyword if there is one. 7125 * 'const' or 'var' keyword if there is one.
7126 * 7126 *
7127 * @param modifiers the modifiers being validated 7127 * @param modifiers the modifiers being validated
7128 * @return the 'final', 'const' or 'var' keyword associated with the field 7128 * @return the 'final', 'const' or 'var' keyword associated with the field
7129 */ 7129 */
7130 Token validateModifiersForTopLevelVariable(Modifiers modifiers) { 7130 Token validateModifiersForTopLevelVariable(Modifiers modifiers) {
7131 validateModifiersForTopLevelDeclaration(modifiers); 7131 validateModifiersForTopLevelDeclaration(modifiers);
7132 if (modifiers.abstractKeyword != null) { 7132 if (modifiers.abstractKeyword != null) {
7133 reportError12(ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE, []); 7133 reportError13(ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE, []);
7134 } 7134 }
7135 if (modifiers.externalKeyword != null) { 7135 if (modifiers.externalKeyword != null) {
7136 reportError13(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, [ ]); 7136 reportError14(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, [ ]);
7137 } 7137 }
7138 Token constKeyword = modifiers.constKeyword; 7138 Token constKeyword = modifiers.constKeyword;
7139 Token finalKeyword = modifiers.finalKeyword; 7139 Token finalKeyword = modifiers.finalKeyword;
7140 Token varKeyword = modifiers.varKeyword; 7140 Token varKeyword = modifiers.varKeyword;
7141 if (constKeyword != null) { 7141 if (constKeyword != null) {
7142 if (finalKeyword != null) { 7142 if (finalKeyword != null) {
7143 reportError13(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []); 7143 reportError14(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []);
7144 } 7144 }
7145 if (varKeyword != null) { 7145 if (varKeyword != null) {
7146 reportError13(ParserErrorCode.CONST_AND_VAR, varKeyword, []); 7146 reportError14(ParserErrorCode.CONST_AND_VAR, varKeyword, []);
7147 } 7147 }
7148 } else if (finalKeyword != null) { 7148 } else if (finalKeyword != null) {
7149 if (varKeyword != null) { 7149 if (varKeyword != null) {
7150 reportError13(ParserErrorCode.FINAL_AND_VAR, varKeyword, []); 7150 reportError14(ParserErrorCode.FINAL_AND_VAR, varKeyword, []);
7151 } 7151 }
7152 } 7152 }
7153 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]); 7153 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]);
7154 } 7154 }
7155 7155
7156 /** 7156 /**
7157 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract' 7157 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract'
7158 * keyword if there is one. 7158 * keyword if there is one.
7159 * 7159 *
7160 * @param modifiers the modifiers being validated 7160 * @param modifiers the modifiers being validated
7161 */ 7161 */
7162 void validateModifiersForTypedef(Modifiers modifiers) { 7162 void validateModifiersForTypedef(Modifiers modifiers) {
7163 validateModifiersForTopLevelDeclaration(modifiers); 7163 validateModifiersForTopLevelDeclaration(modifiers);
7164 if (modifiers.abstractKeyword != null) { 7164 if (modifiers.abstractKeyword != null) {
7165 reportError13(ParserErrorCode.ABSTRACT_TYPEDEF, modifiers.abstractKeyword, []); 7165 reportError14(ParserErrorCode.ABSTRACT_TYPEDEF, modifiers.abstractKeyword, []);
7166 } 7166 }
7167 if (modifiers.constKeyword != null) { 7167 if (modifiers.constKeyword != null) {
7168 reportError13(ParserErrorCode.CONST_TYPEDEF, modifiers.constKeyword, []); 7168 reportError14(ParserErrorCode.CONST_TYPEDEF, modifiers.constKeyword, []);
7169 } 7169 }
7170 if (modifiers.externalKeyword != null) { 7170 if (modifiers.externalKeyword != null) {
7171 reportError13(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalKeyword, []); 7171 reportError14(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalKeyword, []);
7172 } 7172 }
7173 if (modifiers.finalKeyword != null) { 7173 if (modifiers.finalKeyword != null) {
7174 reportError13(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword, []); 7174 reportError14(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword, []);
7175 } 7175 }
7176 if (modifiers.varKeyword != null) { 7176 if (modifiers.varKeyword != null) {
7177 reportError13(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword, []); 7177 reportError14(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword, []);
7178 } 7178 }
7179 } 7179 }
7180 } 7180 }
7181 7181
7182 /** 7182 /**
7183 * Instances of the class `SyntheticKeywordToken` implement a synthetic keyword token. 7183 * Instances of the class `SyntheticKeywordToken` implement a synthetic keyword token.
7184 */ 7184 */
7185 class Parser_SyntheticKeywordToken extends KeywordToken { 7185 class Parser_SyntheticKeywordToken extends KeywordToken {
7186 /** 7186 /**
7187 * Initialize a newly created token to represent the given keyword. 7187 * Initialize a newly created token to represent the given keyword.
(...skipping 2411 matching lines...) Expand 10 before | Expand all | Expand 10 after
9599 if ("\n" == separator) { 9599 if ("\n" == separator) {
9600 _writer.print("\n"); 9600 _writer.print("\n");
9601 indent(); 9601 indent();
9602 } else if (i > 0) { 9602 } else if (i > 0) {
9603 _writer.print(separator); 9603 _writer.print(separator);
9604 } 9604 }
9605 _writer.print(tokens[i].lexeme); 9605 _writer.print(tokens[i].lexeme);
9606 } 9606 }
9607 } 9607 }
9608 } 9608 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698