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

Unified Diff: dart/pkg/polymer_expressions/lib/parser.dart

Issue 336013003: Version 1.5.0-dev.4.14 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 6 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
Index: dart/pkg/polymer_expressions/lib/parser.dart
===================================================================
--- dart/pkg/polymer_expressions/lib/parser.dart (revision 37358)
+++ dart/pkg/polymer_expressions/lib/parser.dart (working copy)
@@ -5,9 +5,12 @@
library polymer_expressions.parser;
import 'tokenizer.dart';
+export 'tokenizer.dart' show ParseException;
import 'expression.dart';
-const _UNARY_OPERATORS = const ['+', '-', '!'];
+const _UNARY_OPERATORS = const <String>['+', '-', '!'];
+const _BINARY_OPERATORS = const <String>['+', '-', '*', '/', '%', '^', '==',
+ '!=', '>', '<', '>=', '<=', '||', '&&', '&', '===', '!==', '|'];
Expression parse(String expr) => new Parser(expr).parse();
@@ -96,6 +99,9 @@
Expression _parseBinary(left) {
var op = _token;
+ if (!_BINARY_OPERATORS.contains(op.value)) {
+ throw new ParseException("unknown operator: ${op.value}");
+ }
_advance();
var right = _parseUnary();
while (_token != null
@@ -125,6 +131,8 @@
_advance();
var expr = _parsePrecedence(_parsePrimary(), POSTFIX_PRECEDENCE);
return _astFactory.unary(value, expr);
+ } else {
+ throw new ParseException("unexpected token: $value");
}
}
return _parsePrimary();
@@ -148,9 +156,9 @@
// TODO(justin): return keyword node
return _astFactory.identifier('this');
} else if (KEYWORDS.contains(keyword)) {
- throw new ParseException('invalid keyword: $keyword');
+ throw new ParseException('unexpected keyword: $keyword');
}
- throw new ArgumentError('unrecognized keyword: $keyword');
+ throw new ParseException('unrecognized keyword: $keyword');
case IDENTIFIER_TOKEN:
return _parseInvokeOrIdentifier();
case STRING_TOKEN:
@@ -169,9 +177,7 @@
}
return null;
case COLON_TOKEN:
- // TODO(justinfagnani): We need better errors throughout the parser, and
- // we should be throwing ParseErrors to be caught by the caller
- throw new ArgumentError('unexpected token ":"');
+ throw new ParseException('unexpected token ":"');
default:
return null;
}
@@ -227,7 +233,7 @@
var right = _parseExpression();
if (right is! Identifier) {
throw new ParseException(
- "as... statements must end with an identifier");
+ "'as' statements must end with an identifier");
}
return _astFactory.asExpr(left, right);
}
« no previous file with comments | « dart/pkg/polymer_expressions/lib/eval.dart ('k') | dart/pkg/polymer_expressions/lib/polymer_expressions.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698