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

Side by Side Diff: frog/parser.dart

Issue 8457007: Better runtime type checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged, and fix typo in member name Created 9 years, 1 month 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 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 938
939 /** Checks if the given expression is a binary op of the given kind. */ 939 /** Checks if the given expression is a binary op of the given kind. */
940 _isBin(expr, kind) { 940 _isBin(expr, kind) {
941 return expr is BinaryExpression && expr.op.kind == kind; 941 return expr is BinaryExpression && expr.op.kind == kind;
942 } 942 }
943 943
944 _boolTypeRef(SourceSpan span) { 944 _boolTypeRef(SourceSpan span) {
945 return new TypeReference(span, world.boolType); 945 return new TypeReference(span, world.boolType);
946 } 946 }
947 947
948 _numTypeRef(SourceSpan span) { 948 _intTypeRef(SourceSpan span) {
949 return new TypeReference(span, world.numType); 949 return new TypeReference(span, world.intType);
950 }
951
952 _doubleTypeRef(SourceSpan span) {
953 return new TypeReference(span, world.doubleType);
950 } 954 }
951 955
952 _stringTypeRef(SourceSpan span) { 956 _stringTypeRef(SourceSpan span) {
953 return new TypeReference(span, world.stringType); 957 return new TypeReference(span, world.stringType);
954 } 958 }
955 959
956 primary() { 960 primary() {
957 int start = _peekToken.start; 961 int start = _peekToken.start;
958 switch (_peek()) { 962 switch (_peek()) {
959 case TokenKind.THIS: 963 case TokenKind.THIS:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 case TokenKind.TRUE: 1002 case TokenKind.TRUE:
999 _eat(TokenKind.TRUE); 1003 _eat(TokenKind.TRUE);
1000 return new LiteralExpression(true, _boolTypeRef(_makeSpan(start)), 1004 return new LiteralExpression(true, _boolTypeRef(_makeSpan(start)),
1001 'true', _makeSpan(start)); 1005 'true', _makeSpan(start));
1002 1006
1003 case TokenKind.FALSE: 1007 case TokenKind.FALSE:
1004 _eat(TokenKind.FALSE); 1008 _eat(TokenKind.FALSE);
1005 return new LiteralExpression(false,_boolTypeRef(_makeSpan(start)), 1009 return new LiteralExpression(false,_boolTypeRef(_makeSpan(start)),
1006 'false', _makeSpan(start)); 1010 'false', _makeSpan(start));
1007 1011
1008 case TokenKind.HEX_NUMBER: 1012 case TokenKind.HEX_INTEGER:
1009 var t = _next(); 1013 var t = _next();
1010 // Remove the 0x or 0X before parsing the hex number. 1014 // Remove the 0x or 0X before parsing the hex number.
1011 return new LiteralExpression(parseHex(t.text.substring(2)), 1015 return new LiteralExpression(parseHex(t.text.substring(2)),
1012 _numTypeRef(_makeSpan(start)), t.text, _makeSpan(start)); 1016 _intTypeRef(_makeSpan(start)), t.text, _makeSpan(start));
1013 1017
1014 case TokenKind.NUMBER: 1018 case TokenKind.INTEGER:
1019 var t = _next();
1020 return new LiteralExpression(Math.parseInt(t.text),
1021 _intTypeRef(_makeSpan(start)), t.text, _makeSpan(start));
1022
1023 case TokenKind.DOUBLE:
1015 var t = _next(); 1024 var t = _next();
1016 return new LiteralExpression(Math.parseDouble(t.text), 1025 return new LiteralExpression(Math.parseDouble(t.text),
1017 _numTypeRef(_makeSpan(start)), t.text, _makeSpan(start)); 1026 _doubleTypeRef(_makeSpan(start)), t.text, _makeSpan(start));
1018 1027
1019 case TokenKind.STRING: 1028 case TokenKind.STRING:
1020 return stringLiteralExpr(); 1029 return stringLiteralExpr();
1021 1030
1022 case TokenKind.INCOMPLETE_STRING: 1031 case TokenKind.INCOMPLETE_STRING:
1023 return stringInterpolation(); 1032 return stringInterpolation();
1024 1033
1025 case TokenKind.LT: 1034 case TokenKind.LT:
1026 return finishTypedLiteral(start, false); 1035 return finishTypedLiteral(start, false);
1027 1036
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 /** Converts an expression into a label. */ 1645 /** Converts an expression into a label. */
1637 _makeLabel(expr) { 1646 _makeLabel(expr) {
1638 if (expr is VarExpression) { 1647 if (expr is VarExpression) {
1639 return expr.name; 1648 return expr.name;
1640 } else { 1649 } else {
1641 _errorExpected('label'); 1650 _errorExpected('label');
1642 return null; 1651 return null;
1643 } 1652 }
1644 } 1653 }
1645 } 1654 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698