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

Side by Side Diff: petitparser/lib/src/reflection/transform.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
(Empty)
1 part of reflection;
2
3 /**
4 * A function transforming one parser to another one.
5 */
6 typedef Parser TransformationHandler(Parser parser);
7
8 /**
9 * Transforms all parsers reachable from [parser] with the given [handler].
10 * The identity function returns a copy of the the incoming parser.
11 *
12 * The implementation first creates a copy of each parser reachable in the
13 * input grammar; then the resulting grammar is traversed until all references
14 * to old parsers are replaced with the transformed ones.
15 */
16 Parser transformParser(Parser parser, TransformationHandler handler) {
17 var mapping = new Map.identity();
18 for (var each in allParser(parser)) {
19 mapping[each] = handler(each.copy());
20 }
21 var seen = new Set.from(mapping.values);
22 var todo = new List.from(mapping.values);
23 while (todo.isNotEmpty) {
24 var parent = todo.removeLast();
25 for (var child in parent.children) {
26 if (mapping.containsKey(child)) {
27 parent.replace(child, mapping[child]);
28 } else if (!seen.contains(child)) {
29 seen.add(child);
30 todo.add(child);
31 }
32 }
33 }
34 return mapping[parser];
35 }
OLDNEW
« no previous file with comments | « petitparser/lib/src/reflection/optimize.dart ('k') | petitparser/lib/src/smalltalk/grammar.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698