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

Side by Side Diff: frog/parser.dart

Issue 9270048: Lots of frog cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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) 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if (oldFactory || _maybeEat(TokenKind.DEFAULT)) { 278 if (oldFactory || _maybeEat(TokenKind.DEFAULT)) {
279 // TODO(jmesserly): keep old factory support for now. Remove soon. 279 // TODO(jmesserly): keep old factory support for now. Remove soon.
280 if (oldFactory) { 280 if (oldFactory) {
281 world.warning('factory no longer supported, use "default" instead', 281 world.warning('factory no longer supported, use "default" instead',
282 _previousToken.span); 282 _previousToken.span);
283 } 283 }
284 284
285 // Note: this can't be type() because it has type parameters not type 285 // Note: this can't be type() because it has type parameters not type
286 // arguments. 286 // arguments.
287 var baseType = nameTypeReference(); 287 var baseType = nameTypeReference();
288 var typeParams = null; 288 var factTypeParams = null;
289 if (_peekKind(TokenKind.LT)) { 289 if (_peekKind(TokenKind.LT)) {
290 typeParams = typeParameters(); 290 factTypeParams = typeParameters();
291 } 291 }
292 defaultType = new DefaultTypeReference(oldFactory, 292 defaultType = new DefaultTypeReference(oldFactory,
293 baseType, typeParams, _makeSpan(baseType.span.start)); 293 baseType, factTypeParams, _makeSpan(baseType.span.start));
294 } 294 }
295 295
296 var body = []; 296 var body = [];
297 if (_maybeEat(TokenKind.LBRACE)) { 297 if (_maybeEat(TokenKind.LBRACE)) {
298 while (!_maybeEat(TokenKind.RBRACE)) { 298 while (!_maybeEat(TokenKind.RBRACE)) {
299 body.add(declaration()); 299 body.add(declaration());
300 if (_recover) { 300 if (_recover) {
301 if (!_recoverTo(TokenKind.RBRACE, TokenKind.SEMICOLON)) break; 301 if (!_recoverTo(TokenKind.RBRACE, TokenKind.SEMICOLON)) break;
302 _maybeEat(TokenKind.SEMICOLON); 302 _maybeEat(TokenKind.SEMICOLON);
303 } 303 }
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 world.error('exactly one type argument expected for list', 1399 world.error('exactly one type argument expected for list',
1400 genericType.span); 1400 genericType.span);
1401 } 1401 }
1402 return finishListLiteral(start, isConst, typeArgs[0]); 1402 return finishListLiteral(start, isConst, typeArgs[0]);
1403 } else if (_peekKind(TokenKind.LBRACE)) { 1403 } else if (_peekKind(TokenKind.LBRACE)) {
1404 var keyType, valueType; 1404 var keyType, valueType;
1405 if (typeArgs.length == 1) { 1405 if (typeArgs.length == 1) {
1406 keyType = null; 1406 keyType = null;
1407 valueType = typeArgs[0]; 1407 valueType = typeArgs[0];
1408 } else if (typeArgs.length == 2) { 1408 } else if (typeArgs.length == 2) {
1409 var keyType = typeArgs[0]; 1409 keyType = typeArgs[0];
1410 // making key explicit is just a warning. 1410 // making key explicit is just a warning.
1411 world.warning( 1411 world.warning(
1412 'a map literal takes one type argument specifying the value type', 1412 'a map literal takes one type argument specifying the value type',
1413 keyType.span); 1413 keyType.span);
1414 valueType = typeArgs[1]; 1414 valueType = typeArgs[1];
1415 } // o.w. the type system will detect the mismatch in type arguments. 1415 } // o.w. the type system will detect the mismatch in type arguments.
1416 return finishMapLiteral(start, isConst, keyType, valueType); 1416 return finishMapLiteral(start, isConst, keyType, valueType);
1417 } else { 1417 } else {
1418 _errorExpected('array or map literal'); 1418 _errorExpected('array or map literal');
1419 } 1419 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 1526
1527 nameTypeReference() { 1527 nameTypeReference() {
1528 int start = _peekToken.start; 1528 int start = _peekToken.start;
1529 var name; 1529 var name;
1530 var names = null; 1530 var names = null;
1531 var typeArgs = null; 1531 var typeArgs = null;
1532 var isFinal = false; 1532 var isFinal = false;
1533 1533
1534 switch (_peek()) { 1534 switch (_peek()) {
1535 case TokenKind.VOID: 1535 case TokenKind.VOID:
1536 return new TypeReference(_next().span, world.voidType); 1536 return new SimpleTypeReference(world.voidType, _next().span);
1537 case TokenKind.VAR: 1537 case TokenKind.VAR:
1538 return new TypeReference(_next().span, world.varType); 1538 return new SimpleTypeReference(world.varType, _next().span);
1539 case TokenKind.FINAL: 1539 case TokenKind.FINAL:
1540 _eat(TokenKind.FINAL); 1540 _eat(TokenKind.FINAL);
1541 isFinal = true; 1541 isFinal = true;
1542 name = identifier(); 1542 name = identifier();
1543 break; 1543 break;
1544 default: 1544 default:
1545 name = identifier(); 1545 name = identifier();
1546 break; 1546 break;
1547 } 1547 }
1548 1548
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 int _pos = 0; 1719 int _pos = 0;
1720 next() { 1720 next() {
1721 var token = tokens[_pos]; 1721 var token = tokens[_pos];
1722 ++_pos; 1722 ++_pos;
1723 if (_pos == tokens.length) { 1723 if (_pos == tokens.length) {
1724 parser.tokenizer = previousTokenizer; 1724 parser.tokenizer = previousTokenizer;
1725 } 1725 }
1726 return token; 1726 return token;
1727 } 1727 }
1728 } 1728 }
OLDNEW
« frog/gen.dart ('K') | « frog/minfrog ('k') | frog/scripts/tree_gen.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698