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

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

Issue 141703024: Refactor of PolymerExpressions. Adds "as" expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: syntax, bindings, and globals tests now passing in Safari Created 6 years, 7 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 | « pkg/polymer_expressions/lib/eval.dart ('k') | pkg/polymer_expressions/lib/parser.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer_expressions/lib/expression.dart
diff --git a/pkg/polymer_expressions/lib/expression.dart b/pkg/polymer_expressions/lib/expression.dart
index 54adfd7579bc7c2a7730309996b63786f1de26b2..ac36c8bbe785a49f30505e15db67782463220b6d 100644
--- a/pkg/polymer_expressions/lib/expression.dart
+++ b/pkg/polymer_expressions/lib/expression.dart
@@ -24,6 +24,7 @@ Index index(Expression e, Expression a) => new Index(e, a);
Invoke invoke(Expression e, String m, List<Expression> a) =>
new Invoke(e, m, a);
InExpression inExpr(Expression l, Expression r) => new InExpression(l, r);
+AsExpression asExpr(Expression l, Expression r) => new AsExpression(l, r);
TernaryOperator ternary(Expression c, Expression t, Expression f) =>
new TernaryOperator(c, t, f);
@@ -59,6 +60,8 @@ class AstFactory {
new Invoke(e, m, a);
InExpression inExpr(Expression l, Expression r) => new InExpression(l, r);
+
+ AsExpression asExpr(Expression l, Expression r) => new AsExpression(l, r);
}
/// Base class for all expressions
@@ -67,6 +70,11 @@ abstract class Expression {
accept(Visitor v);
}
+abstract class HasIdentifier {
+ String get identifier;
+ Expression get expr;
+}
+
class EmptyExpression extends Expression {
const EmptyExpression();
accept(Visitor v) => v.visitEmptyExpression(this);
@@ -212,14 +220,18 @@ class TernaryOperator extends Expression {
trueExpr.hashCode, falseExpr.hashCode);
}
-class InExpression extends Expression {
- final Expression left;
+class InExpression extends Expression implements HasIdentifier {
+ final Identifier left;
final Expression right;
InExpression(this.left, this.right);
accept(Visitor v) => v.visitInExpression(this);
+ String get identifier => left.value;
+
+ Expression get expr => right;
+
String toString() => '($left in $right)';
bool operator ==(o) => o is InExpression && o.left == left
@@ -228,6 +240,26 @@ class InExpression extends Expression {
int get hashCode => _JenkinsSmiHash.hash2(left.hashCode, right.hashCode);
}
+class AsExpression extends Expression implements HasIdentifier {
+ final Expression left;
+ final Identifier right;
+
+ AsExpression(this.left, this.right);
+
+ accept(Visitor v) => v.visitAsExpression(this);
+
+ String get identifier => right.value;
+
+ Expression get expr => left;
+
+ String toString() => '($left as $right)';
+
+ bool operator ==(o) => o is AsExpression && o.left == left
+ && o.right == right;
+
+ int get hashCode => _JenkinsSmiHash.hash2(left.hashCode, right.hashCode);
+}
+
class Index extends Expression {
final Expression receiver;
final Expression argument;
« no previous file with comments | « pkg/polymer_expressions/lib/eval.dart ('k') | pkg/polymer_expressions/lib/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698