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

Side by Side Diff: packages/petitparser/lib/src/reflection/optimize.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
OLDNEW
1 part of reflection; 1 part of petitparser.reflection;
2 2
3 /** 3 /// Returns a copy of [parser] with all settable parsers removed.
4 * Returns a copy of [parser] with all settable parsers removed.
5 */
6 Parser removeSettables(Parser parser) { 4 Parser removeSettables(Parser parser) {
7 return transformParser(parser, (each) { 5 return transformParser(parser, (each) {
8 while (each is SettableParser) { 6 while (each is SettableParser) {
9 each = each.children.first; 7 each = each.children.first;
10 } 8 }
11 return each; 9 return each;
12 }); 10 });
13 } 11 }
14 12
15 /** 13 /// Returns a copy of [parser] with all duplicates parsers collapsed.
16 * Returns a copy of [parser] with all duplicates parsers collapsed.
17 */
18 Parser removeDuplicates(Parser parser) { 14 Parser removeDuplicates(Parser parser) {
19 var uniques = new Set(); 15 var uniques = new Set();
20 return transformParser(parser, (source) { 16 return transformParser(parser, (source) {
21 var target = uniques.firstWhere((each) { 17 var target = uniques.firstWhere((each) {
22 return source != each && source.isEqualTo(each); 18 return source != each && source.isEqualTo(each);
23 }, orElse: () => null); 19 }, orElse: () => null);
24 if (target == null) { 20 if (target == null) {
25 uniques.add(source); 21 uniques.add(source);
26 return source; 22 return source;
27 } else { 23 } else {
28 return target; 24 return target;
29 } 25 }
30 }); 26 });
31 } 27 }
OLDNEW
« no previous file with comments | « packages/petitparser/lib/src/reflection/iterable.dart ('k') | packages/petitparser/lib/src/reflection/transform.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698