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 '../fasta_codes.dart' show Code, Message, Template; | 7 import '../fasta_codes.dart' show Code, Message, Template; |
| 8 | 8 |
| 9 import '../fasta_codes.dart' as fasta; | 9 import '../fasta_codes.dart' as fasta; |
| 10 | 10 |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 } | 850 } |
| 851 Token implementsKeyword; | 851 Token implementsKeyword; |
| 852 int interfacesCount = 0; | 852 int interfacesCount = 0; |
| 853 if (optional('implements', token)) { | 853 if (optional('implements', token)) { |
| 854 implementsKeyword = token; | 854 implementsKeyword = token; |
| 855 do { | 855 do { |
| 856 token = parseType(token.next); | 856 token = parseType(token.next); |
| 857 ++interfacesCount; | 857 ++interfacesCount; |
| 858 } while (optional(',', token)); | 858 } while (optional(',', token)); |
| 859 } | 859 } |
| 860 Token nativeToken; | |
| 861 if (optional('native', token)) { | |
| 862 nativeToken = token; | |
| 863 token = parseNativeClause(token.next); | |
| 864 reportRecoverableError( | |
| 865 nativeToken, fasta.messageNativeClauseShouldBeAnnotation); | |
| 866 } | |
| 860 token = parseClassBody(token); | 867 token = parseClassBody(token); |
| 861 listener.endClassDeclaration(interfacesCount, begin, classKeyword, | 868 listener.endClassDeclaration(interfacesCount, begin, classKeyword, |
| 862 extendsKeyword, implementsKeyword, token); | 869 extendsKeyword, implementsKeyword, nativeToken, token); |
| 863 return token.next; | 870 return token.next; |
| 864 } | 871 } |
| 865 | 872 |
| 866 Token parseStringPart(Token token) { | 873 Token parseStringPart(Token token) { |
| 867 if (token.kind != STRING_TOKEN) { | 874 if (token.kind != STRING_TOKEN) { |
| 868 token = | 875 token = |
| 869 reportUnrecoverableErrorWithToken(token, fasta.templateExpectedString) | 876 reportUnrecoverableErrorWithToken(token, fasta.templateExpectedString) |
| 870 .next; | 877 .next; |
| 871 } | 878 } |
| 872 listener.handleStringPart(token); | 879 listener.handleStringPart(token); |
| (...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2098 | 2105 |
| 2099 typeContinuation ??= | 2106 typeContinuation ??= |
| 2100 (isVarAllowed || memberKind == MemberKind.GeneralizedFunctionType) | 2107 (isVarAllowed || memberKind == MemberKind.GeneralizedFunctionType) |
| 2101 ? TypeContinuation.Required | 2108 ? TypeContinuation.Required |
| 2102 : TypeContinuation.Optional; | 2109 : TypeContinuation.Optional; |
| 2103 | 2110 |
| 2104 token = parseType(token, typeContinuation, null, memberKind); | 2111 token = parseType(token, typeContinuation, null, memberKind); |
| 2105 return token; | 2112 return token; |
| 2106 } | 2113 } |
| 2107 | 2114 |
| 2115 Token parseNativeClause(Token token) { | |
| 2116 if (!identical(token.kind, STRING_TOKEN)) return token; | |
|
ahe
2017/08/21 12:04:10
We don't need to use identical on token.kind.
danrubel
2017/08/22 01:35:28
Good point. Fixed.
| |
| 2117 return parseSingleLiteralString(token); | |
|
ahe
2017/08/21 12:04:10
We should generate an event here. I'm thinking som
danrubel
2017/08/22 01:35:28
Good point. Per discussion I've added a handleNati
| |
| 2118 } | |
| 2119 | |
| 2108 Token skipClassBody(Token token) { | 2120 Token skipClassBody(Token token) { |
| 2109 if (!optional('{', token)) { | 2121 if (!optional('{', token)) { |
| 2110 return reportUnrecoverableErrorWithToken( | 2122 return reportUnrecoverableErrorWithToken( |
| 2111 token, fasta.templateExpectedClassBodyToSkip) | 2123 token, fasta.templateExpectedClassBodyToSkip) |
| 2112 .next; | 2124 .next; |
| 2113 } | 2125 } |
| 2114 Token closeBrace = closeBraceTokenFor(token); | 2126 Token closeBrace = closeBraceTokenFor(token); |
| 2115 if (closeBrace == null || | 2127 if (closeBrace == null || |
| 2116 !identical(closeBrace.kind, $CLOSE_CURLY_BRACKET)) { | 2128 !identical(closeBrace.kind, $CLOSE_CURLY_BRACKET)) { |
| 2117 return reportUnmatchedToken(token).next; | 2129 return reportUnmatchedToken(token).next; |
| (...skipping 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4065 } | 4077 } |
| 4066 | 4078 |
| 4067 Token reportUnexpectedToken(Token token) { | 4079 Token reportUnexpectedToken(Token token) { |
| 4068 return reportUnrecoverableErrorWithToken( | 4080 return reportUnrecoverableErrorWithToken( |
| 4069 token, fasta.templateUnexpectedToken); | 4081 token, fasta.templateUnexpectedToken); |
| 4070 } | 4082 } |
| 4071 } | 4083 } |
| 4072 | 4084 |
| 4073 // TODO(ahe): Remove when analyzer supports generalized function syntax. | 4085 // TODO(ahe): Remove when analyzer supports generalized function syntax. |
| 4074 typedef _MessageWithArgument<T> = Message Function(T); | 4086 typedef _MessageWithArgument<T> = Message Function(T); |
| OLD | NEW |