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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « lib/src/evaluator.dart ('k') | lib/src/intersection_selector.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import '../boolean_selector.dart';
6 import 'ast.dart';
7 import 'evaluator.dart';
8 import 'intersection_selector.dart';
9 import 'parser.dart';
10 import 'union_selector.dart';
11 import 'validator.dart';
12
13 /// The concrete implementation of a [BooleanSelector] parsed from a string.
14 ///
15 /// This is separate from [BooleanSelector] so that [intersect] and [union] can
16 /// check to see whether they're passed a [BooleanSelectorImpl] or a different
17 /// class that implements [BooleanSelector].
18 class BooleanSelectorImpl implements BooleanSelector {
19 /// The parsed AST.
20 final Node _selector;
21
22 /// Parses [selector].
23 ///
24 /// This will throw a [SourceSpanFormatException] if the selector is
25 /// malformed or if it uses an undefined variable.
26 BooleanSelectorImpl.parse(String selector)
27 : _selector = new Parser(selector).parse();
28
29 BooleanSelectorImpl._(this._selector);
30
31 Iterable<String> get variables => _selector.variables;
32
33 bool evaluate(semantics) => _selector.accept(new Evaluator(semantics));
34
35 BooleanSelector intersection(BooleanSelector other) {
36 if (other == BooleanSelector.all) return this;
37 if (other == BooleanSelector.none) return other;
38 return other is BooleanSelectorImpl
39 ? new BooleanSelectorImpl._(new AndNode(_selector, other._selector))
40 : new IntersectionSelector(this, other);
41 }
42
43 BooleanSelector union(BooleanSelector other) {
44 if (other == BooleanSelector.all) return other;
45 if (other == BooleanSelector.none) return this;
46 return other is BooleanSelectorImpl
47 ? new BooleanSelectorImpl._(new OrNode(_selector, other._selector))
48 : new UnionSelector(this, other);
49 }
50
51 void validate(bool isDefined(String variable)) {
52 _selector.accept(new Validator(isDefined));
53 }
54
55 String toString() => _selector.toString();
56 }
OLDNEW
« 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