| 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 part of scanner; | 5 part of scanner; |
| 6 | 6 |
| 7 class FormalParameterType { | 7 class FormalParameterType { |
| 8 final String type; | 8 final String type; |
| 9 const FormalParameterType(this.type); | 9 const FormalParameterType(this.type); |
| 10 bool get isRequired => this == REQUIRED; | 10 bool get isRequired => this == REQUIRED; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 listener.endCompilationUnit(count, token); | 55 listener.endCompilationUnit(count, token); |
| 56 return token; | 56 return token; |
| 57 } | 57 } |
| 58 | 58 |
| 59 Token parseTopLevelDeclaration(Token token) { | 59 Token parseTopLevelDeclaration(Token token) { |
| 60 token = parseMetadataStar(token); | 60 token = parseMetadataStar(token); |
| 61 final String value = token.stringValue; | 61 final String value = token.stringValue; |
| 62 if ((identical(value, 'abstract') && optional('class', token.next)) | 62 if ((identical(value, 'abstract') && optional('class', token.next)) |
| 63 || identical(value, 'class')) { | 63 || identical(value, 'class')) { |
| 64 return parseClass(token); | 64 return parseClassOrNamedMixinApplication(token); |
| 65 } else if (identical(value, 'typedef')) { | 65 } else if (identical(value, 'typedef')) { |
| 66 return parseTypedef(token); | 66 return parseTypedef(token); |
| 67 } else if (identical(value, 'library')) { | 67 } else if (identical(value, 'library')) { |
| 68 return parseLibraryName(token); | 68 return parseLibraryName(token); |
| 69 } else if (identical(value, 'import')) { | 69 } else if (identical(value, 'import')) { |
| 70 return parseImport(token); | 70 return parseImport(token); |
| 71 } else if (identical(value, 'export')) { | 71 } else if (identical(value, 'export')) { |
| 72 return parseExport(token); | 72 return parseExport(token); |
| 73 } else if (identical(value, 'part')) { | 73 } else if (identical(value, 'part')) { |
| 74 return parsePartOrPartOf(token); | 74 return parsePartOrPartOf(token); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 token = parseIdentifier(token.next); | 239 token = parseIdentifier(token.next); |
| 240 } | 240 } |
| 241 token = parseArgumentsOpt(token); | 241 token = parseArgumentsOpt(token); |
| 242 listener.endMetadata(atToken, period, token); | 242 listener.endMetadata(atToken, period, token); |
| 243 return token; | 243 return token; |
| 244 } | 244 } |
| 245 | 245 |
| 246 Token parseTypedef(Token token) { | 246 Token parseTypedef(Token token) { |
| 247 Token typedefKeyword = token; | 247 Token typedefKeyword = token; |
| 248 if (optional('=', peekAfterType(token.next))) { | 248 if (optional('=', peekAfterType(token.next))) { |
| 249 // TODO(aprelev@gmail.com): Remove deprecated 'typedef' mixin application, |
| 250 // remove corresponding diagnostic from members.dart. |
| 249 listener.beginNamedMixinApplication(token); | 251 listener.beginNamedMixinApplication(token); |
| 250 token = parseIdentifier(token.next); | 252 token = parseIdentifier(token.next); |
| 251 token = parseTypeVariablesOpt(token); | 253 token = parseTypeVariablesOpt(token); |
| 252 token = expect('=', token); | 254 token = expect('=', token); |
| 253 token = parseModifiers(token); | 255 token = parseModifiers(token); |
| 254 token = parseMixinApplication(token); | 256 token = parseMixinApplication(token); |
| 255 Token implementsKeyword = null; | 257 Token implementsKeyword = null; |
| 256 if (optional('implements', token)) { | 258 if (optional('implements', token)) { |
| 257 implementsKeyword = token; | 259 implementsKeyword = token; |
| 258 token = parseTypeList(token.next); | 260 token = parseTypeList(token.next); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 BeginGroupToken beginGroupToken = token; | 448 BeginGroupToken beginGroupToken = token; |
| 447 Token endGroup = beginGroupToken.endGroup; | 449 Token endGroup = beginGroupToken.endGroup; |
| 448 if (endGroup == null) { | 450 if (endGroup == null) { |
| 449 return listener.unmatched(beginGroupToken); | 451 return listener.unmatched(beginGroupToken); |
| 450 } else if (!identical(endGroup.kind, $CLOSE_CURLY_BRACKET)) { | 452 } else if (!identical(endGroup.kind, $CLOSE_CURLY_BRACKET)) { |
| 451 return listener.unmatched(beginGroupToken); | 453 return listener.unmatched(beginGroupToken); |
| 452 } | 454 } |
| 453 return beginGroupToken.endGroup; | 455 return beginGroupToken.endGroup; |
| 454 } | 456 } |
| 455 | 457 |
| 456 Token parseClass(Token token) { | 458 Token parseClassOrNamedMixinApplication(Token token) { |
| 457 Token begin = token; | 459 Token begin = token; |
| 458 listener.beginClassDeclaration(token); | 460 Token abstractKeyword; |
| 459 int modifierCount = 0; | |
| 460 if (optional('abstract', token)) { | 461 if (optional('abstract', token)) { |
| 461 listener.handleModifier(token); | 462 abstractKeyword = token; |
| 462 modifierCount++; | |
| 463 token = token.next; | 463 token = token.next; |
| 464 } | 464 } |
| 465 Token classKeyword = token; |
| 466 var isMixinApplication = optional('=', peekAfterType(token.next)); |
| 467 if (isMixinApplication) { |
| 468 listener.beginNamedMixinApplication(begin); |
| 469 token = parseIdentifier(token.next); |
| 470 token = parseTypeVariablesOpt(token); |
| 471 token = expect('=', token); |
| 472 } else { |
| 473 listener.beginClassDeclaration(begin); |
| 474 } |
| 475 |
| 476 // TODO(aprelev@gmail.com): Once 'typedef' named mixin application is |
| 477 // removed, move modifiers for named mixin application to the bottom of |
| 478 // listener stack. This is so stacks for class declaration and named |
| 479 // mixin application look similar. |
| 480 int modifierCount = 0; |
| 481 if (abstractKeyword != null) { |
| 482 parseModifier(abstractKeyword); |
| 483 modifierCount++; |
| 484 } |
| 465 listener.handleModifiers(modifierCount); | 485 listener.handleModifiers(modifierCount); |
| 466 token = parseIdentifier(token.next); | 486 |
| 487 if (isMixinApplication) { |
| 488 return parseNamedMixinApplication(token, classKeyword); |
| 489 } else { |
| 490 return parseClass(begin, classKeyword); |
| 491 } |
| 492 } |
| 493 |
| 494 Token parseNamedMixinApplication(Token token, Token classKeyword) { |
| 495 token = parseMixinApplication(token); |
| 496 Token implementsKeyword = null; |
| 497 if (optional('implements', token)) { |
| 498 implementsKeyword = token; |
| 499 token = parseTypeList(token.next); |
| 500 } |
| 501 listener.endNamedMixinApplication( |
| 502 classKeyword, implementsKeyword, token); |
| 503 return expect(';', token); |
| 504 } |
| 505 |
| 506 Token parseClass(Token begin, Token classKeyword) { |
| 507 Token token = parseIdentifier(classKeyword.next); |
| 467 token = parseTypeVariablesOpt(token); | 508 token = parseTypeVariablesOpt(token); |
| 468 Token extendsKeyword; | 509 Token extendsKeyword; |
| 469 if (optional('extends', token)) { | 510 if (optional('extends', token)) { |
| 470 extendsKeyword = token; | 511 extendsKeyword = token; |
| 471 if (optional('with', peekAfterType(token.next))) { | 512 if (optional('with', peekAfterType(token.next))) { |
| 472 token = parseMixinApplication(token.next); | 513 token = parseMixinApplication(token.next); |
| 473 } else { | 514 } else { |
| 474 token = parseType(token.next); | 515 token = parseType(token.next); |
| 475 } | 516 } |
| 476 } else { | 517 } else { |
| (...skipping 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2392 } | 2433 } |
| 2393 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 2434 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 2394 return expectSemicolon(token); | 2435 return expectSemicolon(token); |
| 2395 } | 2436 } |
| 2396 | 2437 |
| 2397 Token parseEmptyStatement(Token token) { | 2438 Token parseEmptyStatement(Token token) { |
| 2398 listener.handleEmptyStatement(token); | 2439 listener.handleEmptyStatement(token); |
| 2399 return expectSemicolon(token); | 2440 return expectSemicolon(token); |
| 2400 } | 2441 } |
| 2401 } | 2442 } |
| OLD | NEW |