Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library fasta.parser.parser; | 5 library fasta.parser.parser; |
| 6 | 6 |
| 7 import '../scanner.dart' show | 7 import '../scanner.dart' show |
| 8 ErrorToken; | 8 ErrorToken; |
| 9 | 9 |
| 10 import '../scanner/recover.dart' show | 10 import '../scanner/recover.dart' show |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 701 } | 701 } |
| 702 Token endBrace = token; | 702 Token endBrace = token; |
| 703 token = expect('}', token); | 703 token = expect('}', token); |
| 704 listener.endEnum(enumKeyword, endBrace, count); | 704 listener.endEnum(enumKeyword, endBrace, count); |
| 705 return token; | 705 return token; |
| 706 } | 706 } |
| 707 | 707 |
| 708 Token parseClassOrNamedMixinApplication(Token token) { | 708 Token parseClassOrNamedMixinApplication(Token token) { |
| 709 Token begin = token; | 709 Token begin = token; |
| 710 Token abstractKeyword; | 710 Token abstractKeyword; |
| 711 Token classKeyword = token; | |
| 711 if (optional('abstract', token)) { | 712 if (optional('abstract', token)) { |
| 712 abstractKeyword = token; | 713 abstractKeyword = token; |
| 713 token = token.next; | 714 token = token.next; |
| 715 classKeyword = token; | |
| 714 } | 716 } |
|
ahe
2017/02/22 05:48:27
How about adding
assert(optional("class", classKe
scheglov
2017/02/22 06:13:27
Done.
| |
| 715 int modifierCount = 0; | 717 int modifierCount = 0; |
| 716 if (abstractKeyword != null) { | 718 if (abstractKeyword != null) { |
| 717 parseModifier(abstractKeyword); | 719 parseModifier(abstractKeyword); |
| 718 modifierCount++; | 720 modifierCount++; |
| 719 } | 721 } |
| 720 listener.handleModifiers(modifierCount); | 722 listener.handleModifiers(modifierCount); |
| 721 bool isMixinApplication = optional('=', peekAfterType(token)); | 723 bool isMixinApplication = optional('=', peekAfterType(token)); |
| 722 Token name = token.next; | 724 Token name = token.next; |
| 723 token = parseIdentifier(name); | 725 token = parseIdentifier(name); |
| 724 | 726 |
| 725 if (isMixinApplication) { | 727 if (isMixinApplication) { |
| 726 listener.beginNamedMixinApplication(begin, name); | 728 listener.beginNamedMixinApplication(begin, name); |
| 727 } else { | 729 } else { |
| 728 listener.beginClassDeclaration(begin, name); | 730 listener.beginClassDeclaration(begin, name); |
| 729 } | 731 } |
| 730 | 732 |
| 731 token = parseTypeVariablesOpt(token); | 733 token = parseTypeVariablesOpt(token); |
| 732 | 734 |
| 733 if (optional('=', token)) { | 735 if (optional('=', token)) { |
| 734 Token equals = token; | 736 Token equals = token; |
| 735 token = token.next; | 737 token = token.next; |
| 736 return parseNamedMixinApplication(token, begin, name, equals); | 738 return parseNamedMixinApplication(token, begin, classKeyword, name, |
| 739 equals); | |
| 737 } else { | 740 } else { |
| 738 return parseClass(token, begin, name); | 741 return parseClass(token, begin, classKeyword, name); |
| 739 } | 742 } |
| 740 } | 743 } |
| 741 | 744 |
| 742 Token parseNamedMixinApplication(Token token, Token begin, Token name, | 745 Token parseNamedMixinApplication(Token token, Token begin, Token classKeyword, |
| 743 Token equals) { | 746 Token name, Token equals) { |
| 744 token = parseMixinApplication(token); | 747 token = parseMixinApplication(token); |
| 745 Token implementsKeyword = null; | 748 Token implementsKeyword = null; |
| 746 if (optional('implements', token)) { | 749 if (optional('implements', token)) { |
| 747 implementsKeyword = token; | 750 implementsKeyword = token; |
| 748 token = parseTypeList(token.next); | 751 token = parseTypeList(token.next); |
| 749 } | 752 } |
| 750 listener.endNamedMixinApplication(begin, equals, implementsKeyword, token); | 753 listener.endNamedMixinApplication(begin, classKeyword, equals, |
| 754 implementsKeyword, token); | |
| 751 return expect(';', token); | 755 return expect(';', token); |
| 752 } | 756 } |
| 753 | 757 |
| 754 Token parseClass(Token token, Token begin, Token name) { | 758 Token parseClass(Token token, Token begin, Token classKeyword, Token name) { |
| 755 Token extendsKeyword; | 759 Token extendsKeyword; |
| 756 if (optional('extends', token)) { | 760 if (optional('extends', token)) { |
| 757 extendsKeyword = token; | 761 extendsKeyword = token; |
| 758 if (optional('with', peekAfterType(token.next))) { | 762 if (optional('with', peekAfterType(token.next))) { |
| 759 token = parseMixinApplication(token.next); | 763 token = parseMixinApplication(token.next); |
| 760 } else { | 764 } else { |
| 761 token = parseType(token.next); | 765 token = parseType(token.next); |
| 762 } | 766 } |
| 763 } else { | 767 } else { |
| 764 extendsKeyword = null; | 768 extendsKeyword = null; |
| 765 listener.handleNoType(token); | 769 listener.handleNoType(token); |
| 766 } | 770 } |
| 767 Token implementsKeyword; | 771 Token implementsKeyword; |
| 768 int interfacesCount = 0; | 772 int interfacesCount = 0; |
| 769 if (optional('implements', token)) { | 773 if (optional('implements', token)) { |
| 770 implementsKeyword = token; | 774 implementsKeyword = token; |
| 771 do { | 775 do { |
| 772 token = parseType(token.next); | 776 token = parseType(token.next); |
| 773 ++interfacesCount; | 777 ++interfacesCount; |
| 774 } while (optional(',', token)); | 778 } while (optional(',', token)); |
| 775 } | 779 } |
| 776 token = parseClassBody(token); | 780 token = parseClassBody(token); |
| 777 listener.endClassDeclaration( | 781 listener.endClassDeclaration( |
| 778 interfacesCount, begin, extendsKeyword, implementsKeyword, token); | 782 interfacesCount, begin, classKeyword, extendsKeyword, |
| 783 implementsKeyword, token); | |
| 779 return token.next; | 784 return token.next; |
| 780 } | 785 } |
| 781 | 786 |
| 782 Token parseStringPart(Token token) { | 787 Token parseStringPart(Token token) { |
| 783 if (token.kind != STRING_TOKEN) { | 788 if (token.kind != STRING_TOKEN) { |
| 784 token = reportUnrecoverableError(token, ErrorKind.ExpectedString); | 789 token = reportUnrecoverableError(token, ErrorKind.ExpectedString); |
| 785 } | 790 } |
| 786 listener.handleStringPart(token); | 791 listener.handleStringPart(token); |
| 787 return token.next; | 792 return token.next; |
| 788 } | 793 } |
| (...skipping 2528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3317 break; | 3322 break; |
| 3318 } | 3323 } |
| 3319 if (isRecoverable) { | 3324 if (isRecoverable) { |
| 3320 listener.handleRecoverableError(token, kind, arguments); | 3325 listener.handleRecoverableError(token, kind, arguments); |
| 3321 return null; | 3326 return null; |
| 3322 } else { | 3327 } else { |
| 3323 return listener.handleUnrecoverableError(token, kind, arguments); | 3328 return listener.handleUnrecoverableError(token, kind, arguments); |
| 3324 } | 3329 } |
| 3325 } | 3330 } |
| 3326 } | 3331 } |
| OLD | NEW |