Show More
@@ -110,7 +110,52 b' def _isname(ch):' | |||
|
110 | 110 | return ch in _nonpipechars |
|
111 | 111 | |
|
112 | 112 | def _parseasciigraph(text): |
|
113 |
"""str -> {str : [str]}. convert the ASCII graph to edges |
|
|
113 | r"""str -> {str : [str]}. convert the ASCII graph to edges | |
|
114 | ||
|
115 | >>> import pprint | |
|
116 | >>> pprint.pprint({k: [vv for vv in v] | |
|
117 | ... for k, v in _parseasciigraph(br''' | |
|
118 | ... G | |
|
119 | ... | | |
|
120 | ... I D C F # split: B -> E, F, G | |
|
121 | ... \ \| | # replace: C -> D -> H | |
|
122 | ... H B E # prune: F, I | |
|
123 | ... \|/ | |
|
124 | ... A | |
|
125 | ... ''').items()}) | |
|
126 | {'A': [], | |
|
127 | 'B': ['A'], | |
|
128 | 'C': ['B'], | |
|
129 | 'D': ['B'], | |
|
130 | 'E': ['A'], | |
|
131 | 'F': ['E'], | |
|
132 | 'G': ['F'], | |
|
133 | 'H': ['A'], | |
|
134 | 'I': ['H']} | |
|
135 | >>> pprint.pprint({k: [vv for vv in v] | |
|
136 | ... for k, v in _parseasciigraph(br''' | |
|
137 | ... o foo | |
|
138 | ... |\ | |
|
139 | ... +---o bar | |
|
140 | ... | | | | |
|
141 | ... | o | baz | |
|
142 | ... | / | |
|
143 | ... +---o d | |
|
144 | ... | | | |
|
145 | ... +---o c | |
|
146 | ... | | | |
|
147 | ... o | b | |
|
148 | ... |/ | |
|
149 | ... o a | |
|
150 | ... ''').items()}) | |
|
151 | {'a': [], | |
|
152 | 'b': ['a'], | |
|
153 | 'bar': ['b', 'a'], | |
|
154 | 'baz': [], | |
|
155 | 'c': ['b'], | |
|
156 | 'd': ['b'], | |
|
157 | 'foo': ['baz', 'b']} | |
|
158 | """ | |
|
114 | 159 | lines = text.splitlines() |
|
115 | 160 | edges = collections.defaultdict(list) # {node: []} |
|
116 | 161 | |
@@ -277,6 +322,18 b' def _walkgraph(edges):' | |||
|
277 | 322 | v.remove(leaf) |
|
278 | 323 | |
|
279 | 324 | def _getcomments(text): |
|
325 | """ | |
|
326 | >>> [s for s in _getcomments(br''' | |
|
327 | ... G | |
|
328 | ... | | |
|
329 | ... I D C F # split: B -> E, F, G | |
|
330 | ... \ \| | # replace: C -> D -> H | |
|
331 | ... H B E # prune: F, I | |
|
332 | ... \|/ | |
|
333 | ... A | |
|
334 | ... ''')] | |
|
335 | ['split: B -> E, F, G', 'replace: C -> D -> H', 'prune: F, I'] | |
|
336 | """ | |
|
280 | 337 | for line in text.splitlines(): |
|
281 | 338 | if ' # ' not in line: |
|
282 | 339 | continue |
General Comments 0
You need to be logged in to leave comments.
Login now