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

Unified Diff: lib/src/impl.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/evaluator.dart ('k') | lib/src/intersection_selector.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/impl.dart
diff --git a/lib/src/impl.dart b/lib/src/impl.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6a4053060ad7bc3e119ba928942f90716140b2cb
--- /dev/null
+++ b/lib/src/impl.dart
@@ -0,0 +1,56 @@
+// 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 '../boolean_selector.dart';
+import 'ast.dart';
+import 'evaluator.dart';
+import 'intersection_selector.dart';
+import 'parser.dart';
+import 'union_selector.dart';
+import 'validator.dart';
+
+/// The concrete implementation of a [BooleanSelector] parsed from a string.
+///
+/// This is separate from [BooleanSelector] so that [intersect] and [union] can
+/// check to see whether they're passed a [BooleanSelectorImpl] or a different
+/// class that implements [BooleanSelector].
+class BooleanSelectorImpl implements BooleanSelector {
+ /// The parsed AST.
+ final Node _selector;
+
+ /// Parses [selector].
+ ///
+ /// This will throw a [SourceSpanFormatException] if the selector is
+ /// malformed or if it uses an undefined variable.
+ BooleanSelectorImpl.parse(String selector)
+ : _selector = new Parser(selector).parse();
+
+ BooleanSelectorImpl._(this._selector);
+
+ Iterable<String> get variables => _selector.variables;
+
+ bool evaluate(semantics) => _selector.accept(new Evaluator(semantics));
+
+ BooleanSelector intersection(BooleanSelector other) {
+ if (other == BooleanSelector.all) return this;
+ if (other == BooleanSelector.none) return other;
+ return other is BooleanSelectorImpl
+ ? new BooleanSelectorImpl._(new AndNode(_selector, other._selector))
+ : new IntersectionSelector(this, other);
+ }
+
+ BooleanSelector union(BooleanSelector other) {
+ if (other == BooleanSelector.all) return other;
+ if (other == BooleanSelector.none) return this;
+ return other is BooleanSelectorImpl
+ ? new BooleanSelectorImpl._(new OrNode(_selector, other._selector))
+ : new UnionSelector(this, other);
+ }
+
+ void validate(bool isDefined(String variable)) {
+ _selector.accept(new Validator(isDefined));
+ }
+
+ String toString() => _selector.toString();
+}
« no previous file with comments | « lib/src/evaluator.dart ('k') | lib/src/intersection_selector.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698