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

Side by Side Diff: pkg/compiler/lib/src/scanner/parser.dart

Issue 864643006: Allow sync *, async * and yield * in dart2js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/warnings.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 token = token.next; 1505 token = token.next;
1506 while (notEofOrValue('}', token)) { 1506 while (notEofOrValue('}', token)) {
1507 token = parseStatement(token); 1507 token = parseStatement(token);
1508 ++statementCount; 1508 ++statementCount;
1509 } 1509 }
1510 listener.endFunctionBody(statementCount, begin, token); 1510 listener.endFunctionBody(statementCount, begin, token);
1511 expect('}', token); 1511 expect('}', token);
1512 return token; 1512 return token;
1513 } 1513 }
1514 1514
1515 /// `async*` and `sync*` are parsed a two tokens, [token] and [star]. This
1516 /// method checks that there is no whitespace between [token] and [star].
1517 void checkStarredModifier(Token token, Token star, String name) {
1518 if (star.charOffset > token.charOffset + token.charCount) {
1519 listener.reportError(new TokenPair(token, star),
1520 MessageKind.INVALID_STARRED_KEYWORD, {'keyword': name});
1521 }
1522 }
1523
1524 Token parseAsyncModifier(Token token) { 1515 Token parseAsyncModifier(Token token) {
1525 Token async; 1516 Token async;
1526 Token star; 1517 Token star;
1527 awaitIsKeyword = false; 1518 awaitIsKeyword = false;
1528 yieldIsKeyword = false; 1519 yieldIsKeyword = false;
1529 if (optional('async', token)) { 1520 if (optional('async', token)) {
1530 awaitIsKeyword = true; 1521 awaitIsKeyword = true;
1531 async = token; 1522 async = token;
1532 token = token.next; 1523 token = token.next;
1533 if (optional('*', token)) { 1524 if (optional('*', token)) {
1534 yieldIsKeyword = true; 1525 yieldIsKeyword = true;
1535 star = token; 1526 star = token;
1536 token = token.next; 1527 token = token.next;
1537 checkStarredModifier(async, star, 'async*');
1538 } 1528 }
1539 } else if (optional('sync', token)) { 1529 } else if (optional('sync', token)) {
1540 async = token; 1530 async = token;
1541 token = token.next; 1531 token = token.next;
1542 if (optional('*', token)) { 1532 if (optional('*', token)) {
1543 yieldIsKeyword = true; 1533 yieldIsKeyword = true;
1544 star = token; 1534 star = token;
1545 token = token.next; 1535 token = token.next;
1546
1547 checkStarredModifier(async, star, 'sync*');
1548 } else { 1536 } else {
1549 listener.reportError(async, 1537 listener.reportError(async,
1550 MessageKind.INVALID_SYNC_MODIFIER); 1538 MessageKind.INVALID_SYNC_MODIFIER);
1551 } 1539 }
1552 } 1540 }
1553 listener.handleAsyncModifier(async, star); 1541 listener.handleAsyncModifier(async, star);
1554 return token; 1542 return token;
1555 } 1543 }
1556 1544
1557 Token parseStatement(Token token) { 1545 Token parseStatement(Token token) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 1598
1611 Token parseYieldStatement(Token token) { 1599 Token parseYieldStatement(Token token) {
1612 Token begin = token; 1600 Token begin = token;
1613 listener.beginYieldStatement(begin); 1601 listener.beginYieldStatement(begin);
1614 assert(identical('yield', token.stringValue)); 1602 assert(identical('yield', token.stringValue));
1615 token = token.next; 1603 token = token.next;
1616 Token starToken; 1604 Token starToken;
1617 if (optional('*', token)) { 1605 if (optional('*', token)) {
1618 starToken = token; 1606 starToken = token;
1619 token = token.next; 1607 token = token.next;
1620 checkStarredModifier(begin, starToken, 'yield*');
1621 } 1608 }
1622 token = parseExpression(token); 1609 token = parseExpression(token);
1623 listener.endYieldStatement(begin, starToken, token); 1610 listener.endYieldStatement(begin, starToken, token);
1624 return expectSemicolon(token); 1611 return expectSemicolon(token);
1625 } 1612 }
1626 1613
1627 1614
1628 Token parseReturnStatement(Token token) { 1615 Token parseReturnStatement(Token token) {
1629 Token begin = token; 1616 Token begin = token;
1630 listener.beginReturnStatement(begin); 1617 listener.beginReturnStatement(begin);
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
2674 } 2661 }
2675 listener.handleContinueStatement(hasTarget, continueKeyword, token); 2662 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2676 return expectSemicolon(token); 2663 return expectSemicolon(token);
2677 } 2664 }
2678 2665
2679 Token parseEmptyStatement(Token token) { 2666 Token parseEmptyStatement(Token token) {
2680 listener.handleEmptyStatement(token); 2667 listener.handleEmptyStatement(token);
2681 return expectSemicolon(token); 2668 return expectSemicolon(token);
2682 } 2669 }
2683 } 2670 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698