Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // TODO(jimhug): Error recovery needs major work! | 5 // TODO(jimhug): Error recovery needs major work! |
| 6 /** | 6 /** |
| 7 * A simple recursive descent parser for the dart language. | 7 * A simple recursive descent parser for the dart language. |
| 8 * | 8 * |
| 9 * This parser is designed to be more permissive than the official | 9 * This parser is designed to be more permissive than the official |
| 10 * Dart grammar. It is expected that many grammar errors would be | 10 * Dart grammar. It is expected that many grammar errors would be |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 var cases = []; | 612 var cases = []; |
| 613 _eat(TokenKind.LBRACE); | 613 _eat(TokenKind.LBRACE); |
| 614 while (!_maybeEat(TokenKind.RBRACE)) { | 614 while (!_maybeEat(TokenKind.RBRACE)) { |
| 615 cases.add(caseNode()); | 615 cases.add(caseNode()); |
| 616 } | 616 } |
| 617 return new SwitchStatement(test, cases, _makeSpan(start)); | 617 return new SwitchStatement(test, cases, _makeSpan(start)); |
| 618 } | 618 } |
| 619 | 619 |
| 620 _peekCaseEnd() { | 620 _peekCaseEnd() { |
| 621 var kind = _peek(); | 621 var kind = _peek(); |
| 622 //TODO(efortuna): also if the first is an identifier followed by a colon, we | |
| 623 //have a label for the case statement. | |
| 622 return kind == TokenKind.RBRACE || kind == TokenKind.CASE || | 624 return kind == TokenKind.RBRACE || kind == TokenKind.CASE || |
| 623 kind == TokenKind.DEFAULT; | 625 kind == TokenKind.DEFAULT; |
| 624 } | 626 } |
| 625 | 627 |
| 626 caseNode() { | 628 caseNode() { |
| 627 int start = _peekToken.start; | 629 int start = _peekToken.start; |
| 628 var label = null; | 630 var label = null; |
| 629 if (_peekIdentifier()) { | 631 if (_peekIdentifier()) { |
| 632 label = identifier(); | |
|
jimhug
2011/10/28 20:02:44
Whoa! How was this working before?
| |
| 630 _eat(TokenKind.COLON); | 633 _eat(TokenKind.COLON); |
| 631 label = identifier(); | |
| 632 } | 634 } |
| 633 var cases = []; | 635 var cases = []; |
| 634 while (true) { | 636 while (true) { |
| 635 if (_maybeEat(TokenKind.CASE)) { | 637 if (_maybeEat(TokenKind.CASE)) { |
| 636 cases.add(expression()); | 638 cases.add(expression()); |
| 637 _eat(TokenKind.COLON); | 639 _eat(TokenKind.COLON); |
| 638 } else if (_maybeEat(TokenKind.DEFAULT)) { | 640 } else if (_maybeEat(TokenKind.DEFAULT)) { |
| 639 cases.add(null); | 641 cases.add(null); |
| 640 _eat(TokenKind.COLON); | 642 _eat(TokenKind.COLON); |
| 641 } else { | 643 } else { |
| (...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1620 /** Converts an expression into a label. */ | 1622 /** Converts an expression into a label. */ |
| 1621 _makeLabel(expr) { | 1623 _makeLabel(expr) { |
| 1622 if (expr is VarExpression) { | 1624 if (expr is VarExpression) { |
| 1623 return expr.name; | 1625 return expr.name; |
| 1624 } else { | 1626 } else { |
| 1625 _errorExpected('label'); | 1627 _errorExpected('label'); |
| 1626 return null; | 1628 return null; |
| 1627 } | 1629 } |
| 1628 } | 1630 } |
| 1629 } | 1631 } |
| OLD | NEW |