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

Unified Diff: lib/src/evaluator.dart

Issue 1712793002: Add the content of the package. (Closed) Base URL: git@github.com:dart-lang/boolean_selector@master
Patch Set: Created 4 years, 10 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 | « lib/src/ast.dart ('k') | lib/src/impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/evaluator.dart
diff --git a/lib/src/evaluator.dart b/lib/src/evaluator.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9102add652703809758b50a3a6d4aa382851639a
--- /dev/null
+++ b/lib/src/evaluator.dart
@@ -0,0 +1,34 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'ast.dart';
+import 'visitor.dart';
+
+typedef bool _Semantics(String variable);
+
+/// A visitor for evaluating boolean selectors against a specific set of
+/// semantics.
+class Evaluator implements Visitor<bool> {
+ /// The semantics to evaluate against.
+ final _Semantics _semantics;
+
+ Evaluator(semantics)
+ : _semantics = semantics is Iterable
+ ? semantics.toSet().contains
+ : semantics;
+
+ bool visitVariable(VariableNode node) => _semantics(node.name);
+
+ bool visitNot(NotNode node) => !node.child.accept(this);
+
+ bool visitOr(OrNode node) =>
+ node.left.accept(this) || node.right.accept(this);
+
+ bool visitAnd(AndNode node) =>
+ node.left.accept(this) && node.right.accept(this);
+
+ bool visitConditional(ConditionalNode node) => node.condition.accept(this)
+ ? node.whenTrue.accept(this)
+ : node.whenFalse.accept(this);
+}
« no previous file with comments | « lib/src/ast.dart ('k') | lib/src/impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698