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

Unified Diff: frog/leg/scanner/parser.dart

Issue 9320064: Parse unary plus corretly (i.e., by ignoring it when it's valid). (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/language-leg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/scanner/parser.dart
diff --git a/frog/leg/scanner/parser.dart b/frog/leg/scanner/parser.dart
index b911d1d82de61e55a730522eafd15e6ae539613f..2d1bdffb84fc1d4f87232c816669a0bfb9945f05 100644
--- a/frog/leg/scanner/parser.dart
+++ b/frog/leg/scanner/parser.dart
@@ -942,10 +942,21 @@ class Parser {
Token parseUnaryExpression(Token token) {
String value = token.stringValue;
// Prefix:
- if ((value === '!') ||
- (value === '+') || // TODO(ahe): Being removed from specification.
- (value === '-') ||
- (value === '~')) {
+ if (value === '+') {
+ // Dart only allows "prefix plus" as an initial part of a
+ // decimal literal. We scan it as a separate token and then throws
ahe 2012/02/03 11:28:51 throws -> throw
+ // it away here when we know that we have an unary plus, not a
ahe 2012/02/03 11:28:51 "an unary" -> "a unary" http://owl.english.purdue
+ // binary one.
Lasse Reichstein Nielsen 2012/02/03 13:30:17 Comment updated.
+ Token next = token.next;
+ if (next.charOffset === token.charOffset + 1) {
+ if (next.kind === INT_TOKEN) return parseLiteralInt(next);
ahe 2012/02/03 11:28:51 We shouldn't throw tokens away. Long term, it beco
Lasse Reichstein Nielsen 2012/02/03 13:10:22 I think we should throw it away in the listener in
ahe 2012/02/03 13:19:11 Unfortunately, that way of thinking is counter-pro
Lasse Reichstein Nielsen 2012/02/03 13:30:17 I'm not advocating throwing the character away, bu
ahe 2012/02/03 13:41:10 We could do that. I guess it would be limited to L
+ if (next.kind === DOUBLE_TOKEN) return parseLiteralDouble(next);
+ }
+ listener.recoverableError("Unexpected token '+'", token: token);
+ return parseUnaryExpression(next);
+ } else if ((value === '!') ||
+ (value === '-') ||
+ (value === '~')) {
Token operator = token;
// Right associative, so we recurse at the same precedence
// level.
« no previous file with comments | « no previous file | tests/language/language-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698