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

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

Issue 137143010: 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';
11 import 'java_core.dart'; 11 import 'java_core.dart';
12 import 'java_engine.dart';
12 import 'instrumentation.dart'; 13 import 'instrumentation.dart';
13 import 'error.dart'; 14 import 'error.dart';
14 import 'source.dart'; 15 import 'source.dart';
15 import 'scanner.dart'; 16 import 'scanner.dart';
16 import 'ast.dart'; 17 import 'ast.dart';
17 import 'utilities_dart.dart'; 18 import 'utilities_dart.dart';
18 import 'engine.dart' show AnalysisEngine; 19 import 'engine.dart' show AnalysisEngine;
19 import 'utilities_collection.dart' show TokenMap; 20 import 'utilities_collection.dart' show TokenMap;
20 21
21 /** 22 /**
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 if (identical(_oldNode, node.expression)) { 211 if (identical(_oldNode, node.expression)) {
211 return _parser.parseBitwiseOrExpression(); 212 return _parser.parseBitwiseOrExpression();
212 } else if (identical(_oldNode, node.type)) { 213 } else if (identical(_oldNode, node.type)) {
213 return _parser.parseTypeName(); 214 return _parser.parseTypeName();
214 } 215 }
215 return notAChild(node); 216 return notAChild(node);
216 } 217 }
217 218
218 ASTNode visitAssertStatement(AssertStatement node) { 219 ASTNode visitAssertStatement(AssertStatement node) {
219 if (identical(_oldNode, node.condition)) { 220 if (identical(_oldNode, node.condition)) {
220 return _parser.parseExpression3(); 221 return _parser.parseExpression4();
221 } 222 }
222 return notAChild(node); 223 return notAChild(node);
223 } 224 }
224 225
225 ASTNode visitAssignmentExpression(AssignmentExpression node) { 226 ASTNode visitAssignmentExpression(AssignmentExpression node) {
226 if (identical(_oldNode, node.leftHandSide)) { 227 if (identical(_oldNode, node.leftHandSide)) {
227 // 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
228 // 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
229 // need to ensure that the resulting expression is assignable. 230 // need to ensure that the resulting expression is assignable.
230 // return parser.parseConditionalExpression(); 231 // return parser.parseConditionalExpression();
231 throw new InsufficientContextException(); 232 throw new InsufficientContextException();
232 } else if (identical(_oldNode, node.rightHandSide)) { 233 } else if (identical(_oldNode, node.rightHandSide)) {
233 if (isCascadeAllowed(node)) { 234 if (isCascadeAllowed(node)) {
234 return _parser.parseExpression3(); 235 return _parser.parseExpression4();
235 } 236 }
236 return _parser.parseExpressionWithoutCascade(); 237 return _parser.parseExpressionWithoutCascade();
237 } 238 }
238 return notAChild(node); 239 return notAChild(node);
239 } 240 }
240 241
241 ASTNode visitBinaryExpression(BinaryExpression node) { 242 ASTNode visitBinaryExpression(BinaryExpression node) {
242 if (identical(_oldNode, node.leftOperand)) { 243 if (identical(_oldNode, node.leftOperand)) {
243 throw new InsufficientContextException(); 244 throw new InsufficientContextException();
244 } 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
414 } else if (identical(_oldNode, node.identifier)) { 415 } else if (identical(_oldNode, node.identifier)) {
415 return _parser.parseSimpleIdentifier(); 416 return _parser.parseSimpleIdentifier();
416 } 417 }
417 return notAChild(node); 418 return notAChild(node);
418 } 419 }
419 420
420 ASTNode visitDefaultFormalParameter(DefaultFormalParameter node) { 421 ASTNode visitDefaultFormalParameter(DefaultFormalParameter node) {
421 if (identical(_oldNode, node.parameter)) { 422 if (identical(_oldNode, node.parameter)) {
422 return _parser.parseNormalFormalParameter(); 423 return _parser.parseNormalFormalParameter();
423 } else if (identical(_oldNode, node.defaultValue)) { 424 } else if (identical(_oldNode, node.defaultValue)) {
424 return _parser.parseExpression3(); 425 return _parser.parseExpression4();
425 } 426 }
426 return notAChild(node); 427 return notAChild(node);
427 } 428 }
428 429
429 ASTNode visitDoStatement(DoStatement node) { 430 ASTNode visitDoStatement(DoStatement node) {
430 if (identical(_oldNode, node.body)) { 431 if (identical(_oldNode, node.body)) {
431 return _parser.parseStatement2(); 432 return _parser.parseStatement2();
432 } else if (identical(_oldNode, node.condition)) { 433 } else if (identical(_oldNode, node.condition)) {
433 return _parser.parseExpression3(); 434 return _parser.parseExpression4();
434 } 435 }
435 return notAChild(node); 436 return notAChild(node);
436 } 437 }
437 438
438 ASTNode visitDoubleLiteral(DoubleLiteral node) => notAChild(node); 439 ASTNode visitDoubleLiteral(DoubleLiteral node) => notAChild(node);
439 440
440 ASTNode visitEmptyFunctionBody(EmptyFunctionBody node) => notAChild(node); 441 ASTNode visitEmptyFunctionBody(EmptyFunctionBody node) => notAChild(node);
441 442
442 ASTNode visitEmptyStatement(EmptyStatement node) => notAChild(node); 443 ASTNode visitEmptyStatement(EmptyStatement node) => notAChild(node);
443 444
444 ASTNode visitExportDirective(ExportDirective node) { 445 ASTNode visitExportDirective(ExportDirective node) {
445 if (identical(_oldNode, node.documentationComment)) { 446 if (identical(_oldNode, node.documentationComment)) {
446 throw new InsufficientContextException(); 447 throw new InsufficientContextException();
447 } else if (node.metadata.contains(_oldNode)) { 448 } else if (node.metadata.contains(_oldNode)) {
448 return _parser.parseAnnotation(); 449 return _parser.parseAnnotation();
449 } else if (identical(_oldNode, node.uri)) { 450 } else if (identical(_oldNode, node.uri)) {
450 return _parser.parseStringLiteral(); 451 return _parser.parseStringLiteral();
451 } else if (node.combinators.contains(_oldNode)) { 452 } else if (node.combinators.contains(_oldNode)) {
452 throw new IncrementalParseException(); 453 throw new IncrementalParseException();
453 } 454 }
454 return notAChild(node); 455 return notAChild(node);
455 } 456 }
456 457
457 ASTNode visitExpressionFunctionBody(ExpressionFunctionBody node) { 458 ASTNode visitExpressionFunctionBody(ExpressionFunctionBody node) {
458 if (identical(_oldNode, node.expression)) { 459 if (identical(_oldNode, node.expression)) {
459 return _parser.parseExpression3(); 460 return _parser.parseExpression4();
460 } 461 }
461 return notAChild(node); 462 return notAChild(node);
462 } 463 }
463 464
464 ASTNode visitExpressionStatement(ExpressionStatement node) { 465 ASTNode visitExpressionStatement(ExpressionStatement node) {
465 if (identical(_oldNode, node.expression)) { 466 if (identical(_oldNode, node.expression)) {
466 return _parser.parseExpression3(); 467 return _parser.parseExpression4();
467 } 468 }
468 return notAChild(node); 469 return notAChild(node);
469 } 470 }
470 471
471 ASTNode visitExtendsClause(ExtendsClause node) { 472 ASTNode visitExtendsClause(ExtendsClause node) {
472 if (identical(_oldNode, node.superclass)) { 473 if (identical(_oldNode, node.superclass)) {
473 return _parser.parseTypeName(); 474 return _parser.parseTypeName();
474 } 475 }
475 return notAChild(node); 476 return notAChild(node);
476 } 477 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // We don't know which kind of parameter to parse. 517 // We don't know which kind of parameter to parse.
517 throw new InsufficientContextException(); 518 throw new InsufficientContextException();
518 } 519 }
519 520
520 ASTNode visitForStatement(ForStatement node) { 521 ASTNode visitForStatement(ForStatement node) {
521 if (identical(_oldNode, node.variables)) { 522 if (identical(_oldNode, node.variables)) {
522 throw new InsufficientContextException(); 523 throw new InsufficientContextException();
523 } else if (identical(_oldNode, node.initialization)) { 524 } else if (identical(_oldNode, node.initialization)) {
524 throw new InsufficientContextException(); 525 throw new InsufficientContextException();
525 } else if (identical(_oldNode, node.condition)) { 526 } else if (identical(_oldNode, node.condition)) {
526 return _parser.parseExpression3(); 527 return _parser.parseExpression4();
527 } else if (node.updaters.contains(_oldNode)) { 528 } else if (node.updaters.contains(_oldNode)) {
528 return _parser.parseExpression3(); 529 return _parser.parseExpression4();
529 } else if (identical(_oldNode, node.body)) { 530 } else if (identical(_oldNode, node.body)) {
530 return _parser.parseStatement2(); 531 return _parser.parseStatement2();
531 } 532 }
532 return notAChild(node); 533 return notAChild(node);
533 } 534 }
534 535
535 ASTNode visitFunctionDeclaration(FunctionDeclaration node) { 536 ASTNode visitFunctionDeclaration(FunctionDeclaration node) {
536 if (identical(_oldNode, node.documentationComment)) { 537 if (identical(_oldNode, node.documentationComment)) {
537 throw new InsufficientContextException(); 538 throw new InsufficientContextException();
538 } 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
606 607
607 ASTNode visitHideCombinator(HideCombinator node) { 608 ASTNode visitHideCombinator(HideCombinator node) {
608 if (node.hiddenNames.contains(_oldNode)) { 609 if (node.hiddenNames.contains(_oldNode)) {
609 return _parser.parseSimpleIdentifier(); 610 return _parser.parseSimpleIdentifier();
610 } 611 }
611 return notAChild(node); 612 return notAChild(node);
612 } 613 }
613 614
614 ASTNode visitIfStatement(IfStatement node) { 615 ASTNode visitIfStatement(IfStatement node) {
615 if (identical(_oldNode, node.condition)) { 616 if (identical(_oldNode, node.condition)) {
616 return _parser.parseExpression3(); 617 return _parser.parseExpression4();
617 } else if (identical(_oldNode, node.thenStatement)) { 618 } else if (identical(_oldNode, node.thenStatement)) {
618 return _parser.parseStatement2(); 619 return _parser.parseStatement2();
619 } else if (identical(_oldNode, node.elseStatement)) { 620 } else if (identical(_oldNode, node.elseStatement)) {
620 return _parser.parseStatement2(); 621 return _parser.parseStatement2();
621 } 622 }
622 return notAChild(node); 623 return notAChild(node);
623 } 624 }
624 625
625 ASTNode visitImplementsClause(ImplementsClause node) { 626 ASTNode visitImplementsClause(ImplementsClause node) {
626 if (node.interfaces.contains(node)) { 627 if (node.interfaces.contains(node)) {
(...skipping 14 matching lines...) Expand all
641 } else if (node.combinators.contains(_oldNode)) { 642 } else if (node.combinators.contains(_oldNode)) {
642 throw new IncrementalParseException(); 643 throw new IncrementalParseException();
643 } 644 }
644 return notAChild(node); 645 return notAChild(node);
645 } 646 }
646 647
647 ASTNode visitIndexExpression(IndexExpression node) { 648 ASTNode visitIndexExpression(IndexExpression node) {
648 if (identical(_oldNode, node.target)) { 649 if (identical(_oldNode, node.target)) {
649 throw new InsufficientContextException(); 650 throw new InsufficientContextException();
650 } else if (identical(_oldNode, node.index)) { 651 } else if (identical(_oldNode, node.index)) {
651 return _parser.parseExpression3(); 652 return _parser.parseExpression4();
652 } 653 }
653 return notAChild(node); 654 return notAChild(node);
654 } 655 }
655 656
656 ASTNode visitInstanceCreationExpression(InstanceCreationExpression node) { 657 ASTNode visitInstanceCreationExpression(InstanceCreationExpression node) {
657 if (identical(_oldNode, node.constructorName)) { 658 if (identical(_oldNode, node.constructorName)) {
658 return _parser.parseConstructorName(); 659 return _parser.parseConstructorName();
659 } else if (identical(_oldNode, node.argumentList)) { 660 } else if (identical(_oldNode, node.argumentList)) {
660 return _parser.parseArgumentList(); 661 return _parser.parseArgumentList();
661 } 662 }
662 return notAChild(node); 663 return notAChild(node);
663 } 664 }
664 665
665 ASTNode visitIntegerLiteral(IntegerLiteral node) => notAChild(node); 666 ASTNode visitIntegerLiteral(IntegerLiteral node) => notAChild(node);
666 667
667 ASTNode visitInterpolationExpression(InterpolationExpression node) { 668 ASTNode visitInterpolationExpression(InterpolationExpression node) {
668 if (identical(_oldNode, node.expression)) { 669 if (identical(_oldNode, node.expression)) {
669 if (node.leftBracket == null) { 670 if (node.leftBracket == null) {
670 throw new InsufficientContextException(); 671 throw new InsufficientContextException();
671 } 672 }
672 return _parser.parseExpression3(); 673 return _parser.parseExpression4();
673 } 674 }
674 return notAChild(node); 675 return notAChild(node);
675 } 676 }
676 677
677 ASTNode visitInterpolationString(InterpolationString node) { 678 ASTNode visitInterpolationString(InterpolationString node) {
678 throw new InsufficientContextException(); 679 throw new InsufficientContextException();
679 } 680 }
680 681
681 ASTNode visitIsExpression(IsExpression node) { 682 ASTNode visitIsExpression(IsExpression node) {
682 if (identical(_oldNode, node.expression)) { 683 if (identical(_oldNode, node.expression)) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 if (node.components.contains(_oldNode)) { 719 if (node.components.contains(_oldNode)) {
719 return _parser.parseSimpleIdentifier(); 720 return _parser.parseSimpleIdentifier();
720 } 721 }
721 return notAChild(node); 722 return notAChild(node);
722 } 723 }
723 724
724 ASTNode visitListLiteral(ListLiteral node) { 725 ASTNode visitListLiteral(ListLiteral node) {
725 if (identical(_oldNode, node.typeArguments)) { 726 if (identical(_oldNode, node.typeArguments)) {
726 return _parser.parseTypeArgumentList(); 727 return _parser.parseTypeArgumentList();
727 } else if (node.elements.contains(_oldNode)) { 728 } else if (node.elements.contains(_oldNode)) {
728 return _parser.parseExpression3(); 729 return _parser.parseExpression4();
729 } 730 }
730 return notAChild(node); 731 return notAChild(node);
731 } 732 }
732 733
733 ASTNode visitMapLiteral(MapLiteral node) { 734 ASTNode visitMapLiteral(MapLiteral node) {
734 if (identical(_oldNode, node.typeArguments)) { 735 if (identical(_oldNode, node.typeArguments)) {
735 return _parser.parseTypeArgumentList(); 736 return _parser.parseTypeArgumentList();
736 } else if (node.entries.contains(_oldNode)) { 737 } else if (node.entries.contains(_oldNode)) {
737 return _parser.parseMapLiteralEntry(); 738 return _parser.parseMapLiteralEntry();
738 } 739 }
739 return notAChild(node); 740 return notAChild(node);
740 } 741 }
741 742
742 ASTNode visitMapLiteralEntry(MapLiteralEntry node) { 743 ASTNode visitMapLiteralEntry(MapLiteralEntry node) {
743 if (identical(_oldNode, node.key)) { 744 if (identical(_oldNode, node.key)) {
744 return _parser.parseExpression3(); 745 return _parser.parseExpression4();
745 } else if (identical(_oldNode, node.value)) { 746 } else if (identical(_oldNode, node.value)) {
746 return _parser.parseExpression3(); 747 return _parser.parseExpression4();
747 } 748 }
748 return notAChild(node); 749 return notAChild(node);
749 } 750 }
750 751
751 ASTNode visitMethodDeclaration(MethodDeclaration node) { 752 ASTNode visitMethodDeclaration(MethodDeclaration node) {
752 if (identical(_oldNode, node.documentationComment)) { 753 if (identical(_oldNode, node.documentationComment)) {
753 throw new InsufficientContextException(); 754 throw new InsufficientContextException();
754 } else if (node.metadata.contains(_oldNode)) { 755 } else if (node.metadata.contains(_oldNode)) {
755 return _parser.parseAnnotation(); 756 return _parser.parseAnnotation();
756 } else if (identical(_oldNode, node.returnType)) { 757 } else if (identical(_oldNode, node.returnType)) {
(...skipping 18 matching lines...) Expand all
775 } else if (identical(_oldNode, node.argumentList)) { 776 } else if (identical(_oldNode, node.argumentList)) {
776 return _parser.parseArgumentList(); 777 return _parser.parseArgumentList();
777 } 778 }
778 return notAChild(node); 779 return notAChild(node);
779 } 780 }
780 781
781 ASTNode visitNamedExpression(NamedExpression node) { 782 ASTNode visitNamedExpression(NamedExpression node) {
782 if (identical(_oldNode, node.name)) { 783 if (identical(_oldNode, node.name)) {
783 return _parser.parseLabel(); 784 return _parser.parseLabel();
784 } else if (identical(_oldNode, node.expression)) { 785 } else if (identical(_oldNode, node.expression)) {
785 return _parser.parseExpression3(); 786 return _parser.parseExpression4();
786 } 787 }
787 return notAChild(node); 788 return notAChild(node);
788 } 789 }
789 790
790 ASTNode visitNativeClause(NativeClause node) { 791 ASTNode visitNativeClause(NativeClause node) {
791 if (identical(_oldNode, node.name)) { 792 if (identical(_oldNode, node.name)) {
792 return _parser.parseStringLiteral(); 793 return _parser.parseStringLiteral();
793 } 794 }
794 return notAChild(node); 795 return notAChild(node);
795 } 796 }
796 797
797 ASTNode visitNativeFunctionBody(NativeFunctionBody node) { 798 ASTNode visitNativeFunctionBody(NativeFunctionBody node) {
798 if (identical(_oldNode, node.stringLiteral)) { 799 if (identical(_oldNode, node.stringLiteral)) {
799 return _parser.parseStringLiteral(); 800 return _parser.parseStringLiteral();
800 } 801 }
801 return notAChild(node); 802 return notAChild(node);
802 } 803 }
803 804
804 ASTNode visitNullLiteral(NullLiteral node) => notAChild(node); 805 ASTNode visitNullLiteral(NullLiteral node) => notAChild(node);
805 806
806 ASTNode visitParenthesizedExpression(ParenthesizedExpression node) { 807 ASTNode visitParenthesizedExpression(ParenthesizedExpression node) {
807 if (identical(_oldNode, node.expression)) { 808 if (identical(_oldNode, node.expression)) {
808 return _parser.parseExpression3(); 809 return _parser.parseExpression4();
809 } 810 }
810 return notAChild(node); 811 return notAChild(node);
811 } 812 }
812 813
813 ASTNode visitPartDirective(PartDirective node) { 814 ASTNode visitPartDirective(PartDirective node) {
814 if (identical(_oldNode, node.documentationComment)) { 815 if (identical(_oldNode, node.documentationComment)) {
815 throw new InsufficientContextException(); 816 throw new InsufficientContextException();
816 } else if (node.metadata.contains(_oldNode)) { 817 } else if (node.metadata.contains(_oldNode)) {
817 return _parser.parseAnnotation(); 818 return _parser.parseAnnotation();
818 } 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
870 } else if (identical(_oldNode, node.argumentList)) { 871 } else if (identical(_oldNode, node.argumentList)) {
871 return _parser.parseArgumentList(); 872 return _parser.parseArgumentList();
872 } 873 }
873 return notAChild(node); 874 return notAChild(node);
874 } 875 }
875 876
876 ASTNode visitRethrowExpression(RethrowExpression node) => notAChild(node); 877 ASTNode visitRethrowExpression(RethrowExpression node) => notAChild(node);
877 878
878 ASTNode visitReturnStatement(ReturnStatement node) { 879 ASTNode visitReturnStatement(ReturnStatement node) {
879 if (identical(_oldNode, node.expression)) { 880 if (identical(_oldNode, node.expression)) {
880 return _parser.parseExpression3(); 881 return _parser.parseExpression4();
881 } 882 }
882 return notAChild(node); 883 return notAChild(node);
883 } 884 }
884 885
885 ASTNode visitScriptTag(ScriptTag node) => notAChild(node); 886 ASTNode visitScriptTag(ScriptTag node) => notAChild(node);
886 887
887 ASTNode visitShowCombinator(ShowCombinator node) { 888 ASTNode visitShowCombinator(ShowCombinator node) {
888 if (node.shownNames.contains(_oldNode)) { 889 if (node.shownNames.contains(_oldNode)) {
889 return _parser.parseSimpleIdentifier(); 890 return _parser.parseSimpleIdentifier();
890 } 891 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 } 924 }
924 return notAChild(node); 925 return notAChild(node);
925 } 926 }
926 927
927 ASTNode visitSuperExpression(SuperExpression node) => notAChild(node); 928 ASTNode visitSuperExpression(SuperExpression node) => notAChild(node);
928 929
929 ASTNode visitSwitchCase(SwitchCase node) { 930 ASTNode visitSwitchCase(SwitchCase node) {
930 if (node.labels.contains(_oldNode)) { 931 if (node.labels.contains(_oldNode)) {
931 return _parser.parseLabel(); 932 return _parser.parseLabel();
932 } else if (identical(_oldNode, node.expression)) { 933 } else if (identical(_oldNode, node.expression)) {
933 return _parser.parseExpression3(); 934 return _parser.parseExpression4();
934 } else if (node.statements.contains(_oldNode)) { 935 } else if (node.statements.contains(_oldNode)) {
935 return _parser.parseStatement2(); 936 return _parser.parseStatement2();
936 } 937 }
937 return notAChild(node); 938 return notAChild(node);
938 } 939 }
939 940
940 ASTNode visitSwitchDefault(SwitchDefault node) { 941 ASTNode visitSwitchDefault(SwitchDefault node) {
941 if (node.labels.contains(_oldNode)) { 942 if (node.labels.contains(_oldNode)) {
942 return _parser.parseLabel(); 943 return _parser.parseLabel();
943 } else if (node.statements.contains(_oldNode)) { 944 } else if (node.statements.contains(_oldNode)) {
944 return _parser.parseStatement2(); 945 return _parser.parseStatement2();
945 } 946 }
946 return notAChild(node); 947 return notAChild(node);
947 } 948 }
948 949
949 ASTNode visitSwitchStatement(SwitchStatement node) { 950 ASTNode visitSwitchStatement(SwitchStatement node) {
950 if (identical(_oldNode, node.expression)) { 951 if (identical(_oldNode, node.expression)) {
951 return _parser.parseExpression3(); 952 return _parser.parseExpression4();
952 } else if (node.members.contains(_oldNode)) { 953 } else if (node.members.contains(_oldNode)) {
953 throw new InsufficientContextException(); 954 throw new InsufficientContextException();
954 } 955 }
955 return notAChild(node); 956 return notAChild(node);
956 } 957 }
957 958
958 ASTNode visitSymbolLiteral(SymbolLiteral node) => notAChild(node); 959 ASTNode visitSymbolLiteral(SymbolLiteral node) => notAChild(node);
959 960
960 ASTNode visitThisExpression(ThisExpression node) => notAChild(node); 961 ASTNode visitThisExpression(ThisExpression node) => notAChild(node);
961 962
962 ASTNode visitThrowExpression(ThrowExpression node) { 963 ASTNode visitThrowExpression(ThrowExpression node) {
963 if (identical(_oldNode, node.expression)) { 964 if (identical(_oldNode, node.expression)) {
964 if (isCascadeAllowed2(node)) { 965 if (isCascadeAllowed2(node)) {
965 return _parser.parseExpression3(); 966 return _parser.parseExpression4();
966 } 967 }
967 return _parser.parseExpressionWithoutCascade(); 968 return _parser.parseExpressionWithoutCascade();
968 } 969 }
969 return notAChild(node); 970 return notAChild(node);
970 } 971 }
971 972
972 ASTNode visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 973 ASTNode visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
973 if (identical(_oldNode, node.documentationComment)) { 974 if (identical(_oldNode, node.documentationComment)) {
974 throw new InsufficientContextException(); 975 throw new InsufficientContextException();
975 } 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
1053 1054
1054 ASTNode visitVariableDeclarationStatement(VariableDeclarationStatement node) { 1055 ASTNode visitVariableDeclarationStatement(VariableDeclarationStatement node) {
1055 if (identical(_oldNode, node.variables)) { 1056 if (identical(_oldNode, node.variables)) {
1056 throw new InsufficientContextException(); 1057 throw new InsufficientContextException();
1057 } 1058 }
1058 return notAChild(node); 1059 return notAChild(node);
1059 } 1060 }
1060 1061
1061 ASTNode visitWhileStatement(WhileStatement node) { 1062 ASTNode visitWhileStatement(WhileStatement node) {
1062 if (identical(_oldNode, node.condition)) { 1063 if (identical(_oldNode, node.condition)) {
1063 return _parser.parseExpression3(); 1064 return _parser.parseExpression4();
1064 } else if (identical(_oldNode, node.body)) { 1065 } else if (identical(_oldNode, node.body)) {
1065 return _parser.parseStatement2(); 1066 return _parser.parseStatement2();
1066 } 1067 }
1067 return notAChild(node); 1068 return notAChild(node);
1068 } 1069 }
1069 1070
1070 ASTNode visitWithClause(WithClause node) { 1071 ASTNode visitWithClause(WithClause node) {
1071 if (node.mixinTypes.contains(node)) { 1072 if (node.mixinTypes.contains(node)) {
1072 return _parser.parseTypeName(); 1073 return _parser.parseTypeName();
1073 } 1074 }
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 * Parse an expression, starting with the given token. 1408 * Parse an expression, starting with the given token.
1408 * 1409 *
1409 * @param token the first token of the expression 1410 * @param token the first token of the expression
1410 * @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
1411 * recognizable expression 1412 * recognizable expression
1412 */ 1413 */
1413 Expression parseExpression(Token token) { 1414 Expression parseExpression(Token token) {
1414 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.Parser.parseExpression"); 1415 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.Parser.parseExpression");
1415 try { 1416 try {
1416 _currentToken = token; 1417 _currentToken = token;
1417 return parseExpression3(); 1418 return parseExpression4();
1418 } finally { 1419 } finally {
1419 instrumentation.log(); 1420 instrumentation.log();
1420 } 1421 }
1421 } 1422 }
1422 1423
1423 /** 1424 /**
1424 * Parse a statement, starting with the given token. 1425 * Parse a statement, starting with the given token.
1425 * 1426 *
1426 * @param token the first token of the statement 1427 * @param token the first token of the statement
1427 * @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
1502 * </pre> 1503 * </pre>
1503 * 1504 *
1504 * @return the argument that was parsed 1505 * @return the argument that was parsed
1505 */ 1506 */
1506 Expression parseArgument() { 1507 Expression parseArgument() {
1507 // 1508 //
1508 // 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
1509 // have an identifier followed by a colon. 1510 // have an identifier followed by a colon.
1510 // 1511 //
1511 if (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 1512 if (matchesIdentifier() && matches4(peek(), TokenType.COLON)) {
1512 return new NamedExpression(parseLabel(), parseExpression3()); 1513 return new NamedExpression(parseLabel(), parseExpression4());
1513 } else { 1514 } else {
1514 return parseExpression3(); 1515 return parseExpression4();
1515 } 1516 }
1516 } 1517 }
1517 1518
1518 /** 1519 /**
1519 * Parse a list of arguments. 1520 * Parse a list of arguments.
1520 * 1521 *
1521 * <pre> 1522 * <pre>
1522 * arguments ::= 1523 * arguments ::=
1523 * '(' argumentList? ')' 1524 * '(' argumentList? ')'
1524 * 1525 *
(...skipping 17 matching lines...) Expand all
1542 Expression argument = parseArgument(); 1543 Expression argument = parseArgument();
1543 arguments.add(argument); 1544 arguments.add(argument);
1544 bool foundNamedArgument = argument is NamedExpression; 1545 bool foundNamedArgument = argument is NamedExpression;
1545 bool generatedError = false; 1546 bool generatedError = false;
1546 while (optional(TokenType.COMMA)) { 1547 while (optional(TokenType.COMMA)) {
1547 argument = parseArgument(); 1548 argument = parseArgument();
1548 arguments.add(argument); 1549 arguments.add(argument);
1549 if (foundNamedArgument) { 1550 if (foundNamedArgument) {
1550 if (!generatedError && argument is! NamedExpression) { 1551 if (!generatedError && argument is! NamedExpression) {
1551 // 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.
1552 reportError11(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT, []); 1553 reportError12(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT, []);
1553 generatedError = true; 1554 generatedError = true;
1554 } 1555 }
1555 } else if (argument is NamedExpression) { 1556 } else if (argument is NamedExpression) {
1556 foundNamedArgument = true; 1557 foundNamedArgument = true;
1557 } 1558 }
1558 } 1559 }
1559 // 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
1560 // 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
1561 // go back to parsing arguments. 1562 // go back to parsing arguments.
1562 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
1602 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 1603 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET);
1603 List<Statement> statements = new List<Statement>(); 1604 List<Statement> statements = new List<Statement>();
1604 Token statementStart = _currentToken; 1605 Token statementStart = _currentToken;
1605 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET)) { 1606 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET)) {
1606 Statement statement = parseStatement2(); 1607 Statement statement = parseStatement2();
1607 if (statement != null) { 1608 if (statement != null) {
1608 statements.add(statement); 1609 statements.add(statement);
1609 } 1610 }
1610 if (identical(_currentToken, statementStart)) { 1611 if (identical(_currentToken, statementStart)) {
1611 // 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.
1612 reportError12(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 1613 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
1613 advance(); 1614 advance();
1614 } 1615 }
1615 statementStart = _currentToken; 1616 statementStart = _currentToken;
1616 } 1617 }
1617 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 1618 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
1618 return new Block(leftBracket, statements, rightBracket); 1619 return new Block(leftBracket, statements, rightBracket);
1619 } 1620 }
1620 1621
1621 /** 1622 /**
1622 * Parse a class member. 1623 * Parse a class member.
(...skipping 30 matching lines...) Expand all
1653 return parseMethodDeclaration(commentAndMetadata, modifiers.externalKeyw ord, modifiers.staticKeyword, returnType); 1654 return parseMethodDeclaration(commentAndMetadata, modifiers.externalKeyw ord, modifiers.staticKeyword, returnType);
1654 } else { 1655 } else {
1655 // 1656 //
1656 // We have found an error of some kind. Try to recover. 1657 // We have found an error of some kind. Try to recover.
1657 // 1658 //
1658 if (matchesIdentifier()) { 1659 if (matchesIdentifier()) {
1659 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) { 1660 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) {
1660 // 1661 //
1661 // 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".
1662 // 1663 //
1663 reportError10(ParserErrorCode.VOID_VARIABLE, returnType, []); 1664 reportError11(ParserErrorCode.VOID_VARIABLE, returnType, []);
1664 return parseInitializedIdentifierList(commentAndMetadata, modifiers. staticKeyword, validateModifiersForField(modifiers), returnType); 1665 return parseInitializedIdentifierList(commentAndMetadata, modifiers. staticKeyword, validateModifiersForField(modifiers), returnType);
1665 } 1666 }
1666 } 1667 }
1667 if (isOperator(_currentToken)) { 1668 if (isOperator(_currentToken)) {
1668 // 1669 //
1669 // 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.
1670 // 1671 //
1671 validateModifiersForOperator(modifiers); 1672 validateModifiersForOperator(modifiers);
1672 return parseOperator(commentAndMetadata, modifiers.externalKeyword, re turnType); 1673 return parseOperator(commentAndMetadata, modifiers.externalKeyword, re turnType);
1673 } 1674 }
1674 reportError12(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 1675 reportError13(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
1675 return null; 1676 return null;
1676 } 1677 }
1677 } else if (matches(Keyword.GET) && matchesIdentifier2(peek())) { 1678 } else if (matches(Keyword.GET) && matchesIdentifier2(peek())) {
1678 validateModifiersForGetterOrSetterOrMethod(modifiers); 1679 validateModifiersForGetterOrSetterOrMethod(modifiers);
1679 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null); 1680 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null);
1680 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { 1681 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) {
1681 validateModifiersForGetterOrSetterOrMethod(modifiers); 1682 validateModifiersForGetterOrSetterOrMethod(modifiers);
1682 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null); 1683 return parseSetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, null);
1683 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 1684 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) {
1684 validateModifiersForOperator(modifiers); 1685 validateModifiersForOperator(modifiers);
1685 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null); 1686 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null);
1686 } else if (!matchesIdentifier()) { 1687 } else if (!matchesIdentifier()) {
1687 if (isOperator(_currentToken)) { 1688 if (isOperator(_currentToken)) {
1688 // 1689 //
1689 // 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.
1690 // 1691 //
1691 validateModifiersForOperator(modifiers); 1692 validateModifiersForOperator(modifiers);
1692 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null ); 1693 return parseOperator(commentAndMetadata, modifiers.externalKeyword, null );
1693 } 1694 }
1694 reportError12(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); 1695 reportError13(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []);
1695 return null; 1696 return null;
1696 } 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)) {
1697 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());
1698 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { 1699 } else if (matches4(peek(), TokenType.OPEN_PAREN)) {
1699 SimpleIdentifier methodName = parseSimpleIdentifier(); 1700 SimpleIdentifier methodName = parseSimpleIdentifier();
1700 FormalParameterList parameters = parseFormalParameterList(); 1701 FormalParameterList parameters = parseFormalParameterList();
1701 if (matches5(TokenType.COLON) || modifiers.factoryKeyword != null || metho dName.name == className) { 1702 if (matches5(TokenType.COLON) || modifiers.factoryKeyword != null || metho dName.name == className) {
1702 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);
1703 } 1704 }
1704 validateModifiersForGetterOrSetterOrMethod(modifiers); 1705 validateModifiersForGetterOrSetterOrMethod(modifiers);
1705 validateFormalParameterList(parameters); 1706 validateFormalParameterList(parameters);
1706 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo rd, modifiers.staticKeyword, null, methodName, parameters); 1707 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo rd, modifiers.staticKeyword, null, methodName, parameters);
1707 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) { 1708 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) {
1708 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) { 1709 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) {
1709 reportError11(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); 1710 reportError12(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []);
1710 } 1711 }
1711 return parseInitializedIdentifierList(commentAndMetadata, modifiers.static Keyword, validateModifiersForField(modifiers), null); 1712 return parseInitializedIdentifierList(commentAndMetadata, modifiers.static Keyword, validateModifiersForField(modifiers), null);
1712 } 1713 }
1713 TypeName type = parseTypeName(); 1714 TypeName type = parseTypeName();
1714 if (matches(Keyword.GET) && matchesIdentifier2(peek())) { 1715 if (matches(Keyword.GET) && matchesIdentifier2(peek())) {
1715 validateModifiersForGetterOrSetterOrMethod(modifiers); 1716 validateModifiersForGetterOrSetterOrMethod(modifiers);
1716 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, type); 1717 return parseGetter(commentAndMetadata, modifiers.externalKeyword, modifier s.staticKeyword, type);
1717 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) { 1718 } else if (matches(Keyword.SET) && matchesIdentifier2(peek())) {
1718 validateModifiersForGetterOrSetterOrMethod(modifiers); 1719 validateModifiersForGetterOrSetterOrMethod(modifiers);
1719 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
1734 // 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.
1735 // 1736 //
1736 validateModifiersForOperator(modifiers); 1737 validateModifiersForOperator(modifiers);
1737 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type ); 1738 return parseOperator(commentAndMetadata, modifiers.externalKeyword, type );
1738 } 1739 }
1739 // 1740 //
1740 // 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.
1741 // 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
1742 // with a missing field name and semicolon. 1743 // with a missing field name and semicolon.
1743 // 1744 //
1744 reportError12(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []); 1745 reportError13(ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken, []);
1745 try { 1746 try {
1746 lockErrorListener(); 1747 lockErrorListener();
1747 return parseInitializedIdentifierList(commentAndMetadata, modifiers.stat icKeyword, validateModifiersForField(modifiers), type); 1748 return parseInitializedIdentifierList(commentAndMetadata, modifiers.stat icKeyword, validateModifiersForField(modifiers), type);
1748 } finally { 1749 } finally {
1749 unlockErrorListener(); 1750 unlockErrorListener();
1750 } 1751 }
1751 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { 1752 } else if (matches4(peek(), TokenType.OPEN_PAREN)) {
1752 SimpleIdentifier methodName = parseSimpleIdentifier(); 1753 SimpleIdentifier methodName = parseSimpleIdentifier();
1753 FormalParameterList parameters = parseFormalParameterList(); 1754 FormalParameterList parameters = parseFormalParameterList();
1754 if (methodName.name == className) { 1755 if (methodName.name == className) {
1755 reportError10(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type, []); 1756 reportError11(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type, []);
1756 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);
1757 } 1758 }
1758 validateModifiersForGetterOrSetterOrMethod(modifiers); 1759 validateModifiersForGetterOrSetterOrMethod(modifiers);
1759 validateFormalParameterList(parameters); 1760 validateFormalParameterList(parameters);
1760 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo rd, modifiers.staticKeyword, type, methodName, parameters); 1761 return parseMethodDeclaration2(commentAndMetadata, modifiers.externalKeywo rd, modifiers.staticKeyword, type, methodName, parameters);
1761 } 1762 }
1762 return parseInitializedIdentifierList(commentAndMetadata, modifiers.staticKe yword, validateModifiersForField(modifiers), type); 1763 return parseInitializedIdentifierList(commentAndMetadata, modifiers.staticKe yword, validateModifiersForField(modifiers), type);
1763 } 1764 }
1764 1765
1765 /** 1766 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 bool partDirectiveFound = false; 1800 bool partDirectiveFound = false;
1800 bool directiveFoundAfterDeclaration = false; 1801 bool directiveFoundAfterDeclaration = false;
1801 List<Directive> directives = new List<Directive>(); 1802 List<Directive> directives = new List<Directive>();
1802 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ; 1803 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ;
1803 Token memberStart = _currentToken; 1804 Token memberStart = _currentToken;
1804 while (!matches5(TokenType.EOF)) { 1805 while (!matches5(TokenType.EOF)) {
1805 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 1806 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
1806 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)) {
1807 Directive directive = parseDirective(commentAndMetadata); 1808 Directive directive = parseDirective(commentAndMetadata);
1808 if (declarations.length > 0 && !directiveFoundAfterDeclaration) { 1809 if (declarations.length > 0 && !directiveFoundAfterDeclaration) {
1809 reportError11(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, []); 1810 reportError12(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION, []);
1810 directiveFoundAfterDeclaration = true; 1811 directiveFoundAfterDeclaration = true;
1811 } 1812 }
1812 if (directive is LibraryDirective) { 1813 if (directive is LibraryDirective) {
1813 if (libraryDirectiveFound) { 1814 if (libraryDirectiveFound) {
1814 reportError11(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES, []); 1815 reportError12(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES, []);
1815 } else { 1816 } else {
1816 if (directives.length > 0) { 1817 if (directives.length > 0) {
1817 reportError12(ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST, directi ve.libraryToken, []); 1818 reportError13(ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST, directi ve.libraryToken, []);
1818 } 1819 }
1819 libraryDirectiveFound = true; 1820 libraryDirectiveFound = true;
1820 } 1821 }
1821 } else if (directive is PartDirective) { 1822 } else if (directive is PartDirective) {
1822 partDirectiveFound = true; 1823 partDirectiveFound = true;
1823 } else if (partDirectiveFound) { 1824 } else if (partDirectiveFound) {
1824 if (directive is ExportDirective) { 1825 if (directive is ExportDirective) {
1825 reportError12(ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, directive.keyword, []); 1826 reportError13(ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, directive.keyword, []);
1826 } else if (directive is ImportDirective) { 1827 } else if (directive is ImportDirective) {
1827 reportError12(ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, directive.keyword, []); 1828 reportError13(ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE, directive.keyword, []);
1828 } 1829 }
1829 } 1830 }
1830 if (directive is PartOfDirective) { 1831 if (directive is PartOfDirective) {
1831 if (partOfDirectiveFound) { 1832 if (partOfDirectiveFound) {
1832 reportError11(ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES, []); 1833 reportError12(ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES, []);
1833 } else { 1834 } else {
1834 int directiveCount = directives.length; 1835 int directiveCount = directives.length;
1835 for (int i = 0; i < directiveCount; i++) { 1836 for (int i = 0; i < directiveCount; i++) {
1836 reportError12(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, direc tives[i].keyword, []); 1837 reportError13(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, direc tives[i].keyword, []);
1837 } 1838 }
1838 partOfDirectiveFound = true; 1839 partOfDirectiveFound = true;
1839 } 1840 }
1840 } else { 1841 } else {
1841 if (partOfDirectiveFound) { 1842 if (partOfDirectiveFound) {
1842 reportError12(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, directi ve.keyword, []); 1843 reportError13(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, directi ve.keyword, []);
1843 } 1844 }
1844 } 1845 }
1845 directives.add(directive); 1846 directives.add(directive);
1846 } else if (matches5(TokenType.SEMICOLON)) { 1847 } else if (matches5(TokenType.SEMICOLON)) {
1847 reportError12(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 1848 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
1848 advance(); 1849 advance();
1849 } else { 1850 } else {
1850 CompilationUnitMember member = parseCompilationUnitMember(commentAndMeta data); 1851 CompilationUnitMember member = parseCompilationUnitMember(commentAndMeta data);
1851 if (member != null) { 1852 if (member != null) {
1852 declarations.add(member); 1853 declarations.add(member);
1853 } 1854 }
1854 } 1855 }
1855 if (identical(_currentToken, memberStart)) { 1856 if (identical(_currentToken, memberStart)) {
1856 reportError12(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 1857 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
1857 advance(); 1858 advance();
1858 while (!matches5(TokenType.EOF) && !couldBeStartOfCompilationUnitMember( )) { 1859 while (!matches5(TokenType.EOF) && !couldBeStartOfCompilationUnitMember( )) {
1859 advance(); 1860 advance();
1860 } 1861 }
1861 } 1862 }
1862 memberStart = _currentToken; 1863 memberStart = _currentToken;
1863 } 1864 }
1864 return new CompilationUnit(firstToken, scriptTag, directives, declarations, _currentToken); 1865 return new CompilationUnit(firstToken, scriptTag, directives, declarations, _currentToken);
1865 } 1866 }
1866 1867
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 * 1913 *
1913 * <pre> 1914 * <pre>
1914 * expression ::= 1915 * expression ::=
1915 * assignableExpression assignmentOperator expression 1916 * assignableExpression assignmentOperator expression
1916 * | conditionalExpression cascadeSection* 1917 * | conditionalExpression cascadeSection*
1917 * | throwExpression 1918 * | throwExpression
1918 * </pre> 1919 * </pre>
1919 * 1920 *
1920 * @return the expression that was parsed 1921 * @return the expression that was parsed
1921 */ 1922 */
1922 Expression parseExpression3() { 1923 Expression parseExpression4() {
1923 if (matches(Keyword.THROW)) { 1924 if (matches(Keyword.THROW)) {
1924 return parseThrowExpression(); 1925 return parseThrowExpression();
1925 } else if (matches(Keyword.RETHROW)) { 1926 } else if (matches(Keyword.RETHROW)) {
1926 return parseRethrowExpression(); 1927 return parseRethrowExpression();
1927 } 1928 }
1928 // 1929 //
1929 // 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
1930 // 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
1931 // conformance to the restricted grammar after making that determination. 1932 // conformance to the restricted grammar after making that determination.
1932 // 1933 //
1933 Expression expression = parseConditionalExpression(); 1934 Expression expression = parseConditionalExpression();
1934 TokenType tokenType = _currentToken.type; 1935 TokenType tokenType = _currentToken.type;
1935 if (identical(tokenType, TokenType.PERIOD_PERIOD)) { 1936 if (identical(tokenType, TokenType.PERIOD_PERIOD)) {
1936 List<Expression> cascadeSections = new List<Expression>(); 1937 List<Expression> cascadeSections = new List<Expression>();
1937 while (identical(tokenType, TokenType.PERIOD_PERIOD)) { 1938 while (identical(tokenType, TokenType.PERIOD_PERIOD)) {
1938 Expression section = parseCascadeSection(); 1939 Expression section = parseCascadeSection();
1939 if (section != null) { 1940 if (section != null) {
1940 cascadeSections.add(section); 1941 cascadeSections.add(section);
1941 } 1942 }
1942 tokenType = _currentToken.type; 1943 tokenType = _currentToken.type;
1943 } 1944 }
1944 return new CascadeExpression(expression, cascadeSections); 1945 return new CascadeExpression(expression, cascadeSections);
1945 } else if (tokenType.isAssignmentOperator) { 1946 } else if (tokenType.isAssignmentOperator) {
1946 Token operator = andAdvance; 1947 Token operator = andAdvance;
1947 ensureAssignable(expression); 1948 ensureAssignable(expression);
1948 return new AssignmentExpression(expression, operator, parseExpression3()); 1949 return new AssignmentExpression(expression, operator, parseExpression4());
1949 } 1950 }
1950 return expression; 1951 return expression;
1951 } 1952 }
1952 1953
1953 /** 1954 /**
1954 * Parse an expression that does not contain any cascades. 1955 * Parse an expression that does not contain any cascades.
1955 * 1956 *
1956 * <pre> 1957 * <pre>
1957 * expressionWithoutCascade ::= 1958 * expressionWithoutCascade ::=
1958 * assignableExpression assignmentOperator expressionWithoutCascade 1959 * assignableExpression assignmentOperator expressionWithoutCascade
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2048 bool reportedMulipleNamedGroups = false; 2049 bool reportedMulipleNamedGroups = false;
2049 bool reportedMixedGroups = false; 2050 bool reportedMixedGroups = false;
2050 bool wasOptionalParameter = false; 2051 bool wasOptionalParameter = false;
2051 Token initialToken = null; 2052 Token initialToken = null;
2052 do { 2053 do {
2053 if (firstParameter) { 2054 if (firstParameter) {
2054 firstParameter = false; 2055 firstParameter = false;
2055 } else if (!optional(TokenType.COMMA)) { 2056 } else if (!optional(TokenType.COMMA)) {
2056 // 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.
2057 if (getEndToken(leftParenthesis) != null) { 2058 if (getEndToken(leftParenthesis) != null) {
2058 reportError11(ParserErrorCode.EXPECTED_TOKEN, [TokenType.COMMA.lexeme] ); 2059 reportError12(ParserErrorCode.EXPECTED_TOKEN, [TokenType.COMMA.lexeme] );
2059 } else { 2060 } else {
2060 reportError12(ParserErrorCode.MISSING_CLOSING_PARENTHESIS, _currentTok en.previous, []); 2061 reportError13(ParserErrorCode.MISSING_CLOSING_PARENTHESIS, _currentTok en.previous, []);
2061 break; 2062 break;
2062 } 2063 }
2063 } 2064 }
2064 initialToken = _currentToken; 2065 initialToken = _currentToken;
2065 // 2066 //
2066 // Handle the beginning of parameter groups. 2067 // Handle the beginning of parameter groups.
2067 // 2068 //
2068 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { 2069 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) {
2069 wasOptionalParameter = true; 2070 wasOptionalParameter = true;
2070 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) { 2071 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) {
2071 reportError11(ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS, [] ); 2072 reportError12(ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS, [] );
2072 reportedMuliplePositionalGroups = true; 2073 reportedMuliplePositionalGroups = true;
2073 } 2074 }
2074 if (leftCurlyBracket != null && !reportedMixedGroups) { 2075 if (leftCurlyBracket != null && !reportedMixedGroups) {
2075 reportError11(ParserErrorCode.MIXED_PARAMETER_GROUPS, []); 2076 reportError12(ParserErrorCode.MIXED_PARAMETER_GROUPS, []);
2076 reportedMixedGroups = true; 2077 reportedMixedGroups = true;
2077 } 2078 }
2078 leftSquareBracket = andAdvance; 2079 leftSquareBracket = andAdvance;
2079 currentParameters = positionalParameters; 2080 currentParameters = positionalParameters;
2080 kind = ParameterKind.POSITIONAL; 2081 kind = ParameterKind.POSITIONAL;
2081 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 2082 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
2082 wasOptionalParameter = true; 2083 wasOptionalParameter = true;
2083 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) { 2084 if (leftCurlyBracket != null && !reportedMulipleNamedGroups) {
2084 reportError11(ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS, []); 2085 reportError12(ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS, []);
2085 reportedMulipleNamedGroups = true; 2086 reportedMulipleNamedGroups = true;
2086 } 2087 }
2087 if (leftSquareBracket != null && !reportedMixedGroups) { 2088 if (leftSquareBracket != null && !reportedMixedGroups) {
2088 reportError11(ParserErrorCode.MIXED_PARAMETER_GROUPS, []); 2089 reportError12(ParserErrorCode.MIXED_PARAMETER_GROUPS, []);
2089 reportedMixedGroups = true; 2090 reportedMixedGroups = true;
2090 } 2091 }
2091 leftCurlyBracket = andAdvance; 2092 leftCurlyBracket = andAdvance;
2092 currentParameters = namedParameters; 2093 currentParameters = namedParameters;
2093 kind = ParameterKind.NAMED; 2094 kind = ParameterKind.NAMED;
2094 } 2095 }
2095 // 2096 //
2096 // Parse and record the parameter. 2097 // Parse and record the parameter.
2097 // 2098 //
2098 FormalParameter parameter = parseFormalParameter(kind); 2099 FormalParameter parameter = parseFormalParameter(kind);
2099 parameters.add(parameter); 2100 parameters.add(parameter);
2100 currentParameters.add(parameter); 2101 currentParameters.add(parameter);
2101 if (identical(kind, ParameterKind.REQUIRED) && wasOptionalParameter) { 2102 if (identical(kind, ParameterKind.REQUIRED) && wasOptionalParameter) {
2102 reportError10(ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS, paramet er, []); 2103 reportError11(ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS, paramet er, []);
2103 } 2104 }
2104 // 2105 //
2105 // Handle the end of parameter groups. 2106 // Handle the end of parameter groups.
2106 // 2107 //
2107 // 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.
2108 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 2109 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) {
2109 rightSquareBracket = andAdvance; 2110 rightSquareBracket = andAdvance;
2110 currentParameters = normalParameters; 2111 currentParameters = normalParameters;
2111 if (leftSquareBracket == null) { 2112 if (leftSquareBracket == null) {
2112 if (leftCurlyBracket != null) { 2113 if (leftCurlyBracket != null) {
2113 reportError11(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["}"]); 2114 reportError12(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["}"]);
2114 rightCurlyBracket = rightSquareBracket; 2115 rightCurlyBracket = rightSquareBracket;
2115 rightSquareBracket = null; 2116 rightSquareBracket = null;
2116 } else { 2117 } else {
2117 reportError11(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GR OUP, ["["]); 2118 reportError12(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GR OUP, ["["]);
2118 } 2119 }
2119 } 2120 }
2120 kind = ParameterKind.REQUIRED; 2121 kind = ParameterKind.REQUIRED;
2121 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 2122 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
2122 rightCurlyBracket = andAdvance; 2123 rightCurlyBracket = andAdvance;
2123 currentParameters = normalParameters; 2124 currentParameters = normalParameters;
2124 if (leftCurlyBracket == null) { 2125 if (leftCurlyBracket == null) {
2125 if (leftSquareBracket != null) { 2126 if (leftSquareBracket != null) {
2126 reportError11(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["]"]); 2127 reportError12(ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, ["]"]);
2127 rightSquareBracket = rightCurlyBracket; 2128 rightSquareBracket = rightCurlyBracket;
2128 rightCurlyBracket = null; 2129 rightCurlyBracket = null;
2129 } else { 2130 } else {
2130 reportError11(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GR OUP, ["{"]); 2131 reportError12(ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GR OUP, ["{"]);
2131 } 2132 }
2132 } 2133 }
2133 kind = ParameterKind.REQUIRED; 2134 kind = ParameterKind.REQUIRED;
2134 } 2135 }
2135 } while (!matches5(TokenType.CLOSE_PAREN) && initialToken != _currentToken); 2136 } while (!matches5(TokenType.CLOSE_PAREN) && initialToken != _currentToken);
2136 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 2137 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
2137 // 2138 //
2138 // Check that the groups were closed correctly. 2139 // Check that the groups were closed correctly.
2139 // 2140 //
2140 if (leftSquareBracket != null && rightSquareBracket == null) { 2141 if (leftSquareBracket != null && rightSquareBracket == null) {
2141 reportError11(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["]" ]); 2142 reportError12(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["]" ]);
2142 } 2143 }
2143 if (leftCurlyBracket != null && rightCurlyBracket == null) { 2144 if (leftCurlyBracket != null && rightCurlyBracket == null) {
2144 reportError11(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["}" ]); 2145 reportError12(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["}" ]);
2145 } 2146 }
2146 // 2147 //
2147 // Build the parameter list. 2148 // Build the parameter list.
2148 // 2149 //
2149 if (leftSquareBracket == null) { 2150 if (leftSquareBracket == null) {
2150 leftSquareBracket = leftCurlyBracket; 2151 leftSquareBracket = leftCurlyBracket;
2151 } 2152 }
2152 if (rightSquareBracket == null) { 2153 if (rightSquareBracket == null) {
2153 rightSquareBracket = rightCurlyBracket; 2154 rightSquareBracket = rightCurlyBracket;
2154 } 2155 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2251 * Parse a map literal entry. 2252 * Parse a map literal entry.
2252 * 2253 *
2253 * <pre> 2254 * <pre>
2254 * mapLiteralEntry ::= 2255 * mapLiteralEntry ::=
2255 * expression ':' expression 2256 * expression ':' expression
2256 * </pre> 2257 * </pre>
2257 * 2258 *
2258 * @return the map literal entry that was parsed 2259 * @return the map literal entry that was parsed
2259 */ 2260 */
2260 MapLiteralEntry parseMapLiteralEntry() { 2261 MapLiteralEntry parseMapLiteralEntry() {
2261 Expression key = parseExpression3(); 2262 Expression key = parseExpression4();
2262 Token separator = expect2(TokenType.COLON); 2263 Token separator = expect2(TokenType.COLON);
2263 Expression value = parseExpression3(); 2264 Expression value = parseExpression4();
2264 return new MapLiteralEntry(key, separator, value); 2265 return new MapLiteralEntry(key, separator, value);
2265 } 2266 }
2266 2267
2267 /** 2268 /**
2268 * Parse a normal formal parameter. 2269 * Parse a normal formal parameter.
2269 * 2270 *
2270 * <pre> 2271 * <pre>
2271 * normalFormalParameter ::= 2272 * normalFormalParameter ::=
2272 * functionSignature 2273 * functionSignature
2273 * | fieldFormalParameter 2274 * | fieldFormalParameter
(...skipping 19 matching lines...) Expand all
2293 Token period = null; 2294 Token period = null;
2294 if (matches(Keyword.THIS)) { 2295 if (matches(Keyword.THIS)) {
2295 thisKeyword = andAdvance; 2296 thisKeyword = andAdvance;
2296 period = expect2(TokenType.PERIOD); 2297 period = expect2(TokenType.PERIOD);
2297 } 2298 }
2298 SimpleIdentifier identifier = parseSimpleIdentifier(); 2299 SimpleIdentifier identifier = parseSimpleIdentifier();
2299 if (matches5(TokenType.OPEN_PAREN)) { 2300 if (matches5(TokenType.OPEN_PAREN)) {
2300 FormalParameterList parameters = parseFormalParameterList(); 2301 FormalParameterList parameters = parseFormalParameterList();
2301 if (thisKeyword == null) { 2302 if (thisKeyword == null) {
2302 if (holder.keyword != null) { 2303 if (holder.keyword != null) {
2303 reportError12(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.key word, []); 2304 reportError13(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.key word, []);
2304 } 2305 }
2305 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);
2306 } else { 2307 } else {
2307 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);
2308 } 2309 }
2309 } 2310 }
2310 TypeName type = holder.type; 2311 TypeName type = holder.type;
2311 if (type != null) { 2312 if (type != null) {
2312 if (matches3(type.name.beginToken, Keyword.VOID)) { 2313 if (matches3(type.name.beginToken, Keyword.VOID)) {
2313 reportError12(ParserErrorCode.VOID_PARAMETER, type.name.beginToken, []); 2314 reportError13(ParserErrorCode.VOID_PARAMETER, type.name.beginToken, []);
2314 } else if (holder.keyword != null && matches3(holder.keyword, Keyword.VAR) ) { 2315 } else if (holder.keyword != null && matches3(holder.keyword, Keyword.VAR) ) {
2315 reportError12(ParserErrorCode.VAR_AND_TYPE, holder.keyword, []); 2316 reportError13(ParserErrorCode.VAR_AND_TYPE, holder.keyword, []);
2316 } 2317 }
2317 } 2318 }
2318 if (thisKeyword != null) { 2319 if (thisKeyword != null) {
2319 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);
2320 } 2321 }
2321 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);
2322 } 2323 }
2323 2324
2324 /** 2325 /**
2325 * Parse a prefixed identifier. 2326 * Parse a prefixed identifier.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2367 * identifier ::= 2368 * identifier ::=
2368 * IDENTIFIER 2369 * IDENTIFIER
2369 * </pre> 2370 * </pre>
2370 * 2371 *
2371 * @return the simple identifier that was parsed 2372 * @return the simple identifier that was parsed
2372 */ 2373 */
2373 SimpleIdentifier parseSimpleIdentifier() { 2374 SimpleIdentifier parseSimpleIdentifier() {
2374 if (matchesIdentifier()) { 2375 if (matchesIdentifier()) {
2375 return new SimpleIdentifier(andAdvance); 2376 return new SimpleIdentifier(andAdvance);
2376 } 2377 }
2377 reportError11(ParserErrorCode.MISSING_IDENTIFIER, []); 2378 reportError12(ParserErrorCode.MISSING_IDENTIFIER, []);
2378 return createSyntheticIdentifier(); 2379 return createSyntheticIdentifier();
2379 } 2380 }
2380 2381
2381 /** 2382 /**
2382 * Parse a statement. 2383 * Parse a statement.
2383 * 2384 *
2384 * <pre> 2385 * <pre>
2385 * statement ::= 2386 * statement ::=
2386 * label* nonLabeledStatement 2387 * label* nonLabeledStatement
2387 * </pre> 2388 * </pre>
(...skipping 27 matching lines...) Expand all
2415 List<StringLiteral> strings = new List<StringLiteral>(); 2416 List<StringLiteral> strings = new List<StringLiteral>();
2416 while (matches5(TokenType.STRING)) { 2417 while (matches5(TokenType.STRING)) {
2417 Token string = andAdvance; 2418 Token string = andAdvance;
2418 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)) {
2419 strings.add(parseStringInterpolation(string)); 2420 strings.add(parseStringInterpolation(string));
2420 } else { 2421 } else {
2421 strings.add(new SimpleStringLiteral(string, computeStringValue(string.le xeme, true, true))); 2422 strings.add(new SimpleStringLiteral(string, computeStringValue(string.le xeme, true, true)));
2422 } 2423 }
2423 } 2424 }
2424 if (strings.length < 1) { 2425 if (strings.length < 1) {
2425 reportError11(ParserErrorCode.EXPECTED_STRING_LITERAL, []); 2426 reportError12(ParserErrorCode.EXPECTED_STRING_LITERAL, []);
2426 return createSyntheticStringLiteral(); 2427 return createSyntheticStringLiteral();
2427 } else if (strings.length == 1) { 2428 } else if (strings.length == 1) {
2428 return strings[0]; 2429 return strings[0];
2429 } else { 2430 } else {
2430 return new AdjacentStrings(strings); 2431 return new AdjacentStrings(strings);
2431 } 2432 }
2432 } 2433 }
2433 2434
2434 /** 2435 /**
2435 * Parse a list of type arguments. 2436 * Parse a list of type arguments.
(...skipping 25 matching lines...) Expand all
2461 * <pre> 2462 * <pre>
2462 * type ::= 2463 * type ::=
2463 * qualified typeArguments? 2464 * qualified typeArguments?
2464 * </pre> 2465 * </pre>
2465 * 2466 *
2466 * @return the type name that was parsed 2467 * @return the type name that was parsed
2467 */ 2468 */
2468 TypeName parseTypeName() { 2469 TypeName parseTypeName() {
2469 Identifier typeName; 2470 Identifier typeName;
2470 if (matches(Keyword.VAR)) { 2471 if (matches(Keyword.VAR)) {
2471 reportError11(ParserErrorCode.VAR_AS_TYPE_NAME, []); 2472 reportError12(ParserErrorCode.VAR_AS_TYPE_NAME, []);
2472 typeName = new SimpleIdentifier(andAdvance); 2473 typeName = new SimpleIdentifier(andAdvance);
2473 } else if (matchesIdentifier()) { 2474 } else if (matchesIdentifier()) {
2474 typeName = parsePrefixedIdentifier(); 2475 typeName = parsePrefixedIdentifier();
2475 } else { 2476 } else {
2476 typeName = createSyntheticIdentifier(); 2477 typeName = createSyntheticIdentifier();
2477 reportError11(ParserErrorCode.EXPECTED_TYPE_NAME, []); 2478 reportError12(ParserErrorCode.EXPECTED_TYPE_NAME, []);
2478 } 2479 }
2479 TypeArgumentList typeArguments = null; 2480 TypeArgumentList typeArguments = null;
2480 if (matches5(TokenType.LT)) { 2481 if (matches5(TokenType.LT)) {
2481 typeArguments = parseTypeArgumentList(); 2482 typeArguments = parseTypeArgumentList();
2482 } 2483 }
2483 return new TypeName(typeName, typeArguments); 2484 return new TypeName(typeName, typeArguments);
2484 } 2485 }
2485 2486
2486 /** 2487 /**
2487 * Parse a type parameter. 2488 * Parse a type parameter.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2562 * value is invalid. 2563 * value is invalid.
2563 * 2564 *
2564 * @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
2565 * @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
2566 * @param scalarValue the value to be appended 2567 * @param scalarValue the value to be appended
2567 * @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
2568 * @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
2569 */ 2570 */
2570 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) {
2571 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)) {
2572 reportError11(ParserErrorCode.INVALID_CODE_POINT, [escapeSequence]); 2573 reportError12(ParserErrorCode.INVALID_CODE_POINT, [escapeSequence]);
2573 return; 2574 return;
2574 } 2575 }
2575 if (scalarValue < Character.MAX_VALUE) { 2576 if (scalarValue < Character.MAX_VALUE) {
2576 builder.appendChar(scalarValue); 2577 builder.appendChar(scalarValue);
2577 } else { 2578 } else {
2578 builder.append(Character.toChars(scalarValue)); 2579 builder.append(Character.toChars(scalarValue));
2579 } 2580 }
2580 } 2581 }
2581 2582
2582 /** 2583 /**
2583 * Compute the content of a string with the given literal representation. 2584 * Compute the content of a string with the given literal representation.
2584 * 2585 *
2585 * @param lexeme the literal representation of the string 2586 * @param lexeme the literal representation of the string
2586 * @param first `true` if this is the first token in a string literal 2587 * @param first `true` if this is the first token in a string literal
2587 * @param last `true` if this is the last token in a string literal 2588 * @param last `true` if this is the last token in a string literal
2588 * @return the actual value of the string 2589 * @return the actual value of the string
2589 */ 2590 */
2590 String computeStringValue(String lexeme, bool first, bool last) { 2591 String computeStringValue(String lexeme, bool first, bool last) {
2591 bool isRaw = false; 2592 bool isRaw = false;
2592 int start = 0; 2593 int start = 0;
2593 if (first) { 2594 if (first) {
2594 if (lexeme.startsWith("r\"\"\"") || lexeme.startsWith("r'''")) { 2595 if (StringUtilities.startsWith4(lexeme, 0, 0x72, 0x22, 0x22, 0x22) || Stri ngUtilities.startsWith4(lexeme, 0, 0x72, 0x27, 0x27, 0x27)) {
2595 isRaw = true; 2596 isRaw = true;
2596 start += 4; 2597 start += 4;
2597 } else if (lexeme.startsWith("r\"") || lexeme.startsWith("r'")) { 2598 } else if (StringUtilities.startsWith2(lexeme, 0, 0x72, 0x22) || StringUti lities.startsWith2(lexeme, 0, 0x72, 0x27)) {
2598 isRaw = true; 2599 isRaw = true;
2599 start += 2; 2600 start += 2;
2600 } else if (lexeme.startsWith("\"\"\"") || lexeme.startsWith("'''")) { 2601 } else if (StringUtilities.startsWith3(lexeme, 0, 0x22, 0x22, 0x22) || Str ingUtilities.startsWith3(lexeme, 0, 0x27, 0x27, 0x27)) {
2601 start += 3; 2602 start += 3;
2602 } else if (lexeme.startsWith("\"") || lexeme.startsWith("'")) { 2603 } else if (StringUtilities.startsWithChar(lexeme, 0x22) || StringUtilities .startsWithChar(lexeme, 0x27)) {
2603 start += 1; 2604 start += 1;
2604 } 2605 }
2605 } 2606 }
2606 int end = lexeme.length; 2607 int end = lexeme.length;
2607 if (last) { 2608 if (last) {
2608 if (lexeme.endsWith("\"\"\"") || lexeme.endsWith("'''")) { 2609 if (StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) || StringUtilities .endsWith3(lexeme, 0x27, 0x27, 0x27)) {
2609 end -= 3; 2610 end -= 3;
2610 } else if (lexeme.endsWith("\"") || lexeme.endsWith("'")) { 2611 } else if (StringUtilities.endsWithChar(lexeme, 0x22) || StringUtilities.e ndsWithChar(lexeme, 0x27)) {
2611 end -= 1; 2612 end -= 1;
2612 } 2613 }
2613 } 2614 }
2614 if (end - start + 1 < 0) { 2615 if (end - start + 1 < 0) {
2615 AnalysisEngine.instance.logger.logError("Internal error: computeStringValu e(${lexeme}, ${first}, ${last})"); 2616 AnalysisEngine.instance.logger.logError("Internal error: computeStringValu e(${lexeme}, ${first}, ${last})");
2616 return ""; 2617 return "";
2617 } 2618 }
2618 if (isRaw) { 2619 if (isRaw) {
2619 return lexeme.substring(start, end); 2620 return lexeme.substring(start, end);
2620 } 2621 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2722 * 2723 *
2723 * assignableSelector ::= 2724 * assignableSelector ::=
2724 * '[' expression ']' 2725 * '[' expression ']'
2725 * | '.' identifier 2726 * | '.' identifier
2726 * </pre> 2727 * </pre>
2727 * 2728 *
2728 * @param expression the expression being checked 2729 * @param expression the expression being checked
2729 */ 2730 */
2730 void ensureAssignable(Expression expression) { 2731 void ensureAssignable(Expression expression) {
2731 if (expression != null && !expression.isAssignable) { 2732 if (expression != null && !expression.isAssignable) {
2732 reportError11(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE, []); 2733 reportError12(ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE, []);
2733 } 2734 }
2734 } 2735 }
2735 2736
2736 /** 2737 /**
2737 * 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
2738 * 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.
2739 * 2740 *
2740 * @param keyword the keyword that is expected 2741 * @param keyword the keyword that is expected
2741 * @return the token that matched the given type 2742 * @return the token that matched the given type
2742 */ 2743 */
2743 Token expect(Keyword keyword) { 2744 Token expect(Keyword keyword) {
2744 if (matches(keyword)) { 2745 if (matches(keyword)) {
2745 return andAdvance; 2746 return andAdvance;
2746 } 2747 }
2747 // Remove uses of this method in favor of matches? 2748 // Remove uses of this method in favor of matches?
2748 // Pass in the error code to use to report the error? 2749 // Pass in the error code to use to report the error?
2749 reportError11(ParserErrorCode.EXPECTED_TOKEN, [keyword.syntax]); 2750 reportError12(ParserErrorCode.EXPECTED_TOKEN, [keyword.syntax]);
2750 return _currentToken; 2751 return _currentToken;
2751 } 2752 }
2752 2753
2753 /** 2754 /**
2754 * 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.
2755 * Otherwise report an error and return the current token without advancing. 2756 * Otherwise report an error and return the current token without advancing.
2756 * 2757 *
2757 * @param type the type of token that is expected 2758 * @param type the type of token that is expected
2758 * @return the token that matched the given type 2759 * @return the token that matched the given type
2759 */ 2760 */
2760 Token expect2(TokenType type) { 2761 Token expect2(TokenType type) {
2761 if (matches5(type)) { 2762 if (matches5(type)) {
2762 return andAdvance; 2763 return andAdvance;
2763 } 2764 }
2764 // Remove uses of this method in favor of matches? 2765 // Remove uses of this method in favor of matches?
2765 // Pass in the error code to use to report the error? 2766 // Pass in the error code to use to report the error?
2766 if (identical(type, TokenType.SEMICOLON)) { 2767 if (identical(type, TokenType.SEMICOLON)) {
2767 reportError12(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [typ e.lexeme]); 2768 reportError13(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [typ e.lexeme]);
2768 } else { 2769 } else {
2769 reportError11(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]); 2770 reportError12(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]);
2770 } 2771 }
2771 return _currentToken; 2772 return _currentToken;
2772 } 2773 }
2773 2774
2774 /** 2775 /**
2775 * 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
2776 * 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.
2777 * 2778 *
2778 * @param ranges the ranges to be searched 2779 * @param ranges the ranges to be searched
2779 * @param index the index contained in the returned range 2780 * @param index the index contained in the returned range
(...skipping 26 matching lines...) Expand all
2806 /** 2807 /**
2807 * Return a list of the ranges of characters in the given comment string that should be treated as 2808 * Return a list of the ranges of characters in the given comment string that should be treated as
2808 * code blocks. 2809 * code blocks.
2809 * 2810 *
2810 * @param comment the comment being processed 2811 * @param comment the comment being processed
2811 * @return the ranges of characters that should be treated as code blocks 2812 * @return the ranges of characters that should be treated as code blocks
2812 */ 2813 */
2813 List<List<int>> getCodeBlockRanges(String comment) { 2814 List<List<int>> getCodeBlockRanges(String comment) {
2814 List<List<int>> ranges = new List<List<int>>(); 2815 List<List<int>> ranges = new List<List<int>>();
2815 int length = comment.length; 2816 int length = comment.length;
2817 if (length < 3) {
2818 return ranges;
2819 }
2816 int index = 0; 2820 int index = 0;
2817 if (comment.startsWith("/**") || comment.startsWith("///")) { 2821 int firstChar = comment.codeUnitAt(0);
2818 index = 3; 2822 if (firstChar == 0x2F) {
2823 int secondChar = comment.codeUnitAt(1);
2824 int thirdChar = comment.codeUnitAt(2);
2825 if ((secondChar == 0x2A && thirdChar == 0x2A) || (secondChar == 0x2F && th irdChar == 0x2F)) {
2826 index = 3;
2827 }
2819 } 2828 }
2820 while (index < length) { 2829 while (index < length) {
2821 int currentChar = comment.codeUnitAt(index); 2830 int currentChar = comment.codeUnitAt(index);
2822 if (currentChar == 0xD || currentChar == 0xA) { 2831 if (currentChar == 0xD || currentChar == 0xA) {
2823 index = index + 1; 2832 index = index + 1;
2824 while (index < length && Character.isWhitespace(comment.codeUnitAt(index ))) { 2833 while (index < length && Character.isWhitespace(comment.codeUnitAt(index ))) {
2825 index = index + 1; 2834 index = index + 1;
2826 } 2835 }
2827 if (JavaString.startsWithBefore(comment, "* ", index)) { 2836 if (StringUtilities.startsWith6(comment, index, 0x2A, 0x20, 0x20, 0x20, 0x20, 0x20)) {
2828 int end = index + 6; 2837 int end = index + 6;
2829 while (end < length && comment.codeUnitAt(end) != 0xD && comment.codeU nitAt(end) != 0xA) { 2838 while (end < length && comment.codeUnitAt(end) != 0xD && comment.codeU nitAt(end) != 0xA) {
2830 end = end + 1; 2839 end = end + 1;
2831 } 2840 }
2832 ranges.add(<int> [index, end]); 2841 ranges.add(<int> [index, end]);
2833 index = end; 2842 index = end;
2834 } 2843 }
2835 } else if (JavaString.startsWithBefore(comment, "[:", index)) { 2844 } else if (index + 1 < length && currentChar == 0x5B && comment.codeUnitAt (index + 1) == 0x3A) {
2836 int end = JavaString.indexOf(comment, ":]", index + 2); 2845 int end = StringUtilities.indexOf2(comment, index + 2, 0x3A, 0x5D);
2837 if (end < 0) { 2846 if (end < 0) {
2838 end = length; 2847 end = length;
2839 } 2848 }
2840 ranges.add(<int> [index, end]); 2849 ranges.add(<int> [index, end]);
2841 index = end + 1; 2850 index = end + 1;
2842 } else { 2851 } else {
2843 index = index + 1; 2852 index = index + 1;
2844 } 2853 }
2845 } 2854 }
2846 return ranges; 2855 return ranges;
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
3292 * <pre> 3301 * <pre>
3293 * argumentDefinitionTest ::= 3302 * argumentDefinitionTest ::=
3294 * '?' identifier 3303 * '?' identifier
3295 * </pre> 3304 * </pre>
3296 * 3305 *
3297 * @return the argument definition test that was parsed 3306 * @return the argument definition test that was parsed
3298 */ 3307 */
3299 ArgumentDefinitionTest parseArgumentDefinitionTest() { 3308 ArgumentDefinitionTest parseArgumentDefinitionTest() {
3300 Token question = expect2(TokenType.QUESTION); 3309 Token question = expect2(TokenType.QUESTION);
3301 SimpleIdentifier identifier = parseSimpleIdentifier(); 3310 SimpleIdentifier identifier = parseSimpleIdentifier();
3302 reportError12(ParserErrorCode.DEPRECATED_ARGUMENT_DEFINITION_TEST, question, []); 3311 reportError13(ParserErrorCode.DEPRECATED_ARGUMENT_DEFINITION_TEST, question, []);
3303 return new ArgumentDefinitionTest(question, identifier); 3312 return new ArgumentDefinitionTest(question, identifier);
3304 } 3313 }
3305 3314
3306 /** 3315 /**
3307 * Parse an assert statement. 3316 * Parse an assert statement.
3308 * 3317 *
3309 * <pre> 3318 * <pre>
3310 * assertStatement ::= 3319 * assertStatement ::=
3311 * 'assert' '(' conditionalExpression ')' ';' 3320 * 'assert' '(' conditionalExpression ')' ';'
3312 * </pre> 3321 * </pre>
3313 * 3322 *
3314 * @return the assert statement 3323 * @return the assert statement
3315 */ 3324 */
3316 AssertStatement parseAssertStatement() { 3325 AssertStatement parseAssertStatement() {
3317 Token keyword = expect(Keyword.ASSERT); 3326 Token keyword = expect(Keyword.ASSERT);
3318 Token leftParen = expect2(TokenType.OPEN_PAREN); 3327 Token leftParen = expect2(TokenType.OPEN_PAREN);
3319 Expression expression = parseExpression3(); 3328 Expression expression = parseExpression4();
3320 if (expression is AssignmentExpression) { 3329 if (expression is AssignmentExpression) {
3321 reportError10(ParserErrorCode.ASSERT_DOES_NOT_TAKE_ASSIGNMENT, expression, []); 3330 reportError11(ParserErrorCode.ASSERT_DOES_NOT_TAKE_ASSIGNMENT, expression, []);
3322 } else if (expression is CascadeExpression) { 3331 } else if (expression is CascadeExpression) {
3323 reportError10(ParserErrorCode.ASSERT_DOES_NOT_TAKE_CASCADE, expression, [] ); 3332 reportError11(ParserErrorCode.ASSERT_DOES_NOT_TAKE_CASCADE, expression, [] );
3324 } else if (expression is ThrowExpression) { 3333 } else if (expression is ThrowExpression) {
3325 reportError10(ParserErrorCode.ASSERT_DOES_NOT_TAKE_THROW, expression, []); 3334 reportError11(ParserErrorCode.ASSERT_DOES_NOT_TAKE_THROW, expression, []);
3326 } else if (expression is RethrowExpression) { 3335 } else if (expression is RethrowExpression) {
3327 reportError10(ParserErrorCode.ASSERT_DOES_NOT_TAKE_RETHROW, expression, [] ); 3336 reportError11(ParserErrorCode.ASSERT_DOES_NOT_TAKE_RETHROW, expression, [] );
3328 } 3337 }
3329 Token rightParen = expect2(TokenType.CLOSE_PAREN); 3338 Token rightParen = expect2(TokenType.CLOSE_PAREN);
3330 Token semicolon = expect2(TokenType.SEMICOLON); 3339 Token semicolon = expect2(TokenType.SEMICOLON);
3331 return new AssertStatement(keyword, leftParen, expression, rightParen, semic olon); 3340 return new AssertStatement(keyword, leftParen, expression, rightParen, semic olon);
3332 } 3341 }
3333 3342
3334 /** 3343 /**
3335 * Parse an assignable expression. 3344 * Parse an assignable expression.
3336 * 3345 *
3337 * <pre> 3346 * <pre>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3396 * | '.' identifier 3405 * | '.' identifier
3397 * </pre> 3406 * </pre>
3398 * 3407 *
3399 * @param prefix the expression preceding the selector 3408 * @param prefix the expression preceding the selector
3400 * @param optional `true` if the selector is optional 3409 * @param optional `true` if the selector is optional
3401 * @return the assignable selector that was parsed 3410 * @return the assignable selector that was parsed
3402 */ 3411 */
3403 Expression parseAssignableSelector(Expression prefix, bool optional) { 3412 Expression parseAssignableSelector(Expression prefix, bool optional) {
3404 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { 3413 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) {
3405 Token leftBracket = andAdvance; 3414 Token leftBracket = andAdvance;
3406 Expression index = parseExpression3(); 3415 Expression index = parseExpression4();
3407 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 3416 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
3408 return new IndexExpression.forTarget(prefix, leftBracket, index, rightBrac ket); 3417 return new IndexExpression.forTarget(prefix, leftBracket, index, rightBrac ket);
3409 } else if (matches5(TokenType.PERIOD)) { 3418 } else if (matches5(TokenType.PERIOD)) {
3410 Token period = andAdvance; 3419 Token period = andAdvance;
3411 return new PropertyAccess(prefix, period, parseSimpleIdentifier()); 3420 return new PropertyAccess(prefix, period, parseSimpleIdentifier());
3412 } else { 3421 } else {
3413 if (!optional) { 3422 if (!optional) {
3414 // Report the missing selector. 3423 // Report the missing selector.
3415 reportError11(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); 3424 reportError12(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []);
3416 } 3425 }
3417 return prefix; 3426 return prefix;
3418 } 3427 }
3419 } 3428 }
3420 3429
3421 /** 3430 /**
3422 * Parse a bitwise and expression. 3431 * Parse a bitwise and expression.
3423 * 3432 *
3424 * <pre> 3433 * <pre>
3425 * bitwiseAndExpression ::= 3434 * bitwiseAndExpression ::=
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3478 * 3487 *
3479 * @return the break statement that was parsed 3488 * @return the break statement that was parsed
3480 */ 3489 */
3481 Statement parseBreakStatement() { 3490 Statement parseBreakStatement() {
3482 Token breakKeyword = expect(Keyword.BREAK); 3491 Token breakKeyword = expect(Keyword.BREAK);
3483 SimpleIdentifier label = null; 3492 SimpleIdentifier label = null;
3484 if (matchesIdentifier()) { 3493 if (matchesIdentifier()) {
3485 label = parseSimpleIdentifier(); 3494 label = parseSimpleIdentifier();
3486 } 3495 }
3487 if (!_inLoop && !_inSwitch && label == null) { 3496 if (!_inLoop && !_inSwitch && label == null) {
3488 reportError12(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []); 3497 reportError13(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []);
3489 } 3498 }
3490 Token semicolon = expect2(TokenType.SEMICOLON); 3499 Token semicolon = expect2(TokenType.SEMICOLON);
3491 return new BreakStatement(breakKeyword, label, semicolon); 3500 return new BreakStatement(breakKeyword, label, semicolon);
3492 } 3501 }
3493 3502
3494 /** 3503 /**
3495 * Parse a cascade section. 3504 * Parse a cascade section.
3496 * 3505 *
3497 * <pre> 3506 * <pre>
3498 * cascadeSection ::= 3507 * cascadeSection ::=
(...skipping 10 matching lines...) Expand all
3509 * @return the expression representing the cascaded method invocation 3518 * @return the expression representing the cascaded method invocation
3510 */ 3519 */
3511 Expression parseCascadeSection() { 3520 Expression parseCascadeSection() {
3512 Token period = expect2(TokenType.PERIOD_PERIOD); 3521 Token period = expect2(TokenType.PERIOD_PERIOD);
3513 Expression expression = null; 3522 Expression expression = null;
3514 SimpleIdentifier functionName = null; 3523 SimpleIdentifier functionName = null;
3515 if (matchesIdentifier()) { 3524 if (matchesIdentifier()) {
3516 functionName = parseSimpleIdentifier(); 3525 functionName = parseSimpleIdentifier();
3517 } else if (identical(_currentToken.type, TokenType.OPEN_SQUARE_BRACKET)) { 3526 } else if (identical(_currentToken.type, TokenType.OPEN_SQUARE_BRACKET)) {
3518 Token leftBracket = andAdvance; 3527 Token leftBracket = andAdvance;
3519 Expression index = parseExpression3(); 3528 Expression index = parseExpression4();
3520 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 3529 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
3521 expression = new IndexExpression.forCascade(period, leftBracket, index, ri ghtBracket); 3530 expression = new IndexExpression.forCascade(period, leftBracket, index, ri ghtBracket);
3522 period = null; 3531 period = null;
3523 } else { 3532 } else {
3524 reportError12(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, [_current Token.lexeme]); 3533 reportError13(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, [_current Token.lexeme]);
3525 functionName = createSyntheticIdentifier(); 3534 functionName = createSyntheticIdentifier();
3526 } 3535 }
3527 if (identical(_currentToken.type, TokenType.OPEN_PAREN)) { 3536 if (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
3528 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) { 3537 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
3529 if (functionName != null) { 3538 if (functionName != null) {
3530 expression = new MethodInvocation(expression, period, functionName, pa rseArgumentList()); 3539 expression = new MethodInvocation(expression, period, functionName, pa rseArgumentList());
3531 period = null; 3540 period = null;
3532 functionName = null; 3541 functionName = null;
3533 } else if (expression == null) { 3542 } else if (expression == null) {
3534 // 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
3605 // 3614 //
3606 ExtendsClause extendsClause = null; 3615 ExtendsClause extendsClause = null;
3607 WithClause withClause = null; 3616 WithClause withClause = null;
3608 ImplementsClause implementsClause = null; 3617 ImplementsClause implementsClause = null;
3609 bool foundClause = true; 3618 bool foundClause = true;
3610 while (foundClause) { 3619 while (foundClause) {
3611 if (matches(Keyword.EXTENDS)) { 3620 if (matches(Keyword.EXTENDS)) {
3612 if (extendsClause == null) { 3621 if (extendsClause == null) {
3613 extendsClause = parseExtendsClause(); 3622 extendsClause = parseExtendsClause();
3614 if (withClause != null) { 3623 if (withClause != null) {
3615 reportError12(ParserErrorCode.WITH_BEFORE_EXTENDS, withClause.withKe yword, []); 3624 reportError13(ParserErrorCode.WITH_BEFORE_EXTENDS, withClause.withKe yword, []);
3616 } else if (implementsClause != null) { 3625 } else if (implementsClause != null) {
3617 reportError12(ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS, implementsC lause.keyword, []); 3626 reportError13(ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS, implementsC lause.keyword, []);
3618 } 3627 }
3619 } else { 3628 } else {
3620 reportError12(ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES, extendsClause. keyword, []); 3629 reportError13(ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES, extendsClause. keyword, []);
3621 parseExtendsClause(); 3630 parseExtendsClause();
3622 } 3631 }
3623 } else if (matches(Keyword.WITH)) { 3632 } else if (matches(Keyword.WITH)) {
3624 if (withClause == null) { 3633 if (withClause == null) {
3625 withClause = parseWithClause(); 3634 withClause = parseWithClause();
3626 if (implementsClause != null) { 3635 if (implementsClause != null) {
3627 reportError12(ParserErrorCode.IMPLEMENTS_BEFORE_WITH, implementsClau se.keyword, []); 3636 reportError13(ParserErrorCode.IMPLEMENTS_BEFORE_WITH, implementsClau se.keyword, []);
3628 } 3637 }
3629 } else { 3638 } else {
3630 reportError12(ParserErrorCode.MULTIPLE_WITH_CLAUSES, withClause.withKe yword, []); 3639 reportError13(ParserErrorCode.MULTIPLE_WITH_CLAUSES, withClause.withKe yword, []);
3631 parseWithClause(); 3640 parseWithClause();
3632 } 3641 }
3633 } else if (matches(Keyword.IMPLEMENTS)) { 3642 } else if (matches(Keyword.IMPLEMENTS)) {
3634 if (implementsClause == null) { 3643 if (implementsClause == null) {
3635 implementsClause = parseImplementsClause(); 3644 implementsClause = parseImplementsClause();
3636 } else { 3645 } else {
3637 reportError12(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, implementsC lause.keyword, []); 3646 reportError13(ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES, implementsC lause.keyword, []);
3638 parseImplementsClause(); 3647 parseImplementsClause();
3639 } 3648 }
3640 } else { 3649 } else {
3641 foundClause = false; 3650 foundClause = false;
3642 } 3651 }
3643 } 3652 }
3644 if (withClause != null && extendsClause == null) { 3653 if (withClause != null && extendsClause == null) {
3645 reportError12(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withKeyword , []); 3654 reportError13(ParserErrorCode.WITH_WITHOUT_EXTENDS, withClause.withKeyword , []);
3646 } 3655 }
3647 // 3656 //
3648 // Look for and skip over the extra-lingual 'native' specification. 3657 // Look for and skip over the extra-lingual 'native' specification.
3649 // 3658 //
3650 NativeClause nativeClause = null; 3659 NativeClause nativeClause = null;
3651 if (matches2(_NATIVE) && matches4(peek(), TokenType.STRING)) { 3660 if (matches2(_NATIVE) && matches4(peek(), TokenType.STRING)) {
3652 nativeClause = parseNativeClause(); 3661 nativeClause = parseNativeClause();
3653 } 3662 }
3654 // 3663 //
3655 // Parse the body of the class. 3664 // Parse the body of the class.
3656 // 3665 //
3657 Token leftBracket = null; 3666 Token leftBracket = null;
3658 List<ClassMember> members = null; 3667 List<ClassMember> members = null;
3659 Token rightBracket = null; 3668 Token rightBracket = null;
3660 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 3669 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
3661 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 3670 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET);
3662 members = parseClassMembers(className, getEndToken(leftBracket)); 3671 members = parseClassMembers(className, getEndToken(leftBracket));
3663 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 3672 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
3664 } else { 3673 } else {
3665 leftBracket = createSyntheticToken2(TokenType.OPEN_CURLY_BRACKET); 3674 leftBracket = createSyntheticToken2(TokenType.OPEN_CURLY_BRACKET);
3666 rightBracket = createSyntheticToken2(TokenType.CLOSE_CURLY_BRACKET); 3675 rightBracket = createSyntheticToken2(TokenType.CLOSE_CURLY_BRACKET);
3667 reportError11(ParserErrorCode.MISSING_CLASS_BODY, []); 3676 reportError12(ParserErrorCode.MISSING_CLASS_BODY, []);
3668 } 3677 }
3669 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);
3670 classDeclaration.nativeClause = nativeClause; 3679 classDeclaration.nativeClause = nativeClause;
3671 return classDeclaration; 3680 return classDeclaration;
3672 } 3681 }
3673 3682
3674 /** 3683 /**
3675 * Parse a list of class members. 3684 * Parse a list of class members.
3676 * 3685 *
3677 * <pre> 3686 * <pre>
3678 * classMembers ::= 3687 * classMembers ::=
3679 * (metadata memberDefinition)* 3688 * (metadata memberDefinition)*
3680 * </pre> 3689 * </pre>
3681 * 3690 *
3682 * @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
3683 * @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
3684 * is missing 3693 * is missing
3685 * @return the list of class members that were parsed 3694 * @return the list of class members that were parsed
3686 */ 3695 */
3687 List<ClassMember> parseClassMembers(String className, Token closingBracket) { 3696 List<ClassMember> parseClassMembers(String className, Token closingBracket) {
3688 List<ClassMember> members = new List<ClassMember>(); 3697 List<ClassMember> members = new List<ClassMember>();
3689 Token memberStart = _currentToken; 3698 Token memberStart = _currentToken;
3690 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)))) {
3691 if (matches5(TokenType.SEMICOLON)) { 3700 if (matches5(TokenType.SEMICOLON)) {
3692 reportError12(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 3701 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
3693 advance(); 3702 advance();
3694 } else { 3703 } else {
3695 ClassMember member = parseClassMember(className); 3704 ClassMember member = parseClassMember(className);
3696 if (member != null) { 3705 if (member != null) {
3697 members.add(member); 3706 members.add(member);
3698 } 3707 }
3699 } 3708 }
3700 if (identical(_currentToken, memberStart)) { 3709 if (identical(_currentToken, memberStart)) {
3701 reportError12(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 3710 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
3702 advance(); 3711 advance();
3703 } 3712 }
3704 memberStart = _currentToken; 3713 memberStart = _currentToken;
3705 } 3714 }
3706 return members; 3715 return members;
3707 } 3716 }
3708 3717
3709 /** 3718 /**
3710 * Parse a class type alias. 3719 * Parse a class type alias.
3711 * 3720 *
(...skipping 27 matching lines...) Expand all
3739 } 3748 }
3740 ImplementsClause implementsClause = null; 3749 ImplementsClause implementsClause = null;
3741 if (matches(Keyword.IMPLEMENTS)) { 3750 if (matches(Keyword.IMPLEMENTS)) {
3742 implementsClause = parseImplementsClause(); 3751 implementsClause = parseImplementsClause();
3743 } 3752 }
3744 Token semicolon; 3753 Token semicolon;
3745 if (matches5(TokenType.SEMICOLON)) { 3754 if (matches5(TokenType.SEMICOLON)) {
3746 semicolon = andAdvance; 3755 semicolon = andAdvance;
3747 } else { 3756 } else {
3748 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 3757 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
3749 reportError11(ParserErrorCode.EXPECTED_TOKEN, [TokenType.SEMICOLON.lexem e]); 3758 reportError12(ParserErrorCode.EXPECTED_TOKEN, [TokenType.SEMICOLON.lexem e]);
3750 Token leftBracket = andAdvance; 3759 Token leftBracket = andAdvance;
3751 parseClassMembers(className.name, getEndToken(leftBracket)); 3760 parseClassMembers(className.name, getEndToken(leftBracket));
3752 expect2(TokenType.CLOSE_CURLY_BRACKET); 3761 expect2(TokenType.CLOSE_CURLY_BRACKET);
3753 } else { 3762 } else {
3754 reportError12(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [T okenType.SEMICOLON.lexeme]); 3763 reportError13(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [T okenType.SEMICOLON.lexeme]);
3755 } 3764 }
3756 semicolon = createSyntheticToken2(TokenType.SEMICOLON); 3765 semicolon = createSyntheticToken2(TokenType.SEMICOLON);
3757 } 3766 }
3758 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);
3759 } 3768 }
3760 3769
3761 /** 3770 /**
3762 * Parse a list of combinators in a directive. 3771 * Parse a list of combinators in a directive.
3763 * 3772 *
3764 * <pre> 3773 * <pre>
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
3943 } 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)) {
3944 validateModifiersForTypedef(modifiers); 3953 validateModifiersForTypedef(modifiers);
3945 return parseTypeAlias(commentAndMetadata); 3954 return parseTypeAlias(commentAndMetadata);
3946 } 3955 }
3947 if (matches(Keyword.VOID)) { 3956 if (matches(Keyword.VOID)) {
3948 TypeName returnType = parseReturnType(); 3957 TypeName returnType = parseReturnType();
3949 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(p eek())) { 3958 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(p eek())) {
3950 validateModifiersForTopLevelFunction(modifiers); 3959 validateModifiersForTopLevelFunction(modifiers);
3951 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType); 3960 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType);
3952 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 3961 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) {
3953 reportError12(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 3962 reportError13(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []);
3954 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, mo difiers.externalKeyword, returnType)); 3963 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, mo difiers.externalKeyword, returnType));
3955 } else if (matchesIdentifier() && matchesAny(peek(), [ 3964 } else if (matchesIdentifier() && matchesAny(peek(), [
3956 TokenType.OPEN_PAREN, 3965 TokenType.OPEN_PAREN,
3957 TokenType.OPEN_CURLY_BRACKET, 3966 TokenType.OPEN_CURLY_BRACKET,
3958 TokenType.FUNCTION])) { 3967 TokenType.FUNCTION])) {
3959 validateModifiersForTopLevelFunction(modifiers); 3968 validateModifiersForTopLevelFunction(modifiers);
3960 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType); 3969 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType);
3961 } else { 3970 } else {
3962 // 3971 //
3963 // We have found an error of some kind. Try to recover. 3972 // We have found an error of some kind. Try to recover.
3964 // 3973 //
3965 if (matchesIdentifier()) { 3974 if (matchesIdentifier()) {
3966 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) { 3975 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) {
3967 // 3976 //
3968 // 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".
3969 // 3978 //
3970 reportError10(ParserErrorCode.VOID_VARIABLE, returnType, []); 3979 reportError11(ParserErrorCode.VOID_VARIABLE, returnType, []);
3971 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));
3972 } 3981 }
3973 } 3982 }
3974 reportError12(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 3983 reportError13(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
3975 return null; 3984 return null;
3976 } 3985 }
3977 } else if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifi er2(peek())) { 3986 } else if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifi er2(peek())) {
3978 validateModifiersForTopLevelFunction(modifiers); 3987 validateModifiersForTopLevelFunction(modifiers);
3979 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null); 3988 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null);
3980 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 3989 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) {
3981 reportError12(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 3990 reportError13(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []);
3982 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, null)); 3991 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, null));
3983 } else if (!matchesIdentifier()) { 3992 } else if (!matchesIdentifier()) {
3984 reportError12(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 3993 reportError13(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
3985 return null; 3994 return null;
3986 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { 3995 } else if (matches4(peek(), TokenType.OPEN_PAREN)) {
3987 validateModifiersForTopLevelFunction(modifiers); 3996 validateModifiersForTopLevelFunction(modifiers);
3988 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null); 3997 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null);
3989 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) { 3998 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) {
3990 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) { 3999 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) {
3991 reportError11(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); 4000 reportError12(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []);
3992 } 4001 }
3993 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));
3994 } 4003 }
3995 TypeName returnType = parseReturnType(); 4004 TypeName returnType = parseReturnType();
3996 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(pee k())) { 4005 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(pee k())) {
3997 validateModifiersForTopLevelFunction(modifiers); 4006 validateModifiersForTopLevelFunction(modifiers);
3998 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType); 4007 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType);
3999 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 4008 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) {
4000 reportError12(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 4009 reportError13(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []);
4001 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, returnType)); 4010 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, returnType));
4002 } else if (matches5(TokenType.AT)) { 4011 } else if (matches5(TokenType.AT)) {
4003 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));
4004 } else if (!matchesIdentifier()) { 4013 } else if (!matchesIdentifier()) {
4005 // 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.
4006 reportError12(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 4015 reportError13(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
4007 Token semicolon; 4016 Token semicolon;
4008 if (matches5(TokenType.SEMICOLON)) { 4017 if (matches5(TokenType.SEMICOLON)) {
4009 semicolon = andAdvance; 4018 semicolon = andAdvance;
4010 } else { 4019 } else {
4011 semicolon = createSyntheticToken2(TokenType.SEMICOLON); 4020 semicolon = createSyntheticToken2(TokenType.SEMICOLON);
4012 } 4021 }
4013 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 4022 List<VariableDeclaration> variables = new List<VariableDeclaration>();
4014 variables.add(new VariableDeclaration(null, null, createSyntheticIdentifie r(), null, null)); 4023 variables.add(new VariableDeclaration(null, null, createSyntheticIdentifie r(), null, null));
4015 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);
4016 } 4025 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4073 } 4082 }
4074 } while (optional(TokenType.COMMA)); 4083 } while (optional(TokenType.COMMA));
4075 } 4084 }
4076 ConstructorName redirectedConstructor = null; 4085 ConstructorName redirectedConstructor = null;
4077 FunctionBody body; 4086 FunctionBody body;
4078 if (matches5(TokenType.EQ)) { 4087 if (matches5(TokenType.EQ)) {
4079 separator = andAdvance; 4088 separator = andAdvance;
4080 redirectedConstructor = parseConstructorName(); 4089 redirectedConstructor = parseConstructorName();
4081 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON)); 4090 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON));
4082 if (factoryKeyword == null) { 4091 if (factoryKeyword == null) {
4083 reportError10(ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, re directedConstructor, []); 4092 reportError11(ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, re directedConstructor, []);
4084 } 4093 }
4085 } else { 4094 } else {
4086 body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, fals e); 4095 body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, fals e);
4087 if (constKeyword != null && factoryKeyword != null && externalKeyword == n ull) { 4096 if (constKeyword != null && factoryKeyword != null && externalKeyword == n ull) {
4088 reportError12(ParserErrorCode.CONST_FACTORY, factoryKeyword, []); 4097 reportError13(ParserErrorCode.CONST_FACTORY, factoryKeyword, []);
4089 } else if (body is EmptyFunctionBody) { 4098 } else if (body is EmptyFunctionBody) {
4090 if (factoryKeyword != null && externalKeyword == null) { 4099 if (factoryKeyword != null && externalKeyword == null) {
4091 reportError12(ParserErrorCode.FACTORY_WITHOUT_BODY, factoryKeyword, [] ); 4100 reportError13(ParserErrorCode.FACTORY_WITHOUT_BODY, factoryKeyword, [] );
4092 } 4101 }
4093 } else { 4102 } else {
4094 if (constKeyword != null) { 4103 if (constKeyword != null) {
4095 reportError10(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body, []); 4104 reportError11(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body, []);
4096 } else if (!bodyAllowed) { 4105 } else if (!bodyAllowed) {
4097 reportError10(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, body, [] ); 4106 reportError11(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, body, [] );
4098 } 4107 }
4099 } 4108 }
4100 } 4109 }
4101 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);
4102 } 4111 }
4103 4112
4104 /** 4113 /**
4105 * Parse a field initializer within a constructor. 4114 * Parse a field initializer within a constructor.
4106 * 4115 *
4107 * <pre> 4116 * <pre>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4142 * <pre> 4151 * <pre>
4143 * continueStatement ::= 4152 * continueStatement ::=
4144 * 'continue' identifier? ';' 4153 * 'continue' identifier? ';'
4145 * </pre> 4154 * </pre>
4146 * 4155 *
4147 * @return the continue statement that was parsed 4156 * @return the continue statement that was parsed
4148 */ 4157 */
4149 Statement parseContinueStatement() { 4158 Statement parseContinueStatement() {
4150 Token continueKeyword = expect(Keyword.CONTINUE); 4159 Token continueKeyword = expect(Keyword.CONTINUE);
4151 if (!_inLoop && !_inSwitch) { 4160 if (!_inLoop && !_inSwitch) {
4152 reportError12(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword, [ ]); 4161 reportError13(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword, [ ]);
4153 } 4162 }
4154 SimpleIdentifier label = null; 4163 SimpleIdentifier label = null;
4155 if (matchesIdentifier()) { 4164 if (matchesIdentifier()) {
4156 label = parseSimpleIdentifier(); 4165 label = parseSimpleIdentifier();
4157 } 4166 }
4158 if (_inSwitch && !_inLoop && label == null) { 4167 if (_inSwitch && !_inLoop && label == null) {
4159 reportError12(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeyw ord, []); 4168 reportError13(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeyw ord, []);
4160 } 4169 }
4161 Token semicolon = expect2(TokenType.SEMICOLON); 4170 Token semicolon = expect2(TokenType.SEMICOLON);
4162 return new ContinueStatement(continueKeyword, label, semicolon); 4171 return new ContinueStatement(continueKeyword, label, semicolon);
4163 } 4172 }
4164 4173
4165 /** 4174 /**
4166 * Parse a directive. 4175 * Parse a directive.
4167 * 4176 *
4168 * <pre> 4177 * <pre>
4169 * directive ::= 4178 * directive ::=
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4201 * | singleLineComment* 4210 * | singleLineComment*
4202 * </pre> 4211 * </pre>
4203 * 4212 *
4204 * @return the documentation comment that was parsed, or `null` if there was n o comment 4213 * @return the documentation comment that was parsed, or `null` if there was n o comment
4205 */ 4214 */
4206 Comment parseDocumentationComment() { 4215 Comment parseDocumentationComment() {
4207 List<Token> commentTokens = new List<Token>(); 4216 List<Token> commentTokens = new List<Token>();
4208 Token commentToken = _currentToken.precedingComments; 4217 Token commentToken = _currentToken.precedingComments;
4209 while (commentToken != null) { 4218 while (commentToken != null) {
4210 if (identical(commentToken.type, TokenType.SINGLE_LINE_COMMENT)) { 4219 if (identical(commentToken.type, TokenType.SINGLE_LINE_COMMENT)) {
4211 if (commentToken.lexeme.startsWith("///")) { 4220 if (StringUtilities.startsWith3(commentToken.lexeme, 0, 0x2F, 0x2F, 0x2F )) {
4212 if (commentTokens.length == 1 && commentTokens[0].lexeme.startsWith("/ **")) { 4221 if (commentTokens.length == 1 && StringUtilities.startsWith3(commentTo kens[0].lexeme, 0, 0x2F, 0x2A, 0x2A)) {
4213 commentTokens.clear(); 4222 commentTokens.clear();
4214 } 4223 }
4215 commentTokens.add(commentToken); 4224 commentTokens.add(commentToken);
4216 } 4225 }
4217 } else { 4226 } else {
4218 if (commentToken.lexeme.startsWith("/**")) { 4227 if (StringUtilities.startsWith3(commentToken.lexeme, 0, 0x2F, 0x2A, 0x2A )) {
4219 commentTokens.clear(); 4228 commentTokens.clear();
4220 commentTokens.add(commentToken); 4229 commentTokens.add(commentToken);
4221 } 4230 }
4222 } 4231 }
4223 commentToken = commentToken.next; 4232 commentToken = commentToken.next;
4224 } 4233 }
4225 if (commentTokens.isEmpty) { 4234 if (commentTokens.isEmpty) {
4226 return null; 4235 return null;
4227 } 4236 }
4228 List<Token> tokens = new List.from(commentTokens); 4237 List<Token> tokens = new List.from(commentTokens);
(...skipping 12 matching lines...) Expand all
4241 * @return the do statement that was parsed 4250 * @return the do statement that was parsed
4242 */ 4251 */
4243 Statement parseDoStatement() { 4252 Statement parseDoStatement() {
4244 bool wasInLoop = _inLoop; 4253 bool wasInLoop = _inLoop;
4245 _inLoop = true; 4254 _inLoop = true;
4246 try { 4255 try {
4247 Token doKeyword = expect(Keyword.DO); 4256 Token doKeyword = expect(Keyword.DO);
4248 Statement body = parseStatement2(); 4257 Statement body = parseStatement2();
4249 Token whileKeyword = expect(Keyword.WHILE); 4258 Token whileKeyword = expect(Keyword.WHILE);
4250 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 4259 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
4251 Expression condition = parseExpression3(); 4260 Expression condition = parseExpression4();
4252 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4261 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4253 Token semicolon = expect2(TokenType.SEMICOLON); 4262 Token semicolon = expect2(TokenType.SEMICOLON);
4254 return new DoStatement(doKeyword, body, whileKeyword, leftParenthesis, con dition, rightParenthesis, semicolon); 4263 return new DoStatement(doKeyword, body, whileKeyword, leftParenthesis, con dition, rightParenthesis, semicolon);
4255 } finally { 4264 } finally {
4256 _inLoop = wasInLoop; 4265 _inLoop = wasInLoop;
4257 } 4266 }
4258 } 4267 }
4259 4268
4260 /** 4269 /**
4261 * Parse an empty statement. 4270 * Parse an empty statement.
(...skipping 22 matching lines...) Expand all
4284 Expression expression; 4293 Expression expression;
4285 if (matches(Keyword.SUPER) && _currentToken.next.type.isEqualityOperator) { 4294 if (matches(Keyword.SUPER) && _currentToken.next.type.isEqualityOperator) {
4286 expression = new SuperExpression(andAdvance); 4295 expression = new SuperExpression(andAdvance);
4287 } else { 4296 } else {
4288 expression = parseRelationalExpression(); 4297 expression = parseRelationalExpression();
4289 } 4298 }
4290 bool leftEqualityExpression = false; 4299 bool leftEqualityExpression = false;
4291 while (_currentToken.type.isEqualityOperator) { 4300 while (_currentToken.type.isEqualityOperator) {
4292 Token operator = andAdvance; 4301 Token operator = andAdvance;
4293 if (leftEqualityExpression) { 4302 if (leftEqualityExpression) {
4294 reportError10(ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expre ssion, []); 4303 reportError11(ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expre ssion, []);
4295 } 4304 }
4296 expression = new BinaryExpression(expression, operator, parseRelationalExp ression()); 4305 expression = new BinaryExpression(expression, operator, parseRelationalExp ression());
4297 leftEqualityExpression = true; 4306 leftEqualityExpression = true;
4298 } 4307 }
4299 return expression; 4308 return expression;
4300 } 4309 }
4301 4310
4302 /** 4311 /**
4303 * Parse an export directive. 4312 * Parse an export directive.
4304 * 4313 *
(...skipping 18 matching lines...) Expand all
4323 * 4332 *
4324 * <pre> 4333 * <pre>
4325 * expressionList ::= 4334 * expressionList ::=
4326 * expression (',' expression)* 4335 * expression (',' expression)*
4327 * </pre> 4336 * </pre>
4328 * 4337 *
4329 * @return the expression that was parsed 4338 * @return the expression that was parsed
4330 */ 4339 */
4331 List<Expression> parseExpressionList() { 4340 List<Expression> parseExpressionList() {
4332 List<Expression> expressions = new List<Expression>(); 4341 List<Expression> expressions = new List<Expression>();
4333 expressions.add(parseExpression3()); 4342 expressions.add(parseExpression4());
4334 while (optional(TokenType.COMMA)) { 4343 while (optional(TokenType.COMMA)) {
4335 expressions.add(parseExpression3()); 4344 expressions.add(parseExpression4());
4336 } 4345 }
4337 return expressions; 4346 return expressions;
4338 } 4347 }
4339 4348
4340 /** 4349 /**
4341 * Parse the 'final', 'const', 'var' or type preceding a variable declaration. 4350 * Parse the 'final', 'const', 'var' or type preceding a variable declaration.
4342 * 4351 *
4343 * <pre> 4352 * <pre>
4344 * finalConstVarOrType ::= 4353 * finalConstVarOrType ::=
4345 * | 'final' type? 4354 * | 'final' type?
(...skipping 12 matching lines...) Expand all
4358 keyword = andAdvance; 4367 keyword = andAdvance;
4359 if (isTypedIdentifier(_currentToken)) { 4368 if (isTypedIdentifier(_currentToken)) {
4360 type = parseTypeName(); 4369 type = parseTypeName();
4361 } 4370 }
4362 } else if (matches(Keyword.VAR)) { 4371 } else if (matches(Keyword.VAR)) {
4363 keyword = andAdvance; 4372 keyword = andAdvance;
4364 } else { 4373 } else {
4365 if (isTypedIdentifier(_currentToken)) { 4374 if (isTypedIdentifier(_currentToken)) {
4366 type = parseReturnType(); 4375 type = parseReturnType();
4367 } else if (!optional) { 4376 } else if (!optional) {
4368 reportError11(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); 4377 reportError12(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []);
4369 } 4378 }
4370 } 4379 }
4371 return new FinalConstVarOrType(keyword, type); 4380 return new FinalConstVarOrType(keyword, type);
4372 } 4381 }
4373 4382
4374 /** 4383 /**
4375 * 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
4376 * `true`. 4385 * `true`.
4377 * 4386 *
4378 * <pre> 4387 * <pre>
4379 * defaultFormalParameter ::= 4388 * defaultFormalParameter ::=
4380 * normalFormalParameter ('=' expression)? 4389 * normalFormalParameter ('=' expression)?
4381 * 4390 *
4382 * defaultNamedParameter ::= 4391 * defaultNamedParameter ::=
4383 * normalFormalParameter (':' expression)? 4392 * normalFormalParameter (':' expression)?
4384 * </pre> 4393 * </pre>
4385 * 4394 *
4386 * @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
4387 * delimiters 4396 * delimiters
4388 * @return the formal parameter that was parsed 4397 * @return the formal parameter that was parsed
4389 */ 4398 */
4390 FormalParameter parseFormalParameter(ParameterKind kind) { 4399 FormalParameter parseFormalParameter(ParameterKind kind) {
4391 NormalFormalParameter parameter = parseNormalFormalParameter(); 4400 NormalFormalParameter parameter = parseNormalFormalParameter();
4392 if (matches5(TokenType.EQ)) { 4401 if (matches5(TokenType.EQ)) {
4393 Token seperator = andAdvance; 4402 Token seperator = andAdvance;
4394 Expression defaultValue = parseExpression3(); 4403 Expression defaultValue = parseExpression4();
4395 if (identical(kind, ParameterKind.NAMED)) { 4404 if (identical(kind, ParameterKind.NAMED)) {
4396 reportError12(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, seper ator, []); 4405 reportError13(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, seper ator, []);
4397 } else if (identical(kind, ParameterKind.REQUIRED)) { 4406 } else if (identical(kind, ParameterKind.REQUIRED)) {
4398 reportError10(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, parame ter, []); 4407 reportError11(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, parame ter, []);
4399 } 4408 }
4400 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue ); 4409 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue );
4401 } else if (matches5(TokenType.COLON)) { 4410 } else if (matches5(TokenType.COLON)) {
4402 Token seperator = andAdvance; 4411 Token seperator = andAdvance;
4403 Expression defaultValue = parseExpression3(); 4412 Expression defaultValue = parseExpression4();
4404 if (identical(kind, ParameterKind.POSITIONAL)) { 4413 if (identical(kind, ParameterKind.POSITIONAL)) {
4405 reportError12(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, seperator, []); 4414 reportError13(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, seperator, []);
4406 } else if (identical(kind, ParameterKind.REQUIRED)) { 4415 } else if (identical(kind, ParameterKind.REQUIRED)) {
4407 reportError10(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter, []); 4416 reportError11(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter, []);
4408 } 4417 }
4409 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue ); 4418 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue );
4410 } else if (kind != ParameterKind.REQUIRED) { 4419 } else if (kind != ParameterKind.REQUIRED) {
4411 return new DefaultFormalParameter(parameter, kind, null, null); 4420 return new DefaultFormalParameter(parameter, kind, null, null);
4412 } 4421 }
4413 return parameter; 4422 return parameter;
4414 } 4423 }
4415 4424
4416 /** 4425 /**
4417 * Parse a for statement. 4426 * Parse a for statement.
(...skipping 25 matching lines...) Expand all
4443 if (!matches5(TokenType.SEMICOLON)) { 4452 if (!matches5(TokenType.SEMICOLON)) {
4444 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 4453 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
4445 if (matchesIdentifier() && matches3(peek(), Keyword.IN)) { 4454 if (matchesIdentifier() && matches3(peek(), Keyword.IN)) {
4446 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 4455 List<VariableDeclaration> variables = new List<VariableDeclaration>();
4447 SimpleIdentifier variableName = parseSimpleIdentifier(); 4456 SimpleIdentifier variableName = parseSimpleIdentifier();
4448 variables.add(new VariableDeclaration(null, null, variableName, null, null)); 4457 variables.add(new VariableDeclaration(null, null, variableName, null, null));
4449 variableList = new VariableDeclarationList(commentAndMetadata.comment, commentAndMetadata.metadata, null, null, variables); 4458 variableList = new VariableDeclarationList(commentAndMetadata.comment, commentAndMetadata.metadata, null, null, variables);
4450 } else if (isInitializedVariableDeclaration()) { 4459 } else if (isInitializedVariableDeclaration()) {
4451 variableList = parseVariableDeclarationList(commentAndMetadata); 4460 variableList = parseVariableDeclarationList(commentAndMetadata);
4452 } else { 4461 } else {
4453 initialization = parseExpression3(); 4462 initialization = parseExpression4();
4454 } 4463 }
4455 if (matches(Keyword.IN)) { 4464 if (matches(Keyword.IN)) {
4456 DeclaredIdentifier loopVariable = null; 4465 DeclaredIdentifier loopVariable = null;
4457 SimpleIdentifier identifier = null; 4466 SimpleIdentifier identifier = null;
4458 if (variableList == null) { 4467 if (variableList == null) {
4459 // We found: <expression> 'in' 4468 // We found: <expression> 'in'
4460 reportError11(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH, []); 4469 reportError12(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH, []);
4461 } else { 4470 } else {
4462 NodeList<VariableDeclaration> variables = variableList.variables; 4471 NodeList<VariableDeclaration> variables = variableList.variables;
4463 if (variables.length > 1) { 4472 if (variables.length > 1) {
4464 reportError11(ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH, [var iables.length.toString()]); 4473 reportError12(ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH, [var iables.length.toString()]);
4465 } 4474 }
4466 VariableDeclaration variable = variables[0]; 4475 VariableDeclaration variable = variables[0];
4467 if (variable.initializer != null) { 4476 if (variable.initializer != null) {
4468 reportError11(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH, [] ); 4477 reportError12(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH, [] );
4469 } 4478 }
4470 Token keyword = variableList.keyword; 4479 Token keyword = variableList.keyword;
4471 TypeName type = variableList.type; 4480 TypeName type = variableList.type;
4472 if (keyword != null || type != null) { 4481 if (keyword != null || type != null) {
4473 loopVariable = new DeclaredIdentifier(commentAndMetadata.comment, commentAndMetadata.metadata, keyword, type, variable.name); 4482 loopVariable = new DeclaredIdentifier(commentAndMetadata.comment, commentAndMetadata.metadata, keyword, type, variable.name);
4474 } else { 4483 } else {
4475 if (!commentAndMetadata.metadata.isEmpty) { 4484 if (!commentAndMetadata.metadata.isEmpty) {
4476 } 4485 }
4477 identifier = variable.name; 4486 identifier = variable.name;
4478 } 4487 }
4479 } 4488 }
4480 Token inKeyword = expect(Keyword.IN); 4489 Token inKeyword = expect(Keyword.IN);
4481 Expression iterator = parseExpression3(); 4490 Expression iterator = parseExpression4();
4482 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4491 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4483 Statement body = parseStatement2(); 4492 Statement body = parseStatement2();
4484 if (loopVariable == null) { 4493 if (loopVariable == null) {
4485 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);
4486 } 4495 }
4487 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);
4488 } 4497 }
4489 } 4498 }
4490 Token leftSeparator = expect2(TokenType.SEMICOLON); 4499 Token leftSeparator = expect2(TokenType.SEMICOLON);
4491 Expression condition = null; 4500 Expression condition = null;
4492 if (!matches5(TokenType.SEMICOLON)) { 4501 if (!matches5(TokenType.SEMICOLON)) {
4493 condition = parseExpression3(); 4502 condition = parseExpression4();
4494 } 4503 }
4495 Token rightSeparator = expect2(TokenType.SEMICOLON); 4504 Token rightSeparator = expect2(TokenType.SEMICOLON);
4496 List<Expression> updaters = null; 4505 List<Expression> updaters = null;
4497 if (!matches5(TokenType.CLOSE_PAREN)) { 4506 if (!matches5(TokenType.CLOSE_PAREN)) {
4498 updaters = parseExpressionList(); 4507 updaters = parseExpressionList();
4499 } 4508 }
4500 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4509 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4501 Statement body = parseStatement2(); 4510 Statement body = parseStatement2();
4502 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);
4503 } finally { 4512 } finally {
(...skipping 21 matching lines...) Expand all
4525 * @return the function body that was parsed 4534 * @return the function body that was parsed
4526 */ 4535 */
4527 FunctionBody parseFunctionBody(bool mayBeEmpty, ParserErrorCode emptyErrorCode , bool inExpression) { 4536 FunctionBody parseFunctionBody(bool mayBeEmpty, ParserErrorCode emptyErrorCode , bool inExpression) {
4528 bool wasInLoop = _inLoop; 4537 bool wasInLoop = _inLoop;
4529 bool wasInSwitch = _inSwitch; 4538 bool wasInSwitch = _inSwitch;
4530 _inLoop = false; 4539 _inLoop = false;
4531 _inSwitch = false; 4540 _inSwitch = false;
4532 try { 4541 try {
4533 if (matches5(TokenType.SEMICOLON)) { 4542 if (matches5(TokenType.SEMICOLON)) {
4534 if (!mayBeEmpty) { 4543 if (!mayBeEmpty) {
4535 reportError11(emptyErrorCode, []); 4544 reportError12(emptyErrorCode, []);
4536 } 4545 }
4537 return new EmptyFunctionBody(andAdvance); 4546 return new EmptyFunctionBody(andAdvance);
4538 } else if (matches5(TokenType.FUNCTION)) { 4547 } else if (matches5(TokenType.FUNCTION)) {
4539 Token functionDefinition = andAdvance; 4548 Token functionDefinition = andAdvance;
4540 Expression expression = parseExpression3(); 4549 Expression expression = parseExpression4();
4541 Token semicolon = null; 4550 Token semicolon = null;
4542 if (!inExpression) { 4551 if (!inExpression) {
4543 semicolon = expect2(TokenType.SEMICOLON); 4552 semicolon = expect2(TokenType.SEMICOLON);
4544 } 4553 }
4545 if (!_parseFunctionBodies) { 4554 if (!_parseFunctionBodies) {
4546 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON )); 4555 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON ));
4547 } 4556 }
4548 return new ExpressionFunctionBody(functionDefinition, expression, semico lon); 4557 return new ExpressionFunctionBody(functionDefinition, expression, semico lon);
4549 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 4558 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
4550 if (!_parseFunctionBodies) { 4559 if (!_parseFunctionBodies) {
4551 skipBlock(); 4560 skipBlock();
4552 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON )); 4561 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON ));
4553 } 4562 }
4554 return new BlockFunctionBody(parseBlock()); 4563 return new BlockFunctionBody(parseBlock());
4555 } else if (matches2(_NATIVE)) { 4564 } else if (matches2(_NATIVE)) {
4556 Token nativeToken = andAdvance; 4565 Token nativeToken = andAdvance;
4557 StringLiteral stringLiteral = null; 4566 StringLiteral stringLiteral = null;
4558 if (matches5(TokenType.STRING)) { 4567 if (matches5(TokenType.STRING)) {
4559 stringLiteral = parseStringLiteral(); 4568 stringLiteral = parseStringLiteral();
4560 } 4569 }
4561 return new NativeFunctionBody(nativeToken, stringLiteral, expect2(TokenT ype.SEMICOLON)); 4570 return new NativeFunctionBody(nativeToken, stringLiteral, expect2(TokenT ype.SEMICOLON));
4562 } else { 4571 } else {
4563 // Invalid function body 4572 // Invalid function body
4564 reportError11(emptyErrorCode, []); 4573 reportError12(emptyErrorCode, []);
4565 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON)) ; 4574 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON)) ;
4566 } 4575 }
4567 } finally { 4576 } finally {
4568 _inLoop = wasInLoop; 4577 _inLoop = wasInLoop;
4569 _inSwitch = wasInSwitch; 4578 _inSwitch = wasInSwitch;
4570 } 4579 }
4571 } 4580 }
4572 4581
4573 /** 4582 /**
4574 * Parse a function declaration. 4583 * Parse a function declaration.
(...skipping 20 matching lines...) Expand all
4595 } else if (matches(Keyword.SET) && !matches4(peek(), TokenType.OPEN_PAREN)) { 4604 } else if (matches(Keyword.SET) && !matches4(peek(), TokenType.OPEN_PAREN)) {
4596 keyword = andAdvance; 4605 keyword = andAdvance;
4597 } 4606 }
4598 SimpleIdentifier name = parseSimpleIdentifier(); 4607 SimpleIdentifier name = parseSimpleIdentifier();
4599 FormalParameterList parameters = null; 4608 FormalParameterList parameters = null;
4600 if (!isGetter) { 4609 if (!isGetter) {
4601 if (matches5(TokenType.OPEN_PAREN)) { 4610 if (matches5(TokenType.OPEN_PAREN)) {
4602 parameters = parseFormalParameterList(); 4611 parameters = parseFormalParameterList();
4603 validateFormalParameterList(parameters); 4612 validateFormalParameterList(parameters);
4604 } else { 4613 } else {
4605 reportError11(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, []); 4614 reportError12(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, []);
4606 } 4615 }
4607 } else if (matches5(TokenType.OPEN_PAREN)) { 4616 } else if (matches5(TokenType.OPEN_PAREN)) {
4608 reportError11(ParserErrorCode.GETTER_WITH_PARAMETERS, []); 4617 reportError12(ParserErrorCode.GETTER_WITH_PARAMETERS, []);
4609 parseFormalParameterList(); 4618 parseFormalParameterList();
4610 } 4619 }
4611 FunctionBody body; 4620 FunctionBody body;
4612 if (externalKeyword == null) { 4621 if (externalKeyword == null) {
4613 body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, fal se); 4622 body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, fal se);
4614 } else { 4623 } else {
4615 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON)); 4624 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON));
4616 } 4625 }
4617 // if (!isStatement && matches(TokenType.SEMICOLON)) { 4626 // if (!isStatement && matches(TokenType.SEMICOLON)) {
4618 // // TODO(brianwilkerson) Improve this error message. 4627 // // TODO(brianwilkerson) Improve this error message.
(...skipping 30 matching lines...) Expand all
4649 * @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
4650 * declaration 4659 * declaration
4651 * @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
4652 * @return the function declaration statement that was parsed 4661 * @return the function declaration statement that was parsed
4653 */ 4662 */
4654 Statement parseFunctionDeclarationStatement2(CommentAndMetadata commentAndMeta data, TypeName returnType) { 4663 Statement parseFunctionDeclarationStatement2(CommentAndMetadata commentAndMeta data, TypeName returnType) {
4655 FunctionDeclaration declaration = parseFunctionDeclaration(commentAndMetadat a, null, returnType); 4664 FunctionDeclaration declaration = parseFunctionDeclaration(commentAndMetadat a, null, returnType);
4656 Token propertyKeyword = declaration.propertyKeyword; 4665 Token propertyKeyword = declaration.propertyKeyword;
4657 if (propertyKeyword != null) { 4666 if (propertyKeyword != null) {
4658 if (identical((propertyKeyword as KeywordToken).keyword, Keyword.GET)) { 4667 if (identical((propertyKeyword as KeywordToken).keyword, Keyword.GET)) {
4659 reportError12(ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword, []); 4668 reportError13(ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword, []);
4660 } else { 4669 } else {
4661 reportError12(ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword, []); 4670 reportError13(ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword, []);
4662 } 4671 }
4663 } 4672 }
4664 return new FunctionDeclarationStatement(declaration); 4673 return new FunctionDeclarationStatement(declaration);
4665 } 4674 }
4666 4675
4667 /** 4676 /**
4668 * Parse a function type alias. 4677 * Parse a function type alias.
4669 * 4678 *
4670 * <pre> 4679 * <pre>
4671 * functionTypeAlias ::= 4680 * functionTypeAlias ::=
(...skipping 11 matching lines...) Expand all
4683 TypeName returnType = null; 4692 TypeName returnType = null;
4684 if (hasReturnTypeInTypeAlias()) { 4693 if (hasReturnTypeInTypeAlias()) {
4685 returnType = parseReturnType(); 4694 returnType = parseReturnType();
4686 } 4695 }
4687 SimpleIdentifier name = parseSimpleIdentifier(); 4696 SimpleIdentifier name = parseSimpleIdentifier();
4688 TypeParameterList typeParameters = null; 4697 TypeParameterList typeParameters = null;
4689 if (matches5(TokenType.LT)) { 4698 if (matches5(TokenType.LT)) {
4690 typeParameters = parseTypeParameterList(); 4699 typeParameters = parseTypeParameterList();
4691 } 4700 }
4692 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.EOF)) { 4701 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.EOF)) {
4693 reportError11(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); 4702 reportError12(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []);
4694 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));
4695 Token semicolon = expect2(TokenType.SEMICOLON); 4704 Token semicolon = expect2(TokenType.SEMICOLON);
4696 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);
4697 } else if (!matches5(TokenType.OPEN_PAREN)) { 4706 } else if (!matches5(TokenType.OPEN_PAREN)) {
4698 reportError11(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); 4707 reportError12(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []);
4699 // 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
4700 // 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
4701 // typedef parameters before that point. 4710 // typedef parameters before that point.
4702 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));
4703 } 4712 }
4704 FormalParameterList parameters = parseFormalParameterList(); 4713 FormalParameterList parameters = parseFormalParameterList();
4705 validateFormalParameterList(parameters); 4714 validateFormalParameterList(parameters);
4706 Token semicolon = expect2(TokenType.SEMICOLON); 4715 Token semicolon = expect2(TokenType.SEMICOLON);
4707 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);
4708 } 4717 }
(...skipping 14 matching lines...) Expand all
4723 * @param externalKeyword the 'external' token 4732 * @param externalKeyword the 'external' token
4724 * @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
4725 * @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
4726 * type 4735 * type
4727 * @return the getter that was parsed 4736 * @return the getter that was parsed
4728 */ 4737 */
4729 MethodDeclaration parseGetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) { 4738 MethodDeclaration parseGetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) {
4730 Token propertyKeyword = expect(Keyword.GET); 4739 Token propertyKeyword = expect(Keyword.GET);
4731 SimpleIdentifier name = parseSimpleIdentifier(); 4740 SimpleIdentifier name = parseSimpleIdentifier();
4732 if (matches5(TokenType.OPEN_PAREN) && matches4(peek(), TokenType.CLOSE_PAREN )) { 4741 if (matches5(TokenType.OPEN_PAREN) && matches4(peek(), TokenType.CLOSE_PAREN )) {
4733 reportError11(ParserErrorCode.GETTER_WITH_PARAMETERS, []); 4742 reportError12(ParserErrorCode.GETTER_WITH_PARAMETERS, []);
4734 advance(); 4743 advance();
4735 advance(); 4744 advance();
4736 } 4745 }
4737 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);
4738 if (externalKeyword != null && body is! EmptyFunctionBody) { 4747 if (externalKeyword != null && body is! EmptyFunctionBody) {
4739 reportError11(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []); 4748 reportError12(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []);
4740 } 4749 }
4741 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);
4742 } 4751 }
4743 4752
4744 /** 4753 /**
4745 * Parse a list of identifiers. 4754 * Parse a list of identifiers.
4746 * 4755 *
4747 * <pre> 4756 * <pre>
4748 * identifierList ::= 4757 * identifierList ::=
4749 * identifier (',' identifier)* 4758 * identifier (',' identifier)*
(...skipping 17 matching lines...) Expand all
4767 * <pre> 4776 * <pre>
4768 * ifStatement ::= 4777 * ifStatement ::=
4769 * 'if' '(' expression ')' statement ('else' statement)? 4778 * 'if' '(' expression ')' statement ('else' statement)?
4770 * </pre> 4779 * </pre>
4771 * 4780 *
4772 * @return the if statement that was parsed 4781 * @return the if statement that was parsed
4773 */ 4782 */
4774 Statement parseIfStatement() { 4783 Statement parseIfStatement() {
4775 Token ifKeyword = expect(Keyword.IF); 4784 Token ifKeyword = expect(Keyword.IF);
4776 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 4785 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
4777 Expression condition = parseExpression3(); 4786 Expression condition = parseExpression4();
4778 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4787 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4779 Statement thenStatement = parseStatement2(); 4788 Statement thenStatement = parseStatement2();
4780 Token elseKeyword = null; 4789 Token elseKeyword = null;
4781 Statement elseStatement = null; 4790 Statement elseStatement = null;
4782 if (matches(Keyword.ELSE)) { 4791 if (matches(Keyword.ELSE)) {
4783 elseKeyword = andAdvance; 4792 elseKeyword = andAdvance;
4784 elseStatement = parseStatement2(); 4793 elseStatement = parseStatement2();
4785 } 4794 }
4786 return new IfStatement(ifKeyword, leftParenthesis, condition, rightParenthes is, thenStatement, elseKeyword, elseStatement); 4795 return new IfStatement(ifKeyword, leftParenthesis, condition, rightParenthes is, thenStatement, elseKeyword, elseStatement);
4787 } 4796 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
4887 * missing 4896 * missing
4888 * @return the library name that was parsed 4897 * @return the library name that was parsed
4889 */ 4898 */
4890 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis singNameToken) { 4899 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis singNameToken) {
4891 if (matchesIdentifier()) { 4900 if (matchesIdentifier()) {
4892 return parseLibraryIdentifier(); 4901 return parseLibraryIdentifier();
4893 } else if (matches5(TokenType.STRING)) { 4902 } else if (matches5(TokenType.STRING)) {
4894 // 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
4895 // can find a token that can start a compilation unit member. 4904 // can find a token that can start a compilation unit member.
4896 StringLiteral string = parseStringLiteral(); 4905 StringLiteral string = parseStringLiteral();
4897 reportError10(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, []); 4906 reportError11(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, []);
4898 } else { 4907 } else {
4899 reportError12(missingNameError, missingNameToken, []); 4908 reportError13(missingNameError, missingNameToken, []);
4900 } 4909 }
4901 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); 4910 List<SimpleIdentifier> components = new List<SimpleIdentifier>();
4902 components.add(createSyntheticIdentifier()); 4911 components.add(createSyntheticIdentifier());
4903 return new LibraryIdentifier(components); 4912 return new LibraryIdentifier(components);
4904 } 4913 }
4905 4914
4906 /** 4915 /**
4907 * Parse a list literal. 4916 * Parse a list literal.
4908 * 4917 *
4909 * <pre> 4918 * <pre>
(...skipping 18 matching lines...) Expand all
4928 _currentToken.previous.setNext(leftBracket); 4937 _currentToken.previous.setNext(leftBracket);
4929 _currentToken = _currentToken.next; 4938 _currentToken = _currentToken.next;
4930 return new ListLiteral(modifier, typeArguments, leftBracket, null, rightBr acket); 4939 return new ListLiteral(modifier, typeArguments, leftBracket, null, rightBr acket);
4931 } 4940 }
4932 // open 4941 // open
4933 Token leftBracket = expect2(TokenType.OPEN_SQUARE_BRACKET); 4942 Token leftBracket = expect2(TokenType.OPEN_SQUARE_BRACKET);
4934 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 4943 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) {
4935 return new ListLiteral(modifier, typeArguments, leftBracket, null, andAdva nce); 4944 return new ListLiteral(modifier, typeArguments, leftBracket, null, andAdva nce);
4936 } 4945 }
4937 List<Expression> elements = new List<Expression>(); 4946 List<Expression> elements = new List<Expression>();
4938 elements.add(parseExpression3()); 4947 elements.add(parseExpression4());
4939 while (optional(TokenType.COMMA)) { 4948 while (optional(TokenType.COMMA)) {
4940 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 4949 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) {
4941 return new ListLiteral(modifier, typeArguments, leftBracket, elements, a ndAdvance); 4950 return new ListLiteral(modifier, typeArguments, leftBracket, elements, a ndAdvance);
4942 } 4951 }
4943 elements.add(parseExpression3()); 4952 elements.add(parseExpression4());
4944 } 4953 }
4945 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 4954 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
4946 return new ListLiteral(modifier, typeArguments, leftBracket, elements, right Bracket); 4955 return new ListLiteral(modifier, typeArguments, leftBracket, elements, right Bracket);
4947 } 4956 }
4948 4957
4949 /** 4958 /**
4950 * Parse a list or map literal. 4959 * Parse a list or map literal.
4951 * 4960 *
4952 * <pre> 4961 * <pre>
4953 * listOrMapLiteral ::= 4962 * listOrMapLiteral ::=
4954 * listLiteral 4963 * listLiteral
4955 * | mapLiteral 4964 * | mapLiteral
4956 * </pre> 4965 * </pre>
4957 * 4966 *
4958 * @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
4959 * no modifier 4968 * no modifier
4960 * @return the list or map literal that was parsed 4969 * @return the list or map literal that was parsed
4961 */ 4970 */
4962 TypedLiteral parseListOrMapLiteral(Token modifier) { 4971 TypedLiteral parseListOrMapLiteral(Token modifier) {
4963 TypeArgumentList typeArguments = null; 4972 TypeArgumentList typeArguments = null;
4964 if (matches5(TokenType.LT)) { 4973 if (matches5(TokenType.LT)) {
4965 typeArguments = parseTypeArgumentList(); 4974 typeArguments = parseTypeArgumentList();
4966 } 4975 }
4967 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 4976 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
4968 return parseMapLiteral(modifier, typeArguments); 4977 return parseMapLiteral(modifier, typeArguments);
4969 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) { 4978 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) {
4970 return parseListLiteral(modifier, typeArguments); 4979 return parseListLiteral(modifier, typeArguments);
4971 } 4980 }
4972 reportError11(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []); 4981 reportError12(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []);
4973 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));
4974 } 4983 }
4975 4984
4976 /** 4985 /**
4977 * Parse a logical and expression. 4986 * Parse a logical and expression.
4978 * 4987 *
4979 * <pre> 4988 * <pre>
4980 * logicalAndExpression ::= 4989 * logicalAndExpression ::=
4981 * equalityExpression ('&&' equalityExpression)* 4990 * equalityExpression ('&&' equalityExpression)*
4982 * </pre> 4991 * </pre>
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
5061 * @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
5062 * @param returnType the return type of the method 5071 * @param returnType the return type of the method
5063 * @param name the name of the method 5072 * @param name the name of the method
5064 * @param parameters the parameters to the method 5073 * @param parameters the parameters to the method
5065 * @return the method declaration that was parsed 5074 * @return the method declaration that was parsed
5066 */ 5075 */
5067 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) {
5068 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);
5069 if (externalKeyword != null) { 5078 if (externalKeyword != null) {
5070 if (body is! EmptyFunctionBody) { 5079 if (body is! EmptyFunctionBody) {
5071 reportError10(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []); 5080 reportError11(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []);
5072 } 5081 }
5073 } else if (staticKeyword != null) { 5082 } else if (staticKeyword != null) {
5074 if (body is EmptyFunctionBody) { 5083 if (body is EmptyFunctionBody) {
5075 reportError10(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []); 5084 reportError11(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []);
5076 } 5085 }
5077 } 5086 }
5078 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);
5079 } 5088 }
5080 5089
5081 /** 5090 /**
5082 * 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
5083 * 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
5084 * 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
5085 * 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`.
5086 * 5095 *
5087 * <pre> 5096 * <pre>
5088 * modifiers ::= 5097 * modifiers ::=
5089 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | ' var')* 5098 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | ' var')*
5090 * </pre> 5099 * </pre>
5091 * 5100 *
5092 * @return the modifiers that were parsed 5101 * @return the modifiers that were parsed
5093 */ 5102 */
5094 Modifiers parseModifiers() { 5103 Modifiers parseModifiers() {
5095 Modifiers modifiers = new Modifiers(); 5104 Modifiers modifiers = new Modifiers();
5096 bool progress = true; 5105 bool progress = true;
5097 while (progress) { 5106 while (progress) {
5098 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)) {
5099 return modifiers; 5108 return modifiers;
5100 } 5109 }
5101 if (matches(Keyword.ABSTRACT)) { 5110 if (matches(Keyword.ABSTRACT)) {
5102 if (modifiers.abstractKeyword != null) { 5111 if (modifiers.abstractKeyword != null) {
5103 reportError11(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5112 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5104 advance(); 5113 advance();
5105 } else { 5114 } else {
5106 modifiers.abstractKeyword = andAdvance; 5115 modifiers.abstractKeyword = andAdvance;
5107 } 5116 }
5108 } else if (matches(Keyword.CONST)) { 5117 } else if (matches(Keyword.CONST)) {
5109 if (modifiers.constKeyword != null) { 5118 if (modifiers.constKeyword != null) {
5110 reportError11(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5119 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5111 advance(); 5120 advance();
5112 } else { 5121 } else {
5113 modifiers.constKeyword = andAdvance; 5122 modifiers.constKeyword = andAdvance;
5114 } 5123 }
5115 } 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)) {
5116 if (modifiers.externalKeyword != null) { 5125 if (modifiers.externalKeyword != null) {
5117 reportError11(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5126 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5118 advance(); 5127 advance();
5119 } else { 5128 } else {
5120 modifiers.externalKeyword = andAdvance; 5129 modifiers.externalKeyword = andAdvance;
5121 } 5130 }
5122 } 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)) {
5123 if (modifiers.factoryKeyword != null) { 5132 if (modifiers.factoryKeyword != null) {
5124 reportError11(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5133 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5125 advance(); 5134 advance();
5126 } else { 5135 } else {
5127 modifiers.factoryKeyword = andAdvance; 5136 modifiers.factoryKeyword = andAdvance;
5128 } 5137 }
5129 } else if (matches(Keyword.FINAL)) { 5138 } else if (matches(Keyword.FINAL)) {
5130 if (modifiers.finalKeyword != null) { 5139 if (modifiers.finalKeyword != null) {
5131 reportError11(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5140 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5132 advance(); 5141 advance();
5133 } else { 5142 } else {
5134 modifiers.finalKeyword = andAdvance; 5143 modifiers.finalKeyword = andAdvance;
5135 } 5144 }
5136 } 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)) {
5137 if (modifiers.staticKeyword != null) { 5146 if (modifiers.staticKeyword != null) {
5138 reportError11(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5147 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5139 advance(); 5148 advance();
5140 } else { 5149 } else {
5141 modifiers.staticKeyword = andAdvance; 5150 modifiers.staticKeyword = andAdvance;
5142 } 5151 }
5143 } else if (matches(Keyword.VAR)) { 5152 } else if (matches(Keyword.VAR)) {
5144 if (modifiers.varKeyword != null) { 5153 if (modifiers.varKeyword != null) {
5145 reportError11(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]); 5154 reportError12(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexe me]);
5146 advance(); 5155 advance();
5147 } else { 5156 } else {
5148 modifiers.varKeyword = andAdvance; 5157 modifiers.varKeyword = andAdvance;
5149 } 5158 }
5150 } else { 5159 } else {
5151 progress = false; 5160 progress = false;
5152 } 5161 }
5153 } 5162 }
5154 return modifiers; 5163 return modifiers;
5155 } 5164 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
5230 * 5239 *
5231 * @return the non-labeled statement that was parsed 5240 * @return the non-labeled statement that was parsed
5232 */ 5241 */
5233 Statement parseNonLabeledStatement() { 5242 Statement parseNonLabeledStatement() {
5234 // TODO(brianwilkerson) Pass the comment and metadata on where appropriate. 5243 // TODO(brianwilkerson) Pass the comment and metadata on where appropriate.
5235 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 5244 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
5236 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 5245 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
5237 if (matches4(peek(), TokenType.STRING)) { 5246 if (matches4(peek(), TokenType.STRING)) {
5238 Token afterString = skipStringLiteral(_currentToken.next); 5247 Token afterString = skipStringLiteral(_currentToken.next);
5239 if (afterString != null && identical(afterString.type, TokenType.COLON)) { 5248 if (afterString != null && identical(afterString.type, TokenType.COLON)) {
5240 return new ExpressionStatement(parseExpression3(), expect2(TokenType.S EMICOLON)); 5249 return new ExpressionStatement(parseExpression4(), expect2(TokenType.S EMICOLON));
5241 } 5250 }
5242 } 5251 }
5243 return parseBlock(); 5252 return parseBlock();
5244 } else if (matches5(TokenType.KEYWORD) && !(_currentToken as KeywordToken).k eyword.isPseudoKeyword) { 5253 } else if (matches5(TokenType.KEYWORD) && !(_currentToken as KeywordToken).k eyword.isPseudoKeyword) {
5245 Keyword keyword = (_currentToken as KeywordToken).keyword; 5254 Keyword keyword = (_currentToken as KeywordToken).keyword;
5246 // 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
5247 if (identical(keyword, Keyword.ASSERT)) { 5256 if (identical(keyword, Keyword.ASSERT)) {
5248 return parseAssertStatement(); 5257 return parseAssertStatement();
5249 } else if (identical(keyword, Keyword.BREAK)) { 5258 } else if (identical(keyword, Keyword.BREAK)) {
5250 return parseBreakStatement(); 5259 return parseBreakStatement();
(...skipping 28 matching lines...) Expand all
5279 return parseFunctionDeclarationStatement2(commentAndMetadata, returnTy pe); 5288 return parseFunctionDeclarationStatement2(commentAndMetadata, returnTy pe);
5280 } else { 5289 } else {
5281 // 5290 //
5282 // We have found an error of some kind. Try to recover. 5291 // We have found an error of some kind. Try to recover.
5283 // 5292 //
5284 if (matchesIdentifier()) { 5293 if (matchesIdentifier()) {
5285 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) { 5294 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) {
5286 // 5295 //
5287 // 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".
5288 // 5297 //
5289 reportError10(ParserErrorCode.VOID_VARIABLE, returnType, []); 5298 reportError11(ParserErrorCode.VOID_VARIABLE, returnType, []);
5290 return parseVariableDeclarationStatement(commentAndMetadata); 5299 return parseVariableDeclarationStatement(commentAndMetadata);
5291 } 5300 }
5292 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 5301 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
5293 // 5302 //
5294 // 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
5295 // variable declaration. 5304 // variable declaration.
5296 // 5305 //
5297 return parseVariableDeclarationStatement2(commentAndMetadata, null, returnType); 5306 return parseVariableDeclarationStatement2(commentAndMetadata, null, returnType);
5298 } 5307 }
5299 reportError11(ParserErrorCode.MISSING_STATEMENT, []); 5308 reportError12(ParserErrorCode.MISSING_STATEMENT, []);
5300 // TODO(brianwilkerson) Recover from this error. 5309 // TODO(brianwilkerson) Recover from this error.
5301 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON)); 5310 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON));
5302 } 5311 }
5303 } else if (identical(keyword, Keyword.CONST)) { 5312 } else if (identical(keyword, Keyword.CONST)) {
5304 if (matchesAny(peek(), [ 5313 if (matchesAny(peek(), [
5305 TokenType.LT, 5314 TokenType.LT,
5306 TokenType.OPEN_CURLY_BRACKET, 5315 TokenType.OPEN_CURLY_BRACKET,
5307 TokenType.OPEN_SQUARE_BRACKET, 5316 TokenType.OPEN_SQUARE_BRACKET,
5308 TokenType.INDEX])) { 5317 TokenType.INDEX])) {
5309 return new ExpressionStatement(parseExpression3(), expect2(TokenType.S EMICOLON)); 5318 return new ExpressionStatement(parseExpression4(), expect2(TokenType.S EMICOLON));
5310 } else if (matches4(peek(), TokenType.IDENTIFIER)) { 5319 } else if (matches4(peek(), TokenType.IDENTIFIER)) {
5311 Token afterType = skipTypeName(peek()); 5320 Token afterType = skipTypeName(peek());
5312 if (afterType != null) { 5321 if (afterType != null) {
5313 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))) {
5314 return new ExpressionStatement(parseExpression3(), expect2(TokenTy pe.SEMICOLON)); 5323 return new ExpressionStatement(parseExpression4(), expect2(TokenTy pe.SEMICOLON));
5315 } 5324 }
5316 } 5325 }
5317 } 5326 }
5318 return parseVariableDeclarationStatement(commentAndMetadata); 5327 return parseVariableDeclarationStatement(commentAndMetadata);
5319 } 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)) {
5320 return new ExpressionStatement(parseExpression3(), expect2(TokenType.SEM ICOLON)); 5329 return new ExpressionStatement(parseExpression4(), expect2(TokenType.SEM ICOLON));
5321 } else { 5330 } else {
5322 // 5331 //
5323 // We have found an error of some kind. Try to recover. 5332 // We have found an error of some kind. Try to recover.
5324 // 5333 //
5325 reportError11(ParserErrorCode.MISSING_STATEMENT, []); 5334 reportError12(ParserErrorCode.MISSING_STATEMENT, []);
5326 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON)); 5335 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON));
5327 } 5336 }
5328 } else if (matches5(TokenType.SEMICOLON)) { 5337 } else if (matches5(TokenType.SEMICOLON)) {
5329 return parseEmptyStatement(); 5338 return parseEmptyStatement();
5330 } else if (isInitializedVariableDeclaration()) { 5339 } else if (isInitializedVariableDeclaration()) {
5331 return parseVariableDeclarationStatement(commentAndMetadata); 5340 return parseVariableDeclarationStatement(commentAndMetadata);
5332 } else if (isFunctionDeclaration()) { 5341 } else if (isFunctionDeclaration()) {
5333 return parseFunctionDeclarationStatement(); 5342 return parseFunctionDeclarationStatement();
5334 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 5343 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
5335 reportError11(ParserErrorCode.MISSING_STATEMENT, []); 5344 reportError12(ParserErrorCode.MISSING_STATEMENT, []);
5336 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON)); 5345 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON));
5337 } else { 5346 } else {
5338 return new ExpressionStatement(parseExpression3(), expect2(TokenType.SEMIC OLON)); 5347 return new ExpressionStatement(parseExpression4(), expect2(TokenType.SEMIC OLON));
5339 } 5348 }
5340 } 5349 }
5341 5350
5342 /** 5351 /**
5343 * Parse an operator declaration. 5352 * Parse an operator declaration.
5344 * 5353 *
5345 * <pre> 5354 * <pre>
5346 * operatorDeclaration ::= 5355 * operatorDeclaration ::=
5347 * operatorSignature (';' | functionBody) 5356 * operatorSignature (';' | functionBody)
5348 * 5357 *
5349 * operatorSignature ::= 5358 * operatorSignature ::=
5350 * 'external'? returnType? 'operator' operator formalParameterList 5359 * 'external'? returnType? 'operator' operator formalParameterList
5351 * </pre> 5360 * </pre>
5352 * 5361 *
5353 * @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
5354 * declaration 5363 * declaration
5355 * @param externalKeyword the 'external' token 5364 * @param externalKeyword the 'external' token
5356 * @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
5357 * type 5366 * type
5358 * @return the operator declaration that was parsed 5367 * @return the operator declaration that was parsed
5359 */ 5368 */
5360 MethodDeclaration parseOperator(CommentAndMetadata commentAndMetadata, Token e xternalKeyword, TypeName returnType) { 5369 MethodDeclaration parseOperator(CommentAndMetadata commentAndMetadata, Token e xternalKeyword, TypeName returnType) {
5361 Token operatorKeyword; 5370 Token operatorKeyword;
5362 if (matches(Keyword.OPERATOR)) { 5371 if (matches(Keyword.OPERATOR)) {
5363 operatorKeyword = andAdvance; 5372 operatorKeyword = andAdvance;
5364 } else { 5373 } else {
5365 reportError12(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToken, []) ; 5374 reportError13(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToken, []) ;
5366 operatorKeyword = createSyntheticToken(Keyword.OPERATOR); 5375 operatorKeyword = createSyntheticToken(Keyword.OPERATOR);
5367 } 5376 }
5368 if (!_currentToken.isUserDefinableOperator) { 5377 if (!_currentToken.isUserDefinableOperator) {
5369 reportError11(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken. lexeme]); 5378 reportError12(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken. lexeme]);
5370 } 5379 }
5371 SimpleIdentifier name = new SimpleIdentifier(andAdvance); 5380 SimpleIdentifier name = new SimpleIdentifier(andAdvance);
5372 if (matches5(TokenType.EQ)) { 5381 if (matches5(TokenType.EQ)) {
5373 Token previous = _currentToken.previous; 5382 Token previous = _currentToken.previous;
5374 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) {
5375 reportError11(ParserErrorCode.INVALID_OPERATOR, ["${previous.lexeme}${_c urrentToken.lexeme}"]); 5384 reportError12(ParserErrorCode.INVALID_OPERATOR, ["${previous.lexeme}${_c urrentToken.lexeme}"]);
5376 advance(); 5385 advance();
5377 } 5386 }
5378 } 5387 }
5379 FormalParameterList parameters = parseFormalParameterList(); 5388 FormalParameterList parameters = parseFormalParameterList();
5380 validateFormalParameterList(parameters); 5389 validateFormalParameterList(parameters);
5381 FunctionBody body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION _BODY, false); 5390 FunctionBody body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION _BODY, false);
5382 if (externalKeyword != null && body is! EmptyFunctionBody) { 5391 if (externalKeyword != null && body is! EmptyFunctionBody) {
5383 reportError11(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, []); 5392 reportError12(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, []);
5384 } 5393 }
5385 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);
5386 } 5395 }
5387 5396
5388 /** 5397 /**
5389 * 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.
5390 * 5399 *
5391 * @return the return type that was parsed 5400 * @return the return type that was parsed
5392 */ 5401 */
5393 TypeName parseOptionalReturnType() { 5402 TypeName parseOptionalReturnType() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
5458 } else { 5467 } else {
5459 operand = parseAssignableSelector(operand, true); 5468 operand = parseAssignableSelector(operand, true);
5460 } 5469 }
5461 } 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));
5462 return operand; 5471 return operand;
5463 } 5472 }
5464 if (!_currentToken.type.isIncrementOperator) { 5473 if (!_currentToken.type.isIncrementOperator) {
5465 return operand; 5474 return operand;
5466 } 5475 }
5467 if (operand is Literal || operand is FunctionExpressionInvocation) { 5476 if (operand is Literal || operand is FunctionExpressionInvocation) {
5468 reportError11(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); 5477 reportError12(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []);
5469 } 5478 }
5470 Token operator = andAdvance; 5479 Token operator = andAdvance;
5471 return new PostfixExpression(operand, operator); 5480 return new PostfixExpression(operand, operator);
5472 } 5481 }
5473 5482
5474 /** 5483 /**
5475 * Parse a primary expression. 5484 * Parse a primary expression.
5476 * 5485 *
5477 * <pre> 5486 * <pre>
5478 * primary ::= 5487 * primary ::=
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
5553 return parsePrefixedIdentifier(); 5562 return parsePrefixedIdentifier();
5554 } else if (matches(Keyword.NEW)) { 5563 } else if (matches(Keyword.NEW)) {
5555 return parseNewExpression(); 5564 return parseNewExpression();
5556 } else if (matches(Keyword.CONST)) { 5565 } else if (matches(Keyword.CONST)) {
5557 return parseConstExpression(); 5566 return parseConstExpression();
5558 } else if (matches5(TokenType.OPEN_PAREN)) { 5567 } else if (matches5(TokenType.OPEN_PAREN)) {
5559 if (isFunctionExpression(_currentToken)) { 5568 if (isFunctionExpression(_currentToken)) {
5560 return parseFunctionExpression(); 5569 return parseFunctionExpression();
5561 } 5570 }
5562 Token leftParenthesis = andAdvance; 5571 Token leftParenthesis = andAdvance;
5563 Expression expression = parseExpression3(); 5572 Expression expression = parseExpression4();
5564 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 5573 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
5565 return new ParenthesizedExpression(leftParenthesis, expression, rightParen thesis); 5574 return new ParenthesizedExpression(leftParenthesis, expression, rightParen thesis);
5566 } else if (matches5(TokenType.LT)) { 5575 } else if (matches5(TokenType.LT)) {
5567 return parseListOrMapLiteral(null); 5576 return parseListOrMapLiteral(null);
5568 } else if (matches5(TokenType.QUESTION)) { 5577 } else if (matches5(TokenType.QUESTION)) {
5569 return parseArgumentDefinitionTest(); 5578 return parseArgumentDefinitionTest();
5570 } else if (matches(Keyword.VOID)) { 5579 } else if (matches(Keyword.VOID)) {
5571 // 5580 //
5572 // 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.
5573 // 5582 //
5574 // TODO(brianwilkerson) Improve this error message. 5583 // TODO(brianwilkerson) Improve this error message.
5575 reportError11(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]); 5584 reportError12(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]);
5576 advance(); 5585 advance();
5577 return parsePrimaryExpression(); 5586 return parsePrimaryExpression();
5578 } else if (matches5(TokenType.HASH)) { 5587 } else if (matches5(TokenType.HASH)) {
5579 return parseSymbolLiteral(); 5588 return parseSymbolLiteral();
5580 } else { 5589 } else {
5581 reportError11(ParserErrorCode.MISSING_IDENTIFIER, []); 5590 reportError12(ParserErrorCode.MISSING_IDENTIFIER, []);
5582 return createSyntheticIdentifier(); 5591 return createSyntheticIdentifier();
5583 } 5592 }
5584 } 5593 }
5585 5594
5586 /** 5595 /**
5587 * Parse a redirecting constructor invocation. 5596 * Parse a redirecting constructor invocation.
5588 * 5597 *
5589 * <pre> 5598 * <pre>
5590 * redirectingConstructorInvocation ::= 5599 * redirectingConstructorInvocation ::=
5591 * 'this' ('.' identifier)? arguments 5600 * 'this' ('.' identifier)? arguments
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
5661 * 'return' expression? ';' 5670 * 'return' expression? ';'
5662 * </pre> 5671 * </pre>
5663 * 5672 *
5664 * @return the return statement that was parsed 5673 * @return the return statement that was parsed
5665 */ 5674 */
5666 Statement parseReturnStatement() { 5675 Statement parseReturnStatement() {
5667 Token returnKeyword = expect(Keyword.RETURN); 5676 Token returnKeyword = expect(Keyword.RETURN);
5668 if (matches5(TokenType.SEMICOLON)) { 5677 if (matches5(TokenType.SEMICOLON)) {
5669 return new ReturnStatement(returnKeyword, null, andAdvance); 5678 return new ReturnStatement(returnKeyword, null, andAdvance);
5670 } 5679 }
5671 Expression expression = parseExpression3(); 5680 Expression expression = parseExpression4();
5672 Token semicolon = expect2(TokenType.SEMICOLON); 5681 Token semicolon = expect2(TokenType.SEMICOLON);
5673 return new ReturnStatement(returnKeyword, expression, semicolon); 5682 return new ReturnStatement(returnKeyword, expression, semicolon);
5674 } 5683 }
5675 5684
5676 /** 5685 /**
5677 * Parse a setter. 5686 * Parse a setter.
5678 * 5687 *
5679 * <pre> 5688 * <pre>
5680 * setter ::= 5689 * setter ::=
5681 * setterSignature functionBody? 5690 * setterSignature functionBody?
(...skipping 10 matching lines...) Expand all
5692 * type 5701 * type
5693 * @return the setter that was parsed 5702 * @return the setter that was parsed
5694 */ 5703 */
5695 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) { 5704 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) {
5696 Token propertyKeyword = expect(Keyword.SET); 5705 Token propertyKeyword = expect(Keyword.SET);
5697 SimpleIdentifier name = parseSimpleIdentifier(); 5706 SimpleIdentifier name = parseSimpleIdentifier();
5698 FormalParameterList parameters = parseFormalParameterList(); 5707 FormalParameterList parameters = parseFormalParameterList();
5699 validateFormalParameterList(parameters); 5708 validateFormalParameterList(parameters);
5700 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);
5701 if (externalKeyword != null && body is! EmptyFunctionBody) { 5710 if (externalKeyword != null && body is! EmptyFunctionBody) {
5702 reportError11(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []); 5711 reportError12(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []);
5703 } 5712 }
5704 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);
5705 } 5714 }
5706 5715
5707 /** 5716 /**
5708 * Parse a shift expression. 5717 * Parse a shift expression.
5709 * 5718 *
5710 * <pre> 5719 * <pre>
5711 * shiftExpression ::= 5720 * shiftExpression ::=
5712 * additiveExpression (shiftOperator additiveExpression)* 5721 * additiveExpression (shiftOperator additiveExpression)*
(...skipping 25 matching lines...) Expand all
5738 * </pre> 5747 * </pre>
5739 * 5748 *
5740 * @return the statements that were parsed 5749 * @return the statements that were parsed
5741 */ 5750 */
5742 List<Statement> parseStatements2() { 5751 List<Statement> parseStatements2() {
5743 List<Statement> statements = new List<Statement>(); 5752 List<Statement> statements = new List<Statement>();
5744 Token statementStart = _currentToken; 5753 Token statementStart = _currentToken;
5745 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && !isSwitchMember()) { 5754 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && !isSwitchMember()) {
5746 statements.add(parseStatement2()); 5755 statements.add(parseStatement2());
5747 if (identical(_currentToken, statementStart)) { 5756 if (identical(_currentToken, statementStart)) {
5748 reportError12(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 5757 reportError13(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
5749 advance(); 5758 advance();
5750 } 5759 }
5751 statementStart = _currentToken; 5760 statementStart = _currentToken;
5752 } 5761 }
5753 return statements; 5762 return statements;
5754 } 5763 }
5755 5764
5756 /** 5765 /**
5757 * Parse a string literal that contains interpolations. 5766 * Parse a string literal that contains interpolations.
5758 * 5767 *
5759 * @return the string literal that was parsed 5768 * @return the string literal that was parsed
5760 */ 5769 */
5761 StringInterpolation parseStringInterpolation(Token string) { 5770 StringInterpolation parseStringInterpolation(Token string) {
5762 List<InterpolationElement> elements = new List<InterpolationElement>(); 5771 List<InterpolationElement> elements = new List<InterpolationElement>();
5763 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);
5764 elements.add(new InterpolationString(string, computeStringValue(string.lexem e, true, !hasMore))); 5773 elements.add(new InterpolationString(string, computeStringValue(string.lexem e, true, !hasMore)));
5765 while (hasMore) { 5774 while (hasMore) {
5766 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION)) { 5775 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION)) {
5767 Token openToken = andAdvance; 5776 Token openToken = andAdvance;
5768 Expression expression = parseExpression3(); 5777 Expression expression = parseExpression4();
5769 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 5778 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
5770 elements.add(new InterpolationExpression(openToken, expression, rightBra cket)); 5779 elements.add(new InterpolationExpression(openToken, expression, rightBra cket));
5771 } else { 5780 } else {
5772 Token openToken = andAdvance; 5781 Token openToken = andAdvance;
5773 Expression expression = null; 5782 Expression expression = null;
5774 if (matches(Keyword.THIS)) { 5783 if (matches(Keyword.THIS)) {
5775 expression = new ThisExpression(andAdvance); 5784 expression = new ThisExpression(andAdvance);
5776 } else { 5785 } else {
5777 expression = parseSimpleIdentifier(); 5786 expression = parseSimpleIdentifier();
5778 } 5787 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
5825 * 5834 *
5826 * @return the switch statement that was parsed 5835 * @return the switch statement that was parsed
5827 */ 5836 */
5828 SwitchStatement parseSwitchStatement() { 5837 SwitchStatement parseSwitchStatement() {
5829 bool wasInSwitch = _inSwitch; 5838 bool wasInSwitch = _inSwitch;
5830 _inSwitch = true; 5839 _inSwitch = true;
5831 try { 5840 try {
5832 Set<String> definedLabels = new Set<String>(); 5841 Set<String> definedLabels = new Set<String>();
5833 Token keyword = expect(Keyword.SWITCH); 5842 Token keyword = expect(Keyword.SWITCH);
5834 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 5843 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
5835 Expression expression = parseExpression3(); 5844 Expression expression = parseExpression4();
5836 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 5845 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
5837 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 5846 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET);
5838 Token defaultKeyword = null; 5847 Token defaultKeyword = null;
5839 List<SwitchMember> members = new List<SwitchMember>(); 5848 List<SwitchMember> members = new List<SwitchMember>();
5840 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET )) { 5849 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET )) {
5841 List<Label> labels = new List<Label>(); 5850 List<Label> labels = new List<Label>();
5842 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 5851 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) {
5843 SimpleIdentifier identifier = parseSimpleIdentifier(); 5852 SimpleIdentifier identifier = parseSimpleIdentifier();
5844 String label = identifier.token.lexeme; 5853 String label = identifier.token.lexeme;
5845 if (definedLabels.contains(label)) { 5854 if (definedLabels.contains(label)) {
5846 reportError12(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, i dentifier.token, [label]); 5855 reportError13(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, i dentifier.token, [label]);
5847 } else { 5856 } else {
5848 definedLabels.add(label); 5857 definedLabels.add(label);
5849 } 5858 }
5850 Token colon = expect2(TokenType.COLON); 5859 Token colon = expect2(TokenType.COLON);
5851 labels.add(new Label(identifier, colon)); 5860 labels.add(new Label(identifier, colon));
5852 } 5861 }
5853 if (matches(Keyword.CASE)) { 5862 if (matches(Keyword.CASE)) {
5854 Token caseKeyword = andAdvance; 5863 Token caseKeyword = andAdvance;
5855 Expression caseExpression = parseExpression3(); 5864 Expression caseExpression = parseExpression4();
5856 Token colon = expect2(TokenType.COLON); 5865 Token colon = expect2(TokenType.COLON);
5857 members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon, parseStatements2())); 5866 members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon, parseStatements2()));
5858 if (defaultKeyword != null) { 5867 if (defaultKeyword != null) {
5859 reportError12(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, ca seKeyword, []); 5868 reportError13(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, ca seKeyword, []);
5860 } 5869 }
5861 } else if (matches(Keyword.DEFAULT)) { 5870 } else if (matches(Keyword.DEFAULT)) {
5862 if (defaultKeyword != null) { 5871 if (defaultKeyword != null) {
5863 reportError12(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, pee k(), []); 5872 reportError13(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, pee k(), []);
5864 } 5873 }
5865 defaultKeyword = andAdvance; 5874 defaultKeyword = andAdvance;
5866 Token colon = expect2(TokenType.COLON); 5875 Token colon = expect2(TokenType.COLON);
5867 members.add(new SwitchDefault(labels, defaultKeyword, colon, parseStat ements2())); 5876 members.add(new SwitchDefault(labels, defaultKeyword, colon, parseStat ements2()));
5868 } else { 5877 } else {
5869 // 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
5870 // lot smarter about recovering from the error. 5879 // lot smarter about recovering from the error.
5871 reportError11(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []); 5880 reportError12(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []);
5872 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)) {
5873 advance(); 5882 advance();
5874 } 5883 }
5875 } 5884 }
5876 } 5885 }
5877 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 5886 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
5878 return new SwitchStatement(keyword, leftParenthesis, expression, rightPare nthesis, leftBracket, members, rightBracket); 5887 return new SwitchStatement(keyword, leftParenthesis, expression, rightPare nthesis, leftBracket, members, rightBracket);
5879 } finally { 5888 } finally {
5880 _inSwitch = wasInSwitch; 5889 _inSwitch = wasInSwitch;
5881 } 5890 }
(...skipping 12 matching lines...) Expand all
5894 SymbolLiteral parseSymbolLiteral() { 5903 SymbolLiteral parseSymbolLiteral() {
5895 Token poundSign = andAdvance; 5904 Token poundSign = andAdvance;
5896 List<Token> components = new List<Token>(); 5905 List<Token> components = new List<Token>();
5897 if (matchesIdentifier()) { 5906 if (matchesIdentifier()) {
5898 components.add(andAdvance); 5907 components.add(andAdvance);
5899 while (matches5(TokenType.PERIOD)) { 5908 while (matches5(TokenType.PERIOD)) {
5900 advance(); 5909 advance();
5901 if (matchesIdentifier()) { 5910 if (matchesIdentifier()) {
5902 components.add(andAdvance); 5911 components.add(andAdvance);
5903 } else { 5912 } else {
5904 reportError11(ParserErrorCode.MISSING_IDENTIFIER, []); 5913 reportError12(ParserErrorCode.MISSING_IDENTIFIER, []);
5905 components.add(createSyntheticToken2(TokenType.IDENTIFIER)); 5914 components.add(createSyntheticToken2(TokenType.IDENTIFIER));
5906 break; 5915 break;
5907 } 5916 }
5908 } 5917 }
5909 } else if (_currentToken.isOperator) { 5918 } else if (_currentToken.isOperator) {
5910 components.add(andAdvance); 5919 components.add(andAdvance);
5911 } else { 5920 } else {
5912 reportError11(ParserErrorCode.MISSING_IDENTIFIER, []); 5921 reportError12(ParserErrorCode.MISSING_IDENTIFIER, []);
5913 components.add(createSyntheticToken2(TokenType.IDENTIFIER)); 5922 components.add(createSyntheticToken2(TokenType.IDENTIFIER));
5914 } 5923 }
5915 return new SymbolLiteral(poundSign, new List.from(components)); 5924 return new SymbolLiteral(poundSign, new List.from(components));
5916 } 5925 }
5917 5926
5918 /** 5927 /**
5919 * Parse a throw expression. 5928 * Parse a throw expression.
5920 * 5929 *
5921 * <pre> 5930 * <pre>
5922 * throwExpression ::= 5931 * throwExpression ::=
5923 * 'throw' expression 5932 * 'throw' expression
5924 * </pre> 5933 * </pre>
5925 * 5934 *
5926 * @return the throw expression that was parsed 5935 * @return the throw expression that was parsed
5927 */ 5936 */
5928 Expression parseThrowExpression() { 5937 Expression parseThrowExpression() {
5929 Token keyword = expect(Keyword.THROW); 5938 Token keyword = expect(Keyword.THROW);
5930 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { 5939 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) {
5931 reportError12(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []); 5940 reportError13(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []);
5932 return new ThrowExpression(keyword, createSyntheticIdentifier()); 5941 return new ThrowExpression(keyword, createSyntheticIdentifier());
5933 } 5942 }
5934 Expression expression = parseExpression3(); 5943 Expression expression = parseExpression4();
5935 return new ThrowExpression(keyword, expression); 5944 return new ThrowExpression(keyword, expression);
5936 } 5945 }
5937 5946
5938 /** 5947 /**
5939 * Parse a throw expression. 5948 * Parse a throw expression.
5940 * 5949 *
5941 * <pre> 5950 * <pre>
5942 * throwExpressionWithoutCascade ::= 5951 * throwExpressionWithoutCascade ::=
5943 * 'throw' expressionWithoutCascade 5952 * 'throw' expressionWithoutCascade
5944 * </pre> 5953 * </pre>
5945 * 5954 *
5946 * @return the throw expression that was parsed 5955 * @return the throw expression that was parsed
5947 */ 5956 */
5948 Expression parseThrowExpressionWithoutCascade() { 5957 Expression parseThrowExpressionWithoutCascade() {
5949 Token keyword = expect(Keyword.THROW); 5958 Token keyword = expect(Keyword.THROW);
5950 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { 5959 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) {
5951 reportError12(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []); 5960 reportError13(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []);
5952 return new ThrowExpression(keyword, createSyntheticIdentifier()); 5961 return new ThrowExpression(keyword, createSyntheticIdentifier());
5953 } 5962 }
5954 Expression expression = parseExpressionWithoutCascade(); 5963 Expression expression = parseExpressionWithoutCascade();
5955 return new ThrowExpression(keyword, expression); 5964 return new ThrowExpression(keyword, expression);
5956 } 5965 }
5957 5966
5958 /** 5967 /**
5959 * Parse a try statement. 5968 * Parse a try statement.
5960 * 5969 *
5961 * <pre> 5970 * <pre>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
6005 } 6014 }
6006 Block catchBody = parseBlock(); 6015 Block catchBody = parseBlock();
6007 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));
6008 } 6017 }
6009 Token finallyKeyword = null; 6018 Token finallyKeyword = null;
6010 if (matches(Keyword.FINALLY)) { 6019 if (matches(Keyword.FINALLY)) {
6011 finallyKeyword = andAdvance; 6020 finallyKeyword = andAdvance;
6012 finallyClause = parseBlock(); 6021 finallyClause = parseBlock();
6013 } else { 6022 } else {
6014 if (catchClauses.isEmpty) { 6023 if (catchClauses.isEmpty) {
6015 reportError11(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []); 6024 reportError12(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []);
6016 } 6025 }
6017 } 6026 }
6018 return new TryStatement(tryKeyword, body, catchClauses, finallyKeyword, fina llyClause); 6027 return new TryStatement(tryKeyword, body, catchClauses, finallyKeyword, fina llyClause);
6019 } 6028 }
6020 6029
6021 /** 6030 /**
6022 * Parse a type alias. 6031 * Parse a type alias.
6023 * 6032 *
6024 * <pre> 6033 * <pre>
6025 * typeAlias ::= 6034 * typeAlias ::=
(...skipping 20 matching lines...) Expand all
6046 * @return the type alias that was parsed 6055 * @return the type alias that was parsed
6047 */ 6056 */
6048 TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) { 6057 TypeAlias parseTypeAlias(CommentAndMetadata commentAndMetadata) {
6049 Token keyword = expect(Keyword.TYPEDEF); 6058 Token keyword = expect(Keyword.TYPEDEF);
6050 if (matchesIdentifier()) { 6059 if (matchesIdentifier()) {
6051 Token next = peek(); 6060 Token next = peek();
6052 if (matches4(next, TokenType.LT)) { 6061 if (matches4(next, TokenType.LT)) {
6053 next = skipTypeParameterList(next); 6062 next = skipTypeParameterList(next);
6054 if (next != null && matches4(next, TokenType.EQ)) { 6063 if (next != null && matches4(next, TokenType.EQ)) {
6055 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, ke yword); 6064 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, ke yword);
6056 reportError12(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword, [] ); 6065 reportError13(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword, [] );
6057 return typeAlias; 6066 return typeAlias;
6058 } 6067 }
6059 } else if (matches4(next, TokenType.EQ)) { 6068 } else if (matches4(next, TokenType.EQ)) {
6060 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, keyw ord); 6069 TypeAlias typeAlias = parseClassTypeAlias(commentAndMetadata, null, keyw ord);
6061 reportError12(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword, []); 6070 reportError13(ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS, keyword, []);
6062 return typeAlias; 6071 return typeAlias;
6063 } 6072 }
6064 } 6073 }
6065 return parseFunctionTypeAlias(commentAndMetadata, keyword); 6074 return parseFunctionTypeAlias(commentAndMetadata, keyword);
6066 } 6075 }
6067 6076
6068 /** 6077 /**
6069 * Parse a unary expression. 6078 * Parse a unary expression.
6070 * 6079 *
6071 * <pre> 6080 * <pre>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
6108 if (identical(operator.type, TokenType.MINUS_MINUS)) { 6117 if (identical(operator.type, TokenType.MINUS_MINUS)) {
6109 int offset = operator.offset; 6118 int offset = operator.offset;
6110 Token firstOperator = new Token(TokenType.MINUS, offset); 6119 Token firstOperator = new Token(TokenType.MINUS, offset);
6111 Token secondOperator = new Token(TokenType.MINUS, offset + 1); 6120 Token secondOperator = new Token(TokenType.MINUS, offset + 1);
6112 secondOperator.setNext(_currentToken); 6121 secondOperator.setNext(_currentToken);
6113 firstOperator.setNext(secondOperator); 6122 firstOperator.setNext(secondOperator);
6114 operator.previous.setNext(firstOperator); 6123 operator.previous.setNext(firstOperator);
6115 return new PrefixExpression(firstOperator, new PrefixExpression(second Operator, new SuperExpression(andAdvance))); 6124 return new PrefixExpression(firstOperator, new PrefixExpression(second Operator, new SuperExpression(andAdvance)));
6116 } else { 6125 } else {
6117 // Invalid operator before 'super' 6126 // Invalid operator before 'super'
6118 reportError11(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.le xeme]); 6127 reportError12(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.le xeme]);
6119 return new PrefixExpression(operator, new SuperExpression(andAdvance)) ; 6128 return new PrefixExpression(operator, new SuperExpression(andAdvance)) ;
6120 } 6129 }
6121 } 6130 }
6122 return new PrefixExpression(operator, parseAssignableExpression(false)); 6131 return new PrefixExpression(operator, parseAssignableExpression(false));
6123 } else if (matches5(TokenType.PLUS)) { 6132 } else if (matches5(TokenType.PLUS)) {
6124 reportError11(ParserErrorCode.MISSING_IDENTIFIER, []); 6133 reportError12(ParserErrorCode.MISSING_IDENTIFIER, []);
6125 return createSyntheticIdentifier(); 6134 return createSyntheticIdentifier();
6126 } 6135 }
6127 return parsePostfixExpression(); 6136 return parsePostfixExpression();
6128 } 6137 }
6129 6138
6130 /** 6139 /**
6131 * Parse a variable declaration. 6140 * Parse a variable declaration.
6132 * 6141 *
6133 * <pre> 6142 * <pre>
6134 * variableDeclaration ::= 6143 * variableDeclaration ::=
6135 * identifier ('=' expression)? 6144 * identifier ('=' expression)?
6136 * </pre> 6145 * </pre>
6137 * 6146 *
6138 * @return the variable declaration that was parsed 6147 * @return the variable declaration that was parsed
6139 */ 6148 */
6140 VariableDeclaration parseVariableDeclaration() { 6149 VariableDeclaration parseVariableDeclaration() {
6141 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 6150 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
6142 SimpleIdentifier name = parseSimpleIdentifier(); 6151 SimpleIdentifier name = parseSimpleIdentifier();
6143 Token equals = null; 6152 Token equals = null;
6144 Expression initializer = null; 6153 Expression initializer = null;
6145 if (matches5(TokenType.EQ)) { 6154 if (matches5(TokenType.EQ)) {
6146 equals = andAdvance; 6155 equals = andAdvance;
6147 initializer = parseExpression3(); 6156 initializer = parseExpression4();
6148 } 6157 }
6149 return new VariableDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, name, equals, initializer); 6158 return new VariableDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, name, equals, initializer);
6150 } 6159 }
6151 6160
6152 /** 6161 /**
6153 * Parse a variable declaration list. 6162 * Parse a variable declaration list.
6154 * 6163 *
6155 * <pre> 6164 * <pre>
6156 * variableDeclarationList ::= 6165 * variableDeclarationList ::=
6157 * finalConstVarOrType variableDeclaration (',' variableDeclaration)* 6166 * finalConstVarOrType variableDeclaration (',' variableDeclaration)*
(...skipping 17 matching lines...) Expand all
6175 * 6184 *
6176 * @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
6177 * `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
6178 * @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
6179 * there is no keyword 6188 * there is no keyword
6180 * @param type the type of the variables in the list 6189 * @param type the type of the variables in the list
6181 * @return the variable declaration list that was parsed 6190 * @return the variable declaration list that was parsed
6182 */ 6191 */
6183 VariableDeclarationList parseVariableDeclarationList2(CommentAndMetadata comme ntAndMetadata, Token keyword, TypeName type) { 6192 VariableDeclarationList parseVariableDeclarationList2(CommentAndMetadata comme ntAndMetadata, Token keyword, TypeName type) {
6184 if (type != null && keyword != null && matches3(keyword, Keyword.VAR)) { 6193 if (type != null && keyword != null && matches3(keyword, Keyword.VAR)) {
6185 reportError12(ParserErrorCode.VAR_AND_TYPE, keyword, []); 6194 reportError13(ParserErrorCode.VAR_AND_TYPE, keyword, []);
6186 } 6195 }
6187 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 6196 List<VariableDeclaration> variables = new List<VariableDeclaration>();
6188 variables.add(parseVariableDeclaration()); 6197 variables.add(parseVariableDeclaration());
6189 while (matches5(TokenType.COMMA)) { 6198 while (matches5(TokenType.COMMA)) {
6190 advance(); 6199 advance();
6191 variables.add(parseVariableDeclaration()); 6200 variables.add(parseVariableDeclaration());
6192 } 6201 }
6193 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);
6194 } 6203 }
6195 6204
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
6248 * </pre> 6257 * </pre>
6249 * 6258 *
6250 * @return the while statement that was parsed 6259 * @return the while statement that was parsed
6251 */ 6260 */
6252 Statement parseWhileStatement() { 6261 Statement parseWhileStatement() {
6253 bool wasInLoop = _inLoop; 6262 bool wasInLoop = _inLoop;
6254 _inLoop = true; 6263 _inLoop = true;
6255 try { 6264 try {
6256 Token keyword = expect(Keyword.WHILE); 6265 Token keyword = expect(Keyword.WHILE);
6257 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 6266 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
6258 Expression condition = parseExpression3(); 6267 Expression condition = parseExpression4();
6259 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 6268 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
6260 Statement body = parseStatement2(); 6269 Statement body = parseStatement2();
6261 return new WhileStatement(keyword, leftParenthesis, condition, rightParent hesis, body); 6270 return new WhileStatement(keyword, leftParenthesis, condition, rightParent hesis, body);
6262 } finally { 6271 } finally {
6263 _inLoop = wasInLoop; 6272 _inLoop = wasInLoop;
6264 } 6273 }
6265 } 6274 }
6266 6275
6267 /** 6276 /**
6268 * 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
6299 _errorListener.onError(error); 6308 _errorListener.onError(error);
6300 } 6309 }
6301 6310
6302 /** 6311 /**
6303 * Report an error with the given error code and arguments. 6312 * Report an error with the given error code and arguments.
6304 * 6313 *
6305 * @param errorCode the error code of the error to be reported 6314 * @param errorCode the error code of the error to be reported
6306 * @param node the node specifying the location of the error 6315 * @param node the node specifying the location of the error
6307 * @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
6308 */ 6317 */
6309 void reportError10(ParserErrorCode errorCode, ASTNode node, List<Object> argum ents) { 6318 void reportError11(ParserErrorCode errorCode, ASTNode node, List<Object> argum ents) {
6310 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));
6311 } 6320 }
6312 6321
6313 /** 6322 /**
6314 * Report an error with the given error code and arguments. 6323 * Report an error with the given error code and arguments.
6315 * 6324 *
6316 * @param errorCode the error code of the error to be reported 6325 * @param errorCode the error code of the error to be reported
6317 * @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
6318 */ 6327 */
6319 void reportError11(ParserErrorCode errorCode, List<Object> arguments) { 6328 void reportError12(ParserErrorCode errorCode, List<Object> arguments) {
6320 reportError12(errorCode, _currentToken, arguments); 6329 reportError13(errorCode, _currentToken, arguments);
6321 } 6330 }
6322 6331
6323 /** 6332 /**
6324 * Report an error with the given error code and arguments. 6333 * Report an error with the given error code and arguments.
6325 * 6334 *
6326 * @param errorCode the error code of the error to be reported 6335 * @param errorCode the error code of the error to be reported
6327 * @param token the token specifying the location of the error 6336 * @param token the token specifying the location of the error
6328 * @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
6329 */ 6338 */
6330 void reportError12(ParserErrorCode errorCode, Token token, List<Object> argume nts) { 6339 void reportError13(ParserErrorCode errorCode, Token token, List<Object> argume nts) {
6331 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));
6332 } 6341 }
6333 6342
6334 /** 6343 /**
6335 * Skips a block with all containing blocks. 6344 * Skips a block with all containing blocks.
6336 */ 6345 */
6337 void skipBlock() { 6346 void skipBlock() {
6338 _currentToken = (_currentToken as BeginToken).endToken.next; 6347 _currentToken = (_currentToken as BeginToken).endToken.next;
6339 } 6348 }
6340 6349
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
6801 builder.appendChar(0xC); 6810 builder.appendChar(0xC);
6802 } else if (currentChar == 0x62) { 6811 } else if (currentChar == 0x62) {
6803 builder.appendChar(0x8); 6812 builder.appendChar(0x8);
6804 } else if (currentChar == 0x74) { 6813 } else if (currentChar == 0x74) {
6805 builder.appendChar(0x9); 6814 builder.appendChar(0x9);
6806 } else if (currentChar == 0x76) { 6815 } else if (currentChar == 0x76) {
6807 builder.appendChar(0xB); 6816 builder.appendChar(0xB);
6808 } else if (currentChar == 0x78) { 6817 } else if (currentChar == 0x78) {
6809 if (currentIndex + 2 >= length) { 6818 if (currentIndex + 2 >= length) {
6810 // Illegal escape sequence: not enough hex digits 6819 // Illegal escape sequence: not enough hex digits
6811 reportError11(ParserErrorCode.INVALID_HEX_ESCAPE, []); 6820 reportError12(ParserErrorCode.INVALID_HEX_ESCAPE, []);
6812 return length; 6821 return length;
6813 } 6822 }
6814 int firstDigit = lexeme.codeUnitAt(currentIndex + 1); 6823 int firstDigit = lexeme.codeUnitAt(currentIndex + 1);
6815 int secondDigit = lexeme.codeUnitAt(currentIndex + 2); 6824 int secondDigit = lexeme.codeUnitAt(currentIndex + 2);
6816 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit)) { 6825 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit)) {
6817 // Illegal escape sequence: invalid hex digit 6826 // Illegal escape sequence: invalid hex digit
6818 reportError11(ParserErrorCode.INVALID_HEX_ESCAPE, []); 6827 reportError12(ParserErrorCode.INVALID_HEX_ESCAPE, []);
6819 } else { 6828 } else {
6820 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)));
6821 } 6830 }
6822 return currentIndex + 3; 6831 return currentIndex + 3;
6823 } else if (currentChar == 0x75) { 6832 } else if (currentChar == 0x75) {
6824 currentIndex++; 6833 currentIndex++;
6825 if (currentIndex >= length) { 6834 if (currentIndex >= length) {
6826 // Illegal escape sequence: not enough hex digits 6835 // Illegal escape sequence: not enough hex digits
6827 reportError11(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6836 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6828 return length; 6837 return length;
6829 } 6838 }
6830 currentChar = lexeme.codeUnitAt(currentIndex); 6839 currentChar = lexeme.codeUnitAt(currentIndex);
6831 if (currentChar == 0x7B) { 6840 if (currentChar == 0x7B) {
6832 currentIndex++; 6841 currentIndex++;
6833 if (currentIndex >= length) { 6842 if (currentIndex >= length) {
6834 // Illegal escape sequence: incomplete escape 6843 // Illegal escape sequence: incomplete escape
6835 reportError11(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6844 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6836 return length; 6845 return length;
6837 } 6846 }
6838 currentChar = lexeme.codeUnitAt(currentIndex); 6847 currentChar = lexeme.codeUnitAt(currentIndex);
6839 int digitCount = 0; 6848 int digitCount = 0;
6840 int value = 0; 6849 int value = 0;
6841 while (currentChar != 0x7D) { 6850 while (currentChar != 0x7D) {
6842 if (!isHexDigit(currentChar)) { 6851 if (!isHexDigit(currentChar)) {
6843 // Illegal escape sequence: invalid hex digit 6852 // Illegal escape sequence: invalid hex digit
6844 reportError11(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6853 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6845 currentIndex++; 6854 currentIndex++;
6846 while (currentIndex < length && lexeme.codeUnitAt(currentIndex) != 0 x7D) { 6855 while (currentIndex < length && lexeme.codeUnitAt(currentIndex) != 0 x7D) {
6847 currentIndex++; 6856 currentIndex++;
6848 } 6857 }
6849 return currentIndex + 1; 6858 return currentIndex + 1;
6850 } 6859 }
6851 digitCount++; 6860 digitCount++;
6852 value = (value << 4) + Character.digit(currentChar, 16); 6861 value = (value << 4) + Character.digit(currentChar, 16);
6853 currentIndex++; 6862 currentIndex++;
6854 if (currentIndex >= length) { 6863 if (currentIndex >= length) {
6855 // Illegal escape sequence: incomplete escape 6864 // Illegal escape sequence: incomplete escape
6856 reportError11(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6865 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6857 return length; 6866 return length;
6858 } 6867 }
6859 currentChar = lexeme.codeUnitAt(currentIndex); 6868 currentChar = lexeme.codeUnitAt(currentIndex);
6860 } 6869 }
6861 if (digitCount < 1 || digitCount > 6) { 6870 if (digitCount < 1 || digitCount > 6) {
6862 // Illegal escape sequence: not enough or too many hex digits 6871 // Illegal escape sequence: not enough or too many hex digits
6863 reportError11(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6872 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6864 } 6873 }
6865 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), va lue, index, currentIndex); 6874 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), va lue, index, currentIndex);
6866 return currentIndex + 1; 6875 return currentIndex + 1;
6867 } else { 6876 } else {
6868 if (currentIndex + 3 >= length) { 6877 if (currentIndex + 3 >= length) {
6869 // Illegal escape sequence: not enough hex digits 6878 // Illegal escape sequence: not enough hex digits
6870 reportError11(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6879 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6871 return length; 6880 return length;
6872 } 6881 }
6873 int firstDigit = currentChar; 6882 int firstDigit = currentChar;
6874 int secondDigit = lexeme.codeUnitAt(currentIndex + 1); 6883 int secondDigit = lexeme.codeUnitAt(currentIndex + 1);
6875 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2); 6884 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2);
6876 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3); 6885 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3);
6877 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit) || !isHexDigit(t hirdDigit) || !isHexDigit(fourthDigit)) { 6886 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit) || !isHexDigit(t hirdDigit) || !isHexDigit(fourthDigit)) {
6878 // Illegal escape sequence: invalid hex digits 6887 // Illegal escape sequence: invalid hex digits
6879 reportError11(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 6888 reportError12(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
6880 } else { 6889 } else {
6881 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);
6882 } 6891 }
6883 return currentIndex + 4; 6892 return currentIndex + 4;
6884 } 6893 }
6885 } else { 6894 } else {
6886 builder.appendChar(currentChar); 6895 builder.appendChar(currentChar);
6887 } 6896 }
6888 return currentIndex + 1; 6897 return currentIndex + 1;
6889 } 6898 }
(...skipping 10 matching lines...) Expand all
6900 } 6909 }
6901 6910
6902 /** 6911 /**
6903 * 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.
6904 * 6913 *
6905 * @param parameterList the parameter list to be validated 6914 * @param parameterList the parameter list to be validated
6906 */ 6915 */
6907 void validateFormalParameterList(FormalParameterList parameterList) { 6916 void validateFormalParameterList(FormalParameterList parameterList) {
6908 for (FormalParameter parameter in parameterList.parameters) { 6917 for (FormalParameter parameter in parameterList.parameters) {
6909 if (parameter is FieldFormalParameter) { 6918 if (parameter is FieldFormalParameter) {
6910 reportError10(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, par ameter.identifier, []); 6919 reportError11(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, par ameter.identifier, []);
6911 } 6920 }
6912 } 6921 }
6913 } 6922 }
6914 6923
6915 /** 6924 /**
6916 * 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'
6917 * keyword if there is one. 6926 * keyword if there is one.
6918 * 6927 *
6919 * @param modifiers the modifiers being validated 6928 * @param modifiers the modifiers being validated
6920 */ 6929 */
6921 Token validateModifiersForClass(Modifiers modifiers) { 6930 Token validateModifiersForClass(Modifiers modifiers) {
6922 validateModifiersForTopLevelDeclaration(modifiers); 6931 validateModifiersForTopLevelDeclaration(modifiers);
6923 if (modifiers.constKeyword != null) { 6932 if (modifiers.constKeyword != null) {
6924 reportError12(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); 6933 reportError13(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []);
6925 } 6934 }
6926 if (modifiers.externalKeyword != null) { 6935 if (modifiers.externalKeyword != null) {
6927 reportError12(ParserErrorCode.EXTERNAL_CLASS, modifiers.externalKeyword, [ ]); 6936 reportError13(ParserErrorCode.EXTERNAL_CLASS, modifiers.externalKeyword, [ ]);
6928 } 6937 }
6929 if (modifiers.finalKeyword != null) { 6938 if (modifiers.finalKeyword != null) {
6930 reportError12(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); 6939 reportError13(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []);
6931 } 6940 }
6932 if (modifiers.varKeyword != null) { 6941 if (modifiers.varKeyword != null) {
6933 reportError12(ParserErrorCode.VAR_CLASS, modifiers.varKeyword, []); 6942 reportError13(ParserErrorCode.VAR_CLASS, modifiers.varKeyword, []);
6934 } 6943 }
6935 return modifiers.abstractKeyword; 6944 return modifiers.abstractKeyword;
6936 } 6945 }
6937 6946
6938 /** 6947 /**
6939 * 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
6940 * 'const' keyword if there is one. 6949 * 'const' keyword if there is one.
6941 * 6950 *
6942 * @param modifiers the modifiers being validated 6951 * @param modifiers the modifiers being validated
6943 * @return the 'const' or 'final' keyword associated with the constructor 6952 * @return the 'const' or 'final' keyword associated with the constructor
6944 */ 6953 */
6945 Token validateModifiersForConstructor(Modifiers modifiers) { 6954 Token validateModifiersForConstructor(Modifiers modifiers) {
6946 if (modifiers.abstractKeyword != null) { 6955 if (modifiers.abstractKeyword != null) {
6947 reportError11(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 6956 reportError12(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []);
6948 } 6957 }
6949 if (modifiers.finalKeyword != null) { 6958 if (modifiers.finalKeyword != null) {
6950 reportError12(ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKeyword, [ ]); 6959 reportError13(ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKeyword, [ ]);
6951 } 6960 }
6952 if (modifiers.staticKeyword != null) { 6961 if (modifiers.staticKeyword != null) {
6953 reportError12(ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticKeyword, []); 6962 reportError13(ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticKeyword, []);
6954 } 6963 }
6955 if (modifiers.varKeyword != null) { 6964 if (modifiers.varKeyword != null) {
6956 reportError12(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, modifiers.varK eyword, []); 6965 reportError13(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, modifiers.varK eyword, []);
6957 } 6966 }
6958 Token externalKeyword = modifiers.externalKeyword; 6967 Token externalKeyword = modifiers.externalKeyword;
6959 Token constKeyword = modifiers.constKeyword; 6968 Token constKeyword = modifiers.constKeyword;
6960 Token factoryKeyword = modifiers.factoryKeyword; 6969 Token factoryKeyword = modifiers.factoryKeyword;
6961 if (externalKeyword != null && constKeyword != null && constKeyword.offset < externalKeyword.offset) { 6970 if (externalKeyword != null && constKeyword != null && constKeyword.offset < externalKeyword.offset) {
6962 reportError12(ParserErrorCode.EXTERNAL_AFTER_CONST, externalKeyword, []); 6971 reportError13(ParserErrorCode.EXTERNAL_AFTER_CONST, externalKeyword, []);
6963 } 6972 }
6964 if (externalKeyword != null && factoryKeyword != null && factoryKeyword.offs et < externalKeyword.offset) { 6973 if (externalKeyword != null && factoryKeyword != null && factoryKeyword.offs et < externalKeyword.offset) {
6965 reportError12(ParserErrorCode.EXTERNAL_AFTER_FACTORY, externalKeyword, []) ; 6974 reportError13(ParserErrorCode.EXTERNAL_AFTER_FACTORY, externalKeyword, []) ;
6966 } 6975 }
6967 return constKeyword; 6976 return constKeyword;
6968 } 6977 }
6969 6978
6970 /** 6979 /**
6971 * 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',
6972 * 'const' or 'var' keyword if there is one. 6981 * 'const' or 'var' keyword if there is one.
6973 * 6982 *
6974 * @param modifiers the modifiers being validated 6983 * @param modifiers the modifiers being validated
6975 * @return the 'final', 'const' or 'var' keyword associated with the field 6984 * @return the 'final', 'const' or 'var' keyword associated with the field
6976 */ 6985 */
6977 Token validateModifiersForField(Modifiers modifiers) { 6986 Token validateModifiersForField(Modifiers modifiers) {
6978 if (modifiers.abstractKeyword != null) { 6987 if (modifiers.abstractKeyword != null) {
6979 reportError11(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 6988 reportError12(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []);
6980 } 6989 }
6981 if (modifiers.externalKeyword != null) { 6990 if (modifiers.externalKeyword != null) {
6982 reportError12(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, [ ]); 6991 reportError13(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, [ ]);
6983 } 6992 }
6984 if (modifiers.factoryKeyword != null) { 6993 if (modifiers.factoryKeyword != null) {
6985 reportError12(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []); 6994 reportError13(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []);
6986 } 6995 }
6987 Token staticKeyword = modifiers.staticKeyword; 6996 Token staticKeyword = modifiers.staticKeyword;
6988 Token constKeyword = modifiers.constKeyword; 6997 Token constKeyword = modifiers.constKeyword;
6989 Token finalKeyword = modifiers.finalKeyword; 6998 Token finalKeyword = modifiers.finalKeyword;
6990 Token varKeyword = modifiers.varKeyword; 6999 Token varKeyword = modifiers.varKeyword;
6991 if (constKeyword != null) { 7000 if (constKeyword != null) {
6992 if (finalKeyword != null) { 7001 if (finalKeyword != null) {
6993 reportError12(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []); 7002 reportError13(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []);
6994 } 7003 }
6995 if (varKeyword != null) { 7004 if (varKeyword != null) {
6996 reportError12(ParserErrorCode.CONST_AND_VAR, varKeyword, []); 7005 reportError13(ParserErrorCode.CONST_AND_VAR, varKeyword, []);
6997 } 7006 }
6998 if (staticKeyword != null && constKeyword.offset < staticKeyword.offset) { 7007 if (staticKeyword != null && constKeyword.offset < staticKeyword.offset) {
6999 reportError12(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword, []); 7008 reportError13(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword, []);
7000 } 7009 }
7001 } else if (finalKeyword != null) { 7010 } else if (finalKeyword != null) {
7002 if (varKeyword != null) { 7011 if (varKeyword != null) {
7003 reportError12(ParserErrorCode.FINAL_AND_VAR, varKeyword, []); 7012 reportError13(ParserErrorCode.FINAL_AND_VAR, varKeyword, []);
7004 } 7013 }
7005 if (staticKeyword != null && finalKeyword.offset < staticKeyword.offset) { 7014 if (staticKeyword != null && finalKeyword.offset < staticKeyword.offset) {
7006 reportError12(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword, []); 7015 reportError13(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword, []);
7007 } 7016 }
7008 } else if (varKeyword != null && staticKeyword != null && varKeyword.offset < staticKeyword.offset) { 7017 } else if (varKeyword != null && staticKeyword != null && varKeyword.offset < staticKeyword.offset) {
7009 reportError12(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword, []); 7018 reportError13(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword, []);
7010 } 7019 }
7011 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]); 7020 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]);
7012 } 7021 }
7013 7022
7014 /** 7023 /**
7015 * 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.
7016 * 7025 *
7017 * @param modifiers the modifiers being validated 7026 * @param modifiers the modifiers being validated
7018 */ 7027 */
7019 void validateModifiersForFunctionDeclarationStatement(Modifiers modifiers) { 7028 void validateModifiersForFunctionDeclarationStatement(Modifiers modifiers) {
7020 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) {
7021 reportError11(ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER, []); 7030 reportError12(ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER, []);
7022 } 7031 }
7023 } 7032 }
7024 7033
7025 /** 7034 /**
7026 * 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.
7027 * 7036 *
7028 * @param modifiers the modifiers being validated 7037 * @param modifiers the modifiers being validated
7029 */ 7038 */
7030 void validateModifiersForGetterOrSetterOrMethod(Modifiers modifiers) { 7039 void validateModifiersForGetterOrSetterOrMethod(Modifiers modifiers) {
7031 if (modifiers.abstractKeyword != null) { 7040 if (modifiers.abstractKeyword != null) {
7032 reportError11(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 7041 reportError12(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []);
7033 } 7042 }
7034 if (modifiers.constKeyword != null) { 7043 if (modifiers.constKeyword != null) {
7035 reportError12(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); 7044 reportError13(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []);
7036 } 7045 }
7037 if (modifiers.factoryKeyword != null) { 7046 if (modifiers.factoryKeyword != null) {
7038 reportError12(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []); 7047 reportError13(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []);
7039 } 7048 }
7040 if (modifiers.finalKeyword != null) { 7049 if (modifiers.finalKeyword != null) {
7041 reportError12(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); 7050 reportError13(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []);
7042 } 7051 }
7043 if (modifiers.varKeyword != null) { 7052 if (modifiers.varKeyword != null) {
7044 reportError12(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); 7053 reportError13(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []);
7045 } 7054 }
7046 Token externalKeyword = modifiers.externalKeyword; 7055 Token externalKeyword = modifiers.externalKeyword;
7047 Token staticKeyword = modifiers.staticKeyword; 7056 Token staticKeyword = modifiers.staticKeyword;
7048 if (externalKeyword != null && staticKeyword != null && staticKeyword.offset < externalKeyword.offset) { 7057 if (externalKeyword != null && staticKeyword != null && staticKeyword.offset < externalKeyword.offset) {
7049 reportError12(ParserErrorCode.EXTERNAL_AFTER_STATIC, externalKeyword, []); 7058 reportError13(ParserErrorCode.EXTERNAL_AFTER_STATIC, externalKeyword, []);
7050 } 7059 }
7051 } 7060 }
7052 7061
7053 /** 7062 /**
7054 * 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.
7055 * 7064 *
7056 * @param modifiers the modifiers being validated 7065 * @param modifiers the modifiers being validated
7057 */ 7066 */
7058 void validateModifiersForOperator(Modifiers modifiers) { 7067 void validateModifiersForOperator(Modifiers modifiers) {
7059 if (modifiers.abstractKeyword != null) { 7068 if (modifiers.abstractKeyword != null) {
7060 reportError11(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []); 7069 reportError12(ParserErrorCode.ABSTRACT_CLASS_MEMBER, []);
7061 } 7070 }
7062 if (modifiers.constKeyword != null) { 7071 if (modifiers.constKeyword != null) {
7063 reportError12(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []); 7072 reportError13(ParserErrorCode.CONST_METHOD, modifiers.constKeyword, []);
7064 } 7073 }
7065 if (modifiers.factoryKeyword != null) { 7074 if (modifiers.factoryKeyword != null) {
7066 reportError12(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []); 7075 reportError13(ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKe yword, []);
7067 } 7076 }
7068 if (modifiers.finalKeyword != null) { 7077 if (modifiers.finalKeyword != null) {
7069 reportError12(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []); 7078 reportError13(ParserErrorCode.FINAL_METHOD, modifiers.finalKeyword, []);
7070 } 7079 }
7071 if (modifiers.staticKeyword != null) { 7080 if (modifiers.staticKeyword != null) {
7072 reportError12(ParserErrorCode.STATIC_OPERATOR, modifiers.staticKeyword, [] ); 7081 reportError13(ParserErrorCode.STATIC_OPERATOR, modifiers.staticKeyword, [] );
7073 } 7082 }
7074 if (modifiers.varKeyword != null) { 7083 if (modifiers.varKeyword != null) {
7075 reportError12(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); 7084 reportError13(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []);
7076 } 7085 }
7077 } 7086 }
7078 7087
7079 /** 7088 /**
7080 * 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.
7081 * 7090 *
7082 * @param modifiers the modifiers being validated 7091 * @param modifiers the modifiers being validated
7083 */ 7092 */
7084 void validateModifiersForTopLevelDeclaration(Modifiers modifiers) { 7093 void validateModifiersForTopLevelDeclaration(Modifiers modifiers) {
7085 if (modifiers.factoryKeyword != null) { 7094 if (modifiers.factoryKeyword != null) {
7086 reportError12(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION, modifiers.fac toryKeyword, []); 7095 reportError13(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION, modifiers.fac toryKeyword, []);
7087 } 7096 }
7088 if (modifiers.staticKeyword != null) { 7097 if (modifiers.staticKeyword != null) {
7089 reportError12(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION, modifiers.stat icKeyword, []); 7098 reportError13(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION, modifiers.stat icKeyword, []);
7090 } 7099 }
7091 } 7100 }
7092 7101
7093 /** 7102 /**
7094 * 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.
7095 * 7104 *
7096 * @param modifiers the modifiers being validated 7105 * @param modifiers the modifiers being validated
7097 */ 7106 */
7098 void validateModifiersForTopLevelFunction(Modifiers modifiers) { 7107 void validateModifiersForTopLevelFunction(Modifiers modifiers) {
7099 validateModifiersForTopLevelDeclaration(modifiers); 7108 validateModifiersForTopLevelDeclaration(modifiers);
7100 if (modifiers.abstractKeyword != null) { 7109 if (modifiers.abstractKeyword != null) {
7101 reportError11(ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION, []); 7110 reportError12(ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION, []);
7102 } 7111 }
7103 if (modifiers.constKeyword != null) { 7112 if (modifiers.constKeyword != null) {
7104 reportError12(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []); 7113 reportError13(ParserErrorCode.CONST_CLASS, modifiers.constKeyword, []);
7105 } 7114 }
7106 if (modifiers.finalKeyword != null) { 7115 if (modifiers.finalKeyword != null) {
7107 reportError12(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []); 7116 reportError13(ParserErrorCode.FINAL_CLASS, modifiers.finalKeyword, []);
7108 } 7117 }
7109 if (modifiers.varKeyword != null) { 7118 if (modifiers.varKeyword != null) {
7110 reportError12(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []); 7119 reportError13(ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword, []);
7111 } 7120 }
7112 } 7121 }
7113 7122
7114 /** 7123 /**
7115 * 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',
7116 * 'const' or 'var' keyword if there is one. 7125 * 'const' or 'var' keyword if there is one.
7117 * 7126 *
7118 * @param modifiers the modifiers being validated 7127 * @param modifiers the modifiers being validated
7119 * @return the 'final', 'const' or 'var' keyword associated with the field 7128 * @return the 'final', 'const' or 'var' keyword associated with the field
7120 */ 7129 */
7121 Token validateModifiersForTopLevelVariable(Modifiers modifiers) { 7130 Token validateModifiersForTopLevelVariable(Modifiers modifiers) {
7122 validateModifiersForTopLevelDeclaration(modifiers); 7131 validateModifiersForTopLevelDeclaration(modifiers);
7123 if (modifiers.abstractKeyword != null) { 7132 if (modifiers.abstractKeyword != null) {
7124 reportError11(ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE, []); 7133 reportError12(ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE, []);
7125 } 7134 }
7126 if (modifiers.externalKeyword != null) { 7135 if (modifiers.externalKeyword != null) {
7127 reportError12(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, [ ]); 7136 reportError13(ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword, [ ]);
7128 } 7137 }
7129 Token constKeyword = modifiers.constKeyword; 7138 Token constKeyword = modifiers.constKeyword;
7130 Token finalKeyword = modifiers.finalKeyword; 7139 Token finalKeyword = modifiers.finalKeyword;
7131 Token varKeyword = modifiers.varKeyword; 7140 Token varKeyword = modifiers.varKeyword;
7132 if (constKeyword != null) { 7141 if (constKeyword != null) {
7133 if (finalKeyword != null) { 7142 if (finalKeyword != null) {
7134 reportError12(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []); 7143 reportError13(ParserErrorCode.CONST_AND_FINAL, finalKeyword, []);
7135 } 7144 }
7136 if (varKeyword != null) { 7145 if (varKeyword != null) {
7137 reportError12(ParserErrorCode.CONST_AND_VAR, varKeyword, []); 7146 reportError13(ParserErrorCode.CONST_AND_VAR, varKeyword, []);
7138 } 7147 }
7139 } else if (finalKeyword != null) { 7148 } else if (finalKeyword != null) {
7140 if (varKeyword != null) { 7149 if (varKeyword != null) {
7141 reportError12(ParserErrorCode.FINAL_AND_VAR, varKeyword, []); 7150 reportError13(ParserErrorCode.FINAL_AND_VAR, varKeyword, []);
7142 } 7151 }
7143 } 7152 }
7144 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]); 7153 return lexicallyFirst([constKeyword, finalKeyword, varKeyword]);
7145 } 7154 }
7146 7155
7147 /** 7156 /**
7148 * 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'
7149 * keyword if there is one. 7158 * keyword if there is one.
7150 * 7159 *
7151 * @param modifiers the modifiers being validated 7160 * @param modifiers the modifiers being validated
7152 */ 7161 */
7153 void validateModifiersForTypedef(Modifiers modifiers) { 7162 void validateModifiersForTypedef(Modifiers modifiers) {
7154 validateModifiersForTopLevelDeclaration(modifiers); 7163 validateModifiersForTopLevelDeclaration(modifiers);
7155 if (modifiers.abstractKeyword != null) { 7164 if (modifiers.abstractKeyword != null) {
7156 reportError12(ParserErrorCode.ABSTRACT_TYPEDEF, modifiers.abstractKeyword, []); 7165 reportError13(ParserErrorCode.ABSTRACT_TYPEDEF, modifiers.abstractKeyword, []);
7157 } 7166 }
7158 if (modifiers.constKeyword != null) { 7167 if (modifiers.constKeyword != null) {
7159 reportError12(ParserErrorCode.CONST_TYPEDEF, modifiers.constKeyword, []); 7168 reportError13(ParserErrorCode.CONST_TYPEDEF, modifiers.constKeyword, []);
7160 } 7169 }
7161 if (modifiers.externalKeyword != null) { 7170 if (modifiers.externalKeyword != null) {
7162 reportError12(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalKeyword, []); 7171 reportError13(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalKeyword, []);
7163 } 7172 }
7164 if (modifiers.finalKeyword != null) { 7173 if (modifiers.finalKeyword != null) {
7165 reportError12(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword, []); 7174 reportError13(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword, []);
7166 } 7175 }
7167 if (modifiers.varKeyword != null) { 7176 if (modifiers.varKeyword != null) {
7168 reportError12(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword, []); 7177 reportError13(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword, []);
7169 } 7178 }
7170 } 7179 }
7171 } 7180 }
7172 7181
7173 /** 7182 /**
7174 * Instances of the class `SyntheticKeywordToken` implement a synthetic keyword token. 7183 * Instances of the class `SyntheticKeywordToken` implement a synthetic keyword token.
7175 */ 7184 */
7176 class Parser_SyntheticKeywordToken extends KeywordToken { 7185 class Parser_SyntheticKeywordToken extends KeywordToken {
7177 /** 7186 /**
7178 * Initialize a newly created token to represent the given keyword. 7187 * Initialize a newly created token to represent the given keyword.
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
7601 7610
7602 /** 7611 /**
7603 * The template used to create the message to be displayed for this error. 7612 * The template used to create the message to be displayed for this error.
7604 */ 7613 */
7605 String _message; 7614 String _message;
7606 7615
7607 /** 7616 /**
7608 * The template used to create the correction to be displayed for this error, or `null` if 7617 * The template used to create the correction to be displayed for this error, or `null` if
7609 * there is no correction information for this error. 7618 * there is no correction information for this error.
7610 */ 7619 */
7611 String correction9; 7620 String correction8;
7612 7621
7613 /** 7622 /**
7614 * Initialize a newly created error code to have the given severity and messag e. 7623 * Initialize a newly created error code to have the given severity and messag e.
7615 * 7624 *
7616 * @param severity the severity of the error 7625 * @param severity the severity of the error
7617 * @param message the message template used to create the message to be displa yed for the error 7626 * @param message the message template used to create the message to be displa yed for the error
7618 */ 7627 */
7619 ParserErrorCode.con1(String name, int ordinal, ErrorSeverity severity, String message) : super(name, ordinal) { 7628 ParserErrorCode.con1(String name, int ordinal, ErrorSeverity severity, String message) : super(name, ordinal) {
7620 this._severity = severity; 7629 this._severity = severity;
7621 this._message = message; 7630 this._message = message;
7622 } 7631 }
7623 7632
7624 /** 7633 /**
7625 * Initialize a newly created error code to have the given severity, message a nd correction. 7634 * Initialize a newly created error code to have the given severity, message a nd correction.
7626 * 7635 *
7627 * @param severity the severity of the error 7636 * @param severity the severity of the error
7628 * @param message the template used to create the message to be displayed for the error 7637 * @param message the template used to create the message to be displayed for the error
7629 * @param correction the template used to create the correction to be displaye d for the error 7638 * @param correction the template used to create the correction to be displaye d for the error
7630 */ 7639 */
7631 ParserErrorCode.con2(String name, int ordinal, ErrorSeverity severity, String message, String correction) : super(name, ordinal) { 7640 ParserErrorCode.con2(String name, int ordinal, ErrorSeverity severity, String message, String correction) : super(name, ordinal) {
7632 this._severity = severity; 7641 this._severity = severity;
7633 this._message = message; 7642 this._message = message;
7634 this.correction9 = correction; 7643 this.correction8 = correction;
7635 } 7644 }
7636 7645
7637 /** 7646 /**
7638 * Initialize a newly created error code to have the given message and a sever ity of ERROR. 7647 * Initialize a newly created error code to have the given message and a sever ity of ERROR.
7639 * 7648 *
7640 * @param message the message template used to create the message to be displa yed for the error 7649 * @param message the message template used to create the message to be displa yed for the error
7641 */ 7650 */
7642 ParserErrorCode.con3(String name, int ordinal, String message) : this.con1(nam e, ordinal, ErrorSeverity.ERROR, message); 7651 ParserErrorCode.con3(String name, int ordinal, String message) : this.con1(nam e, ordinal, ErrorSeverity.ERROR, message);
7643 7652
7644 String get correction => correction9; 7653 String get correction => correction8;
7645 7654
7646 ErrorSeverity get errorSeverity => _severity; 7655 ErrorSeverity get errorSeverity => _severity;
7647 7656
7648 String get message => _message; 7657 String get message => _message;
7649 7658
7650 ErrorType get type => ErrorType.SYNTACTIC_ERROR; 7659 ErrorType get type => ErrorType.SYNTACTIC_ERROR;
7651 } 7660 }
7652 7661
7653 /** 7662 /**
7654 * Instances of the class `ResolutionCopier` copies resolution information from one AST 7663 * Instances of the class `ResolutionCopier` copies resolution information from one AST
(...skipping 1935 matching lines...) Expand 10 before | Expand all | Expand 10 after
9590 if ("\n" == separator) { 9599 if ("\n" == separator) {
9591 _writer.print("\n"); 9600 _writer.print("\n");
9592 indent(); 9601 indent();
9593 } else if (i > 0) { 9602 } else if (i > 0) {
9594 _writer.print(separator); 9603 _writer.print(separator);
9595 } 9604 }
9596 _writer.print(tokens[i].lexeme); 9605 _writer.print(tokens[i].lexeme);
9597 } 9606 }
9598 } 9607 }
9599 } 9608 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698