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

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

Issue 10392024: Add a "Label" Node around an Identifier that is being used as a label. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Only use Label nodes for label introductions. Include the colon. Created 8 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 /** 5 /**
6 * An event generating parser of Dart programs. This parser expects 6 * An event generating parser of Dart programs. This parser expects
7 * all tokens in a linked list (aka a token stream). 7 * all tokens in a linked list (aka a token stream).
8 * 8 *
9 * The class [Scanner] is used to generate a token stream. See the 9 * The class [Scanner] is used to generate a token stream. See the
10 * file scanner.dart. 10 * file scanner.dart.
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 BeginGroupToken begin = token.next; 835 BeginGroupToken begin = token.next;
836 String afterParens = begin.endGroup.next.stringValue; 836 String afterParens = begin.endGroup.next.stringValue;
837 if (afterParens === '{' || afterParens === '=>') { 837 if (afterParens === '{' || afterParens === '=>') {
838 return parseFunctionDeclaration(token); 838 return parseFunctionDeclaration(token);
839 } 839 }
840 } 840 }
841 } 841 }
842 return parseExpressionStatement(token); 842 return parseExpressionStatement(token);
843 } 843 }
844 844
845 Token parseLabel(Token token) {
846 token = parseIdentifier(token);
847 Token colon = token;
848 token = expect(':', token);
849 listener.handleLabel(colon);
850 return token;
851 }
852
845 Token parseLabeledStatement(Token token) { 853 Token parseLabeledStatement(Token token) {
846 listener.beginLabeledStatement(token); 854 listener.beginLabeledStatement(token);
847 token = parseIdentifier(token); 855 token = parseLabel(token);
848 Token colon = token;
849 token = expect(':', token);
850 token = parseStatement(token); 856 token = parseStatement(token);
851 listener.endLabeledStatement(colon); 857 listener.endLabeledStatement();
852 return token; 858 return token;
853 } 859 }
854 860
855 Token parseExpressionStatement(Token token) { 861 Token parseExpressionStatement(Token token) {
856 listener.beginExpressionStatement(token); 862 listener.beginExpressionStatement(token);
857 token = parseExpression(token); 863 token = parseExpression(token);
858 listener.endExpressionStatement(token); 864 listener.endExpressionStatement(token);
859 return expectSemicolon(token); 865 return expectSemicolon(token);
860 } 866 }
861 867
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 return token; 1570 return token;
1565 } 1571 }
1566 1572
1567 Token parseSwitchCase(Token token) { 1573 Token parseSwitchCase(Token token) {
1568 Token begin = token; 1574 Token begin = token;
1569 Token defaultKeyword = null; 1575 Token defaultKeyword = null;
1570 Token label = null; 1576 Token label = null;
1571 // First an optional label. 1577 // First an optional label.
1572 if (isIdentifier(token)) { 1578 if (isIdentifier(token)) {
1573 label = token; 1579 label = token;
1574 token = parseIdentifier(token); 1580 token = parseLabel(token);
1575 token = expect(':', token);
1576 } 1581 }
1577 // Then one or more case expressions, the last of which may be 1582 // Then one or more case expressions, the last of which may be
1578 // 'default' instead. 1583 // 'default' instead.
1579 int expressionCount = 0; 1584 int expressionCount = 0;
1580 { 1585 {
1581 String value = token.stringValue; 1586 String value = token.stringValue;
1582 do { 1587 do {
1583 if (value === 'default') { 1588 if (value === 'default') {
1584 defaultKeyword = token; 1589 defaultKeyword = token;
1585 token = expect(':', token.next); 1590 token = expect(':', token.next);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 } 1643 }
1639 listener.handleContinueStatement(hasTarget, continueKeyword, token); 1644 listener.handleContinueStatement(hasTarget, continueKeyword, token);
1640 return expectSemicolon(token); 1645 return expectSemicolon(token);
1641 } 1646 }
1642 1647
1643 Token parseEmptyStatement(Token token) { 1648 Token parseEmptyStatement(Token token) {
1644 listener.handleEmptyStatement(token); 1649 listener.handleEmptyStatement(token);
1645 return expectSemicolon(token); 1650 return expectSemicolon(token);
1646 } 1651 }
1647 } 1652 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698