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 '../fasta_codes.dart' | 7 import '../fasta_codes.dart' |
8 show | 8 show |
9 FastaCode, | 9 FastaCode, |
10 FastaMessage, | 10 FastaMessage, |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 } else { | 630 } else { |
631 token = afterType; | 631 token = afterType; |
632 token = parseIdentifier(token, IdentifierContext.typedefDeclaration); | 632 token = parseIdentifier(token, IdentifierContext.typedefDeclaration); |
633 token = parseTypeVariablesOpt(token); | 633 token = parseTypeVariablesOpt(token); |
634 token = parseFormalParameters(token, MemberKind.FunctionTypeAlias); | 634 token = parseFormalParameters(token, MemberKind.FunctionTypeAlias); |
635 } | 635 } |
636 listener.endFunctionTypeAlias(typedefKeyword, equals, token); | 636 listener.endFunctionTypeAlias(typedefKeyword, equals, token); |
637 return expect(';', token); | 637 return expect(';', token); |
638 } | 638 } |
639 | 639 |
640 Token parseMixinApplication(Token token) { | 640 /// Parse a mixin application starting from `with`. Assumes that the first |
641 /// type has already been parsed. | |
642 Token parseMixinApplicationRest(Token token) { | |
641 listener.beginMixinApplication(token); | 643 listener.beginMixinApplication(token); |
642 token = parseType(token); | |
643 Token withKeyword = token; | 644 Token withKeyword = token; |
644 token = expect('with', token); | 645 token = expect('with', token); |
645 token = parseTypeList(token); | 646 token = parseTypeList(token); |
646 listener.endMixinApplication(withKeyword); | 647 listener.endMixinApplication(withKeyword); |
647 return token; | 648 return token; |
648 } | 649 } |
649 | 650 |
650 Token parseFormalParametersOpt(Token token, MemberKind kind) { | 651 Token parseFormalParametersOpt(Token token, MemberKind kind) { |
651 if (optional('(', token)) { | 652 if (optional('(', token)) { |
652 return parseFormalParameters(token, kind); | 653 return parseFormalParameters(token, kind); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
995 return parseNamedMixinApplication( | 996 return parseNamedMixinApplication( |
996 token, begin, classKeyword, name, equals); | 997 token, begin, classKeyword, name, equals); |
997 } else { | 998 } else { |
998 listener.beginClassDeclaration(begin, name); | 999 listener.beginClassDeclaration(begin, name); |
999 return parseClass(token, begin, classKeyword, name); | 1000 return parseClass(token, begin, classKeyword, name); |
1000 } | 1001 } |
1001 } | 1002 } |
1002 | 1003 |
1003 Token parseNamedMixinApplication( | 1004 Token parseNamedMixinApplication( |
1004 Token token, Token begin, Token classKeyword, Token name, Token equals) { | 1005 Token token, Token begin, Token classKeyword, Token name, Token equals) { |
1005 token = parseMixinApplication(token); | 1006 token = parseType(token); |
1007 token = parseMixinApplicationRest(token); | |
1006 Token implementsKeyword = null; | 1008 Token implementsKeyword = null; |
1007 if (optional('implements', token)) { | 1009 if (optional('implements', token)) { |
1008 implementsKeyword = token; | 1010 implementsKeyword = token; |
1009 token = parseTypeList(token.next); | 1011 token = parseTypeList(token.next); |
1010 } | 1012 } |
1011 listener.endNamedMixinApplication( | 1013 listener.endNamedMixinApplication( |
1012 begin, classKeyword, equals, implementsKeyword, token); | 1014 begin, classKeyword, equals, implementsKeyword, token); |
1013 return expect(';', token); | 1015 return expect(';', token); |
1014 } | 1016 } |
1015 | 1017 |
1016 Token parseClass(Token token, Token begin, Token classKeyword, Token name) { | 1018 Token parseClass(Token token, Token begin, Token classKeyword, Token name) { |
danrubel
2017/06/24 22:18:51
nit: "name" parameter is never used
ahe
2017/06/26 11:18:16
I'll address this in the next CL. After you pointe
| |
1017 Token extendsKeyword; | 1019 Token extendsKeyword; |
1018 if (optional('extends', token)) { | 1020 if (optional('extends', token)) { |
1019 extendsKeyword = token; | 1021 extendsKeyword = token; |
1020 if (optional('with', peekAfterNominalType(token.next))) { | 1022 token = parseType(token.next); |
1021 token = parseMixinApplication(token.next); | 1023 if (optional('with', token)) { |
1022 } else { | 1024 token = parseMixinApplicationRest(token); |
1023 token = parseType(token.next); | |
1024 } | 1025 } |
1025 } else { | 1026 } else { |
1026 extendsKeyword = null; | 1027 extendsKeyword = null; |
1027 listener.handleNoType(token); | 1028 listener.handleNoType(token); |
1028 } | 1029 } |
1029 Token implementsKeyword; | 1030 Token implementsKeyword; |
1030 int interfacesCount = 0; | 1031 int interfacesCount = 0; |
1031 if (optional('implements', token)) { | 1032 if (optional('implements', token)) { |
1032 implementsKeyword = token; | 1033 implementsKeyword = token; |
1033 do { | 1034 do { |
(...skipping 2998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4032 return reportUnrecoverableError( | 4033 return reportUnrecoverableError( |
4033 token, () => code.format(uri, token.charOffset, string)); | 4034 token, () => code.format(uri, token.charOffset, string)); |
4034 } | 4035 } |
4035 } | 4036 } |
4036 | 4037 |
4037 typedef FastaMessage NoArgument(Uri uri, int charOffset); | 4038 typedef FastaMessage NoArgument(Uri uri, int charOffset); |
4038 | 4039 |
4039 typedef FastaMessage TokenArgument(Uri uri, int charOffset, Token token); | 4040 typedef FastaMessage TokenArgument(Uri uri, int charOffset, Token token); |
4040 | 4041 |
4041 typedef FastaMessage StringArgument(Uri uri, int charOffset, String string); | 4042 typedef FastaMessage StringArgument(Uri uri, int charOffset, String string); |
OLD | NEW |