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

Side by Side Diff: petitparser/lib/src/reflection/iterable.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 | « petitparser/lib/src/lisp/standard.dart ('k') | petitparser/lib/src/reflection/optimize.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 part of reflection;
2
3 /**
4 * Returns a lazy iterable over all parsers reachable from a [root].
5 *
6 * For example, the following code prints the two parsers of the
7 * defined grammar:
8 *
9 * var parser = range('0', '9').star();
10 * allParser(parser).forEach((each) {
11 * print(each);
12 * });
13 *
14 */
15 Iterable<Parser> allParser(Parser root) => new _ParserIterable(root);
16
17 class _ParserIterable extends IterableBase<Parser> {
18 final Parser root;
19
20 _ParserIterable(this.root);
21
22 @override
23 Iterator<Parser> get iterator => new _ParserIterator([root]);
24 }
25
26 class _ParserIterator implements Iterator<Parser> {
27 final List<Parser> todo;
28 final Set<Parser> seen;
29
30 _ParserIterator(Iterable<Parser> roots)
31 : todo = new List.from(roots),
32 seen = new Set.from(roots);
33
34 @override
35 Parser current;
36
37 @override
38 bool moveNext() {
39 if (todo.isEmpty) {
40 current = null;
41 return false;
42 }
43 current = todo.removeLast();
44 for (var parser in current.children) {
45 if (!seen.contains(parser)) {
46 todo.add(parser);
47 seen.add(parser);
48 }
49 }
50 return true;
51 }
52 }
OLDNEW
« no previous file with comments | « petitparser/lib/src/lisp/standard.dart ('k') | petitparser/lib/src/reflection/optimize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698