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

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: Address review comments. 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..26413dfb3296c10ea833909beb7c2de3388b597d 100644
--- a/frog/leg/scanner/parser.dart
+++ b/frog/leg/scanner/parser.dart
@@ -942,10 +942,22 @@ 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 throw
+ // it away here when we know that we have a unary plus, not a
ahe 2012/02/03 13:19:11 We are not throwing it away anymore :-)
+ // binary one.
+ Token operator = token;
+ Token next = token.next;
+ if (next.charOffset !== token.charOffset + 1 ||
+ (next.kind !== INT_TOKEN && next.kind !== DOUBLE_TOKEN)) {
+ listener.recoverableError("Unexpected token '+'", token: token);
+ }
+ token = parsePrecedenceExpression(next, POSTFIX_PRECEDENCE);
+ listener.handleUnaryPrefixExpression(operator);
+ } 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