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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/scanner/parser.dart

Issue 11878043: Start adding support for mixin application syntax. We now parse the typedef variant of mixin applic… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix broken language test. Created 7 years, 11 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) 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 part of scanner; 5 part of scanner;
6 6
7 /** 7 /**
8 * An event generating parser of Dart programs. This parser expects 8 * An event generating parser of Dart programs. This parser expects
9 * all tokens in a linked list (aka a token stream). 9 * all tokens in a linked list (aka a token stream).
10 * 10 *
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 Token parseTopLevelDeclaration(Token token) { 47 Token parseTopLevelDeclaration(Token token) {
48 token = parseMetadataStar(token); 48 token = parseMetadataStar(token);
49 final String value = token.stringValue; 49 final String value = token.stringValue;
50 if (identical(value, 'interface')) { 50 if (identical(value, 'interface')) {
51 return parseInterface(token); 51 return parseInterface(token);
52 } else if ((identical(value, 'abstract')) || (identical(value, 'class'))) { 52 } else if ((identical(value, 'abstract')) || (identical(value, 'class'))) {
53 return parseClass(token); 53 return parseClass(token);
54 } else if (identical(value, 'typedef')) { 54 } else if (identical(value, 'typedef')) {
55 return parseNamedFunctionAlias(token); 55 return parseTypedef(token);
56 } else if (identical(value, '#')) { 56 } else if (identical(value, '#')) {
57 return parseScriptTags(token); 57 return parseScriptTags(token);
58 } else if (identical(value, 'library')) { 58 } else if (identical(value, 'library')) {
59 return parseLibraryName(token); 59 return parseLibraryName(token);
60 } else if (identical(value, 'import')) { 60 } else if (identical(value, 'import')) {
61 return parseImport(token); 61 return parseImport(token);
62 } else if (identical(value, 'export')) { 62 } else if (identical(value, 'export')) {
63 return parseExport(token); 63 return parseExport(token);
64 } else if (identical(value, 'part')) { 64 } else if (identical(value, 'part')) {
65 return parsePartOrPartOf(token); 65 return parsePartOrPartOf(token);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 token = parseIdentifier(token); 154 token = parseIdentifier(token);
155 int count = 1; 155 int count = 1;
156 while (optional(',', token)) { 156 while (optional(',', token)) {
157 token = parseIdentifier(token.next); 157 token = parseIdentifier(token.next);
158 count++; 158 count++;
159 } 159 }
160 listener.endIdentifierList(count); 160 listener.endIdentifierList(count);
161 return token; 161 return token;
162 } 162 }
163 163
164 /// type (, type)*
165 Token parseTypeList(Token token) {
166 listener.beginTypeList(token);
167 token = parseType(token);
168 int count = 1;
169 while (optional(',', token)) {
170 token = parseType(token.next);
171 count++;
172 }
173 listener.endTypeList(count);
174 return token;
175 }
176
164 Token parsePartOrPartOf(Token token) { 177 Token parsePartOrPartOf(Token token) {
165 assert(optional('part', token)); 178 assert(optional('part', token));
166 if (optional('of', token.next)) { 179 if (optional('of', token.next)) {
167 return parsePartOf(token); 180 return parsePartOf(token);
168 } else { 181 } else {
169 return parsePart(token); 182 return parsePart(token);
170 } 183 }
171 } 184 }
172 185
173 Token parsePart(Token token) { 186 Token parsePart(Token token) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 token = parseInterfaceBody(token); 252 token = parseInterfaceBody(token);
240 listener.endInterface(supertypeCount, interfaceKeyword, 253 listener.endInterface(supertypeCount, interfaceKeyword,
241 extendsKeyword, token); 254 extendsKeyword, token);
242 return token.next; 255 return token.next;
243 } 256 }
244 257
245 Token parseInterfaceBody(Token token) { 258 Token parseInterfaceBody(Token token) {
246 return parseClassBody(token); 259 return parseClassBody(token);
247 } 260 }
248 261
249 Token parseNamedFunctionAlias(Token token) { 262 Token parseTypedef(Token token) {
250 Token typedefKeyword = token; 263 Token typedefKeyword = token;
251 listener.beginFunctionTypeAlias(token); 264 if (optional('=', peekAfterType(token.next))) {
252 token = parseReturnTypeOpt(token.next); 265 listener.beginNamedMixinApplication(token);
253 token = parseIdentifier(token); 266 token = parseIdentifier(token.next);
254 token = parseTypeVariablesOpt(token); 267 token = parseTypeVariablesOpt(token);
255 token = parseFormalParameters(token); 268 token = expect('=', token);
256 listener.endFunctionTypeAlias(typedefKeyword, token); 269 token = parseMixinApplication(token);
270 listener.endNamedMixinApplication(typedefKeyword, token);
271 } else {
272 listener.beginFunctionTypeAlias(token);
273 token = parseReturnTypeOpt(token.next);
274 token = parseIdentifier(token);
275 token = parseTypeVariablesOpt(token);
276 token = parseFormalParameters(token);
277 listener.endFunctionTypeAlias(typedefKeyword, token);
278 }
257 return expect(';', token); 279 return expect(';', token);
258 } 280 }
259 281
282 Token parseMixinApplication(Token token) {
283 listener.beginMixinApplication(token);
284 token = parseModifiers(token);
285 token = parseType(token);
286 token = expect('with', token);
287 token = parseTypeList(token);
288 listener.endMixinApplication();
289 return token;
290 }
291
260 Token parseReturnTypeOpt(Token token) { 292 Token parseReturnTypeOpt(Token token) {
261 if (identical(token.stringValue, 'void')) { 293 if (identical(token.stringValue, 'void')) {
262 listener.handleVoidKeyword(token); 294 listener.handleVoidKeyword(token);
263 return token.next; 295 return token.next;
264 } else { 296 } else {
265 return parseTypeOpt(token); 297 return parseTypeOpt(token);
266 } 298 }
267 } 299 }
268 300
269 Token parseFormalParametersOpt(Token token) { 301 Token parseFormalParametersOpt(Token token) {
(...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 } 2187 }
2156 listener.handleContinueStatement(hasTarget, continueKeyword, token); 2188 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2157 return expectSemicolon(token); 2189 return expectSemicolon(token);
2158 } 2190 }
2159 2191
2160 Token parseEmptyStatement(Token token) { 2192 Token parseEmptyStatement(Token token) {
2161 listener.handleEmptyStatement(token); 2193 listener.handleEmptyStatement(token);
2162 return expectSemicolon(token); 2194 return expectSemicolon(token);
2163 } 2195 }
2164 } 2196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698