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

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

Issue 141703024: Refactor of PolymerExpressions. Adds "as" expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Roll to latest version, simplified much of the scope creation Created 6 years, 8 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: pkg/polymer_expressions/lib/eval.dart
diff --git a/pkg/polymer_expressions/lib/eval.dart b/pkg/polymer_expressions/lib/eval.dart
index 2332cf908f6f276aea268197cba996be800abaa3..4a2ee419ed23065ae5c82abe690ad940dcb9ea57 100644
--- a/pkg/polymer_expressions/lib/eval.dart
+++ b/pkg/polymer_expressions/lib/eval.dart
@@ -60,7 +60,7 @@ Object eval(Expression expr, Scope scope) {
* [ExpressionObsserver].
*/
ExpressionObserver observe(Expression expr, Scope scope) {
- var observer = new ObserverBuilder(scope).visit(expr);
+ var observer = new ObserverBuilder().visit(expr);
return observer;
}
@@ -151,6 +151,9 @@ void assign(Expression expr, Object value, Scope scope) {
* and then finally looks up the name as a property in the model.
*/
abstract class Scope implements Indexable<String, Object> {
+ static int __seq = 1;
+ final int _seq = __seq++;
+
Scope._();
/** Create a scope containing a [model] and all of [variables]. */
@@ -184,6 +187,9 @@ abstract class Scope implements Indexable<String, Object> {
/** Create a new scope extending this scope with an additional variable. */
Scope childScope(String name, Object value) =>
new _LocalVariableScope(name, value, this);
+
+ String toString() => 'Scope(seq: $_seq model: $model)';
+
}
/**
@@ -207,6 +213,8 @@ class _ModelScope extends Scope {
}
Object _isModelProperty(String name) => name != 'this';
+
+ String toString() => 'ModelScope(model: $model)';
}
/**
@@ -238,6 +246,8 @@ class _LocalVariableScope extends Scope {
if (varName == name) return false;
return parent == null ? false : parent._isModelProperty(name);
}
+
+ String toString() => 'LocalVariableScope(varName: $varName, value: $value, parent: $parent)';
Jennifer Messerly 2014/04/24 00:51:34 long line
justinfagnani 2014/05/28 00:29:37 Done.
}
/** A scope that holds a reference to a global variables. */
@@ -263,6 +273,8 @@ class _GlobalsScope extends Scope {
if (variables.containsKey(name)) return false;
return parent == null ? false : parent._isModelProperty(name);
}
+
+ String toString() => 'GlobalsScope(variables: $variables, parent: $parent)';
}
Object _convert(v) => v is Stream ? new StreamBinding(v) : v;
@@ -322,18 +334,12 @@ class Updater extends RecursiveVisitor {
visitExpression(ExpressionObserver e) {
e._observe(scope);
}
-
- visitInExpression(InObserver c) {
- visit(c.right);
- visitExpression(c);
- }
}
class ObserverBuilder extends Visitor {
- final Scope scope;
final Queue parents = new Queue();
- ObserverBuilder(this.scope);
+ ObserverBuilder();
visitEmptyExpression(EmptyExpression e) => new EmptyObserver(e);
@@ -421,13 +427,11 @@ class ObserverBuilder extends Visitor {
}
visitInExpression(InExpression i) {
- // don't visit the left. It's an identifier, but we don't want to evaluate
- // it, we just want to add it to the comprehension object
- var left = visit(i.left);
- var right = visit(i.right);
- var inexpr = new InObserver(i, left, right);
- right._parent = inexpr;
- return inexpr;
+ throw new UnsupportedError("can't eval an 'in' expression");
+ }
+
+ visitAsExpression(AsExpression i) {
+ throw new UnsupportedError("can't eval an 'as' expression");
}
}
@@ -705,47 +709,9 @@ class InvokeObserver extends ExpressionObserver<Invoke> implements Invoke {
accept(Visitor v) => v.visitInvoke(this);
}
-class InObserver extends ExpressionObserver<InExpression>
- implements InExpression {
- IdentifierObserver left;
- ExpressionObserver right;
-
- InObserver(Expression expr, this.left, this.right) : super(expr);
-
- _updateSelf(Scope scope) {
- Identifier identifier = left;
- var iterable = right._value;
-
- if (iterable is! Iterable && iterable != null) {
- throw new EvalException("right side of 'in' is not an iterator");
- }
-
- if (iterable is ObservableList) {
- _subscription = iterable.listChanges.listen((_) => _invalidate(scope));
- }
-
- // TODO: make Comprehension observable and update it
- _value = new Comprehension(identifier.value, iterable);
- }
-
- accept(Visitor v) => v.visitInExpression(this);
-}
_toBool(v) => (v == null) ? false : v;
-/**
- * A comprehension declaration ("a in b"). [identifier] is the loop variable
- * that's added to the scope during iteration. [iterable] is the set of
- * objects to iterate over.
- */
-class Comprehension {
- final String identifier;
- final Iterable iterable;
-
- Comprehension(this.identifier, Iterable iterable)
- : iterable = (iterable != null) ? iterable : const [];
-}
-
class EvalException implements Exception {
final String message;
EvalException(this.message);
« no previous file with comments | « no previous file | pkg/polymer_expressions/lib/expression.dart » ('j') | pkg/polymer_expressions/lib/polymer_expressions.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698