equal
deleted
inserted
replaced
108 """char -> bool. return True if ch looks like part of a name, False |
108 """char -> bool. return True if ch looks like part of a name, False |
109 otherwise""" |
109 otherwise""" |
110 return ch in _nonpipechars |
110 return ch in _nonpipechars |
111 |
111 |
112 def _parseasciigraph(text): |
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 lines = text.splitlines() |
159 lines = text.splitlines() |
115 edges = collections.defaultdict(list) # {node: []} |
160 edges = collections.defaultdict(list) # {node: []} |
116 |
161 |
117 def get(y, x): |
162 def get(y, x): |
118 """(int, int) -> char. give a coordinate, return the char. return a |
163 """(int, int) -> char. give a coordinate, return the char. return a |
275 for k, v in remaining.iteritems(): |
320 for k, v in remaining.iteritems(): |
276 if leaf in v: |
321 if leaf in v: |
277 v.remove(leaf) |
322 v.remove(leaf) |
278 |
323 |
279 def _getcomments(text): |
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 for line in text.splitlines(): |
337 for line in text.splitlines(): |
281 if ' # ' not in line: |
338 if ' # ' not in line: |
282 continue |
339 continue |
283 yield line.split(' # ', 1)[1].split(' # ')[0].strip() |
340 yield line.split(' # ', 1)[1].split(' # ')[0].strip() |
284 |
341 |