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

Side by Side Diff: frog/parser.dart

Issue 8788004: Fixing parsing of factories. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updated minfrog Created 9 years 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) 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 245 }
246 246
247 var _native = null; 247 var _native = null;
248 if (_maybeEat(TokenKind.NATIVE)) { 248 if (_maybeEat(TokenKind.NATIVE)) {
249 _native = maybeStringLiteral(); 249 _native = maybeStringLiteral();
250 if (_native !== null) _native = new NativeType(_native); 250 if (_native !== null) _native = new NativeType(_native);
251 } 251 }
252 252
253 var _factory = null; 253 var _factory = null;
254 if (_maybeEat(TokenKind.FACTORY)) { 254 if (_maybeEat(TokenKind.FACTORY)) {
255 _factory = type(); 255 // Note: this can't be type(), because for some strange reason these are
256 // type parameters, not type arguments.
257 _factory = nameTypeReference();
258 if (_peekKind(TokenKind.LT)) {
259 // TODO(jmesserly): not sure what to do with these. They aren't used for
260 // anything as far as I can tell.
jimhug 2011/12/08 16:24:30 Just hold your nose and parse them <smile/frown>
261 typeParameters();
262 }
256 } 263 }
257 264
258 var body = []; 265 var body = [];
259 if (_maybeEat(TokenKind.LBRACE)) { 266 if (_maybeEat(TokenKind.LBRACE)) {
260 while (!_maybeEat(TokenKind.RBRACE)) { 267 while (!_maybeEat(TokenKind.RBRACE)) {
261 if (isPrematureEndOfFile()) break; 268 if (isPrematureEndOfFile()) break;
262 body.add(declaration()); 269 body.add(declaration());
263 } 270 }
264 } else { 271 } else {
265 _errorExpected('block starting with "{" or ";"'); 272 _errorExpected('block starting with "{" or ";"');
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 1530
1524 typeList() { 1531 typeList() {
1525 var types = []; 1532 var types = [];
1526 do { 1533 do {
1527 types.add(type()); 1534 types.add(type());
1528 } while (_maybeEat(TokenKind.COMMA)); 1535 } while (_maybeEat(TokenKind.COMMA));
1529 1536
1530 return types; 1537 return types;
1531 } 1538 }
1532 1539
1533 type([int depth = 0]) { 1540 nameTypeReference() {
1534 int start = _peekToken.start; 1541 int start = _peekToken.start;
1535 var name; 1542 var name;
1536 var names = null; 1543 var names = null;
1537 var typeArgs = null; 1544 var typeArgs = null;
1538 var isFinal = false; 1545 var isFinal = false;
1539 1546
1540 switch (_peek()) { 1547 switch (_peek()) {
1541 case TokenKind.VOID: 1548 case TokenKind.VOID:
1542 return new TypeReference(_next().span, world.voidType); 1549 return new TypeReference(_next().span, world.voidType);
1543 case TokenKind.VAR: 1550 case TokenKind.VAR:
1544 return new TypeReference(_next().span, world.varType); 1551 return new TypeReference(_next().span, world.varType);
1545 case TokenKind.FINAL: 1552 case TokenKind.FINAL:
1546 _eat(TokenKind.FINAL); 1553 _eat(TokenKind.FINAL);
1547 isFinal = true; 1554 isFinal = true;
1548 name = identifier(); 1555 name = identifier();
1549 break; 1556 break;
1550 default: 1557 default:
1551 name = identifier(); 1558 name = identifier();
1552 break; 1559 break;
1553 } 1560 }
1554 1561
1555 while (_maybeEat(TokenKind.DOT)) { 1562 while (_maybeEat(TokenKind.DOT)) {
1556 if (names === null) names = []; 1563 if (names === null) names = [];
1557 names.add(identifier()); 1564 names.add(identifier());
1558 } 1565 }
1559 1566
1560 var typeRef = new NameTypeReference(isFinal, name, names, 1567 return new NameTypeReference(isFinal, name, names, _makeSpan(start));
1561 _makeSpan(start)); 1568 }
1569
1570 type([int depth = 0]) {
1571 var typeRef = nameTypeReference();
1562 1572
1563 if (_peekKind(TokenKind.LT)) { 1573 if (_peekKind(TokenKind.LT)) {
1564 return addTypeArguments(typeRef, depth); 1574 return addTypeArguments(typeRef, depth);
1565 } else { 1575 } else {
1566 return typeRef; 1576 return typeRef;
1567 } 1577 }
1568 } 1578 }
1569 1579
1570 formalParameter(bool inOptionalBlock) { 1580 formalParameter(bool inOptionalBlock) {
1571 int start = _peekToken.start; 1581 int start = _peekToken.start;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 int _pos = 0; 1713 int _pos = 0;
1704 next() { 1714 next() {
1705 var token = tokens[_pos]; 1715 var token = tokens[_pos];
1706 ++_pos; 1716 ++_pos;
1707 if (_pos == tokens.length) { 1717 if (_pos == tokens.length) {
1708 parser.tokenizer = previousTokenizer; 1718 parser.tokenizer = previousTokenizer;
1709 } 1719 }
1710 return token; 1720 return token;
1711 } 1721 }
1712 } 1722 }
OLDNEW
« no previous file with comments | « frog/minfrog ('k') | tests/language/language.status » ('j') | tests/language/language.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698