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

Side by Side Diff: frog/parser.dart

Issue 8856004: frog: better errors/warnigns about type annotations in map literals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' 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
« no previous file with comments | « frog/minfrog ('k') | no next file » | 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) 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 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 finishTypedLiteral(int start, bool isConst) { 1449 finishTypedLiteral(int start, bool isConst) {
1450 var span = _makeSpan(start); 1450 var span = _makeSpan(start);
1451 var typeToBeNamedLater = new NameTypeReference(false, null, null, span); 1451 var typeToBeNamedLater = new NameTypeReference(false, null, null, span);
1452 var genericType = addTypeArguments(typeToBeNamedLater, 0); 1452 var genericType = addTypeArguments(typeToBeNamedLater, 0);
1453 1453
1454 if (_peekKind(TokenKind.LBRACK) || _peekKind(TokenKind.INDEX)) { 1454 if (_peekKind(TokenKind.LBRACK) || _peekKind(TokenKind.INDEX)) {
1455 genericType.baseType = new TypeReference(span, world.listType); 1455 genericType.baseType = new TypeReference(span, world.listType);
1456 return finishListLiteral(start, isConst, genericType); 1456 return finishListLiteral(start, isConst, genericType);
1457 } else if (_peekKind(TokenKind.LBRACE)) { 1457 } else if (_peekKind(TokenKind.LBRACE)) {
1458 genericType.baseType = new TypeReference(span, world.mapType); 1458 genericType.baseType = new TypeReference(span, world.mapType);
1459 if (genericType.typeArguments.length != 1) { 1459 if (genericType.typeArguments.length == 1) {
1460 _error('a map literal takes one type argument specfying the value type', 1460 genericType.typeArguments = [new TypeReference(span, world.stringType),
1461 genericType.typeArguments.length == 0 1461 genericType.typeArguments[0]];
1462 ? genericType.typeArguments.span 1462 } else if (genericType.typeArguments.length == 2) {
1463 : genericType.typeArguments[1].span); 1463 var keyType = genericType.typeArguments[0];
1464 } 1464 if (keyType is! NameTypeReference || keyType.name.name !== "String") {
1465 genericType.typeArguments = [new TypeReference(span, world.stringType), 1465 world.error('the key type of a map literal is implicitly "String"',
1466 genericType.typeArguments[0]]; 1466 keyType.span);
1467 } else {
1468 // making key explicit is just a warning.
1469 world.warning(
1470 'a map literal takes one type argument specifying the value type',
1471 keyType.span);
1472 }
1473 } // o.w. the type system will detect the mismatch in type arguments.
1467 return finishMapLiteral(start, isConst, genericType); 1474 return finishMapLiteral(start, isConst, genericType);
1468 } else { 1475 } else {
1469 _errorExpected('array or map literal'); 1476 _errorExpected('array or map literal');
1470 } 1477 }
1471 } 1478 }
1472 1479
1473 /////////////////////////////////////////////////////////////////// 1480 ///////////////////////////////////////////////////////////////////
1474 // Some auxilary productions. 1481 // Some auxilary productions.
1475 /////////////////////////////////////////////////////////////////// 1482 ///////////////////////////////////////////////////////////////////
1476 _readModifiers() { 1483 _readModifiers() {
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 int _pos = 0; 1758 int _pos = 0;
1752 next() { 1759 next() {
1753 var token = tokens[_pos]; 1760 var token = tokens[_pos];
1754 ++_pos; 1761 ++_pos;
1755 if (_pos == tokens.length) { 1762 if (_pos == tokens.length) {
1756 parser.tokenizer = previousTokenizer; 1763 parser.tokenizer = previousTokenizer;
1757 } 1764 }
1758 return token; 1765 return token;
1759 } 1766 }
1760 } 1767 }
OLDNEW
« no previous file with comments | « frog/minfrog ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698