Index: pkg/polymer_expressions/lib/parser.dart |
=================================================================== |
--- pkg/polymer_expressions/lib/parser.dart (revision 37373) |
+++ 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); |
} |