comparison mercurial/revset.py @ 25253:3f1a9b44b8c2

parser: move prettyformat() function from revset module I want to use it in doctests that I'll add by future patches. Also, it can be used in "hg debugfileset" command.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 26 Apr 2015 22:20:03 +0900
parents 235f6490550c
children 61b3529e2377
comparison
equal deleted inserted replaced
25252:ac381dd7a21f 25253:3f1a9b44b8c2
2633 pos += 1 2633 pos += 1
2634 2634
2635 return ret 2635 return ret
2636 2636
2637 def prettyformat(tree): 2637 def prettyformat(tree):
2638 def _prettyformat(tree, level, lines): 2638 return parser.prettyformat(tree, ('string', 'symbol'))
2639 if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
2640 lines.append((level, str(tree)))
2641 else:
2642 lines.append((level, '(%s' % tree[0]))
2643 for s in tree[1:]:
2644 _prettyformat(s, level + 1, lines)
2645 lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')]
2646
2647 lines = []
2648 _prettyformat(tree, 0, lines)
2649 output = '\n'.join((' '*l + s) for l, s in lines)
2650 return output
2651 2639
2652 def depth(tree): 2640 def depth(tree):
2653 if isinstance(tree, tuple): 2641 if isinstance(tree, tuple):
2654 return max(map(depth, tree)) + 1 2642 return max(map(depth, tree)) + 1
2655 else: 2643 else: