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

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

Issue 282453004: Dart2js enum parsing. Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Allow trailing comma. Created 6 years, 7 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 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 parseClassOrNamedMixinApplication(token); 64 return parseClassOrNamedMixinApplication(token);
65 } else if (identical(value, 'enum')) {
66 return parseEnum(token);
65 } else if (identical(value, 'typedef')) { 67 } else if (identical(value, 'typedef')) {
66 return parseTypedef(token); 68 return parseTypedef(token);
67 } else if (identical(value, 'library')) { 69 } else if (identical(value, 'library')) {
68 return parseLibraryName(token); 70 return parseLibraryName(token);
69 } else if (identical(value, 'import')) { 71 } else if (identical(value, 'import')) {
70 return parseImport(token); 72 return parseImport(token);
71 } else if (identical(value, 'export')) { 73 } else if (identical(value, 'export')) {
72 return parseExport(token); 74 return parseExport(token);
73 } else if (identical(value, 'part')) { 75 } else if (identical(value, 'part')) {
74 return parsePartOrPartOf(token); 76 return parsePartOrPartOf(token);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 BeginGroupToken beginGroupToken = token; 449 BeginGroupToken beginGroupToken = token;
448 Token endGroup = beginGroupToken.endGroup; 450 Token endGroup = beginGroupToken.endGroup;
449 if (endGroup == null) { 451 if (endGroup == null) {
450 return listener.unmatched(beginGroupToken); 452 return listener.unmatched(beginGroupToken);
451 } else if (!identical(endGroup.kind, $CLOSE_CURLY_BRACKET)) { 453 } else if (!identical(endGroup.kind, $CLOSE_CURLY_BRACKET)) {
452 return listener.unmatched(beginGroupToken); 454 return listener.unmatched(beginGroupToken);
453 } 455 }
454 return beginGroupToken.endGroup; 456 return beginGroupToken.endGroup;
455 } 457 }
456 458
459 Token parseEnum(Token token) {
460 listener.beginEnum(token);
461 Token enumKeyword = token;
462 token = parseIdentifier(token.next);
463 token = expect('{', token);
464 int count = 0;
465 if (!optional('}', token)) {
466 token = parseIdentifier(token);
467 count++;
468 while (optional(',', token)) {
469 token = token.next;
470 if (optional('}', token)) break;
471 token = parseIdentifier(token);
472 count++;
473 }
474 }
475 Token endBrace = token;
476 token = expect('}', token);
477 listener.endEnum(enumKeyword, endBrace, count);
478 return token;
479 }
480
457 Token parseClassOrNamedMixinApplication(Token token) { 481 Token parseClassOrNamedMixinApplication(Token token) {
458 Token begin = token; 482 Token begin = token;
459 Token abstractKeyword; 483 Token abstractKeyword;
460 if (optional('abstract', token)) { 484 if (optional('abstract', token)) {
461 abstractKeyword = token; 485 abstractKeyword = token;
462 token = token.next; 486 token = token.next;
463 } 487 }
464 Token classKeyword = token; 488 Token classKeyword = token;
465 var isMixinApplication = optional('=', peekAfterType(token.next)); 489 var isMixinApplication = optional('=', peekAfterType(token.next));
466 if (isMixinApplication) { 490 if (isMixinApplication) {
(...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after
2445 } 2469 }
2446 listener.handleContinueStatement(hasTarget, continueKeyword, token); 2470 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2447 return expectSemicolon(token); 2471 return expectSemicolon(token);
2448 } 2472 }
2449 2473
2450 Token parseEmptyStatement(Token token) { 2474 Token parseEmptyStatement(Token token) {
2451 listener.handleEmptyStatement(token); 2475 listener.handleEmptyStatement(token);
2452 return expectSemicolon(token); 2476 return expectSemicolon(token);
2453 } 2477 }
2454 } 2478 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698