parser: move prettyformat() function from revset module
authorYuya Nishihara <yuya@tcha.org>
Sun, 26 Apr 2015 22:20:03 +0900
changeset 25253 3f1a9b44b8c2
parent 25252 ac381dd7a21f
child 25254 060bdfef2517
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.
mercurial/parser.py
mercurial/revset.py
--- a/mercurial/parser.py	Sun Apr 26 19:50:42 2015 +0900
+++ b/mercurial/parser.py	Sun Apr 26 22:20:03 2015 +0900
@@ -93,3 +93,18 @@
         if self._methods:
             return self.eval(t)
         return t
+
+def prettyformat(tree, leafnodes):
+    def _prettyformat(tree, level, lines):
+        if not isinstance(tree, tuple) or tree[0] in leafnodes:
+            lines.append((level, str(tree)))
+        else:
+            lines.append((level, '(%s' % tree[0]))
+            for s in tree[1:]:
+                _prettyformat(s, level + 1, lines)
+            lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')]
+
+    lines = []
+    _prettyformat(tree, 0, lines)
+    output = '\n'.join(('  ' * l + s) for l, s in lines)
+    return output
--- a/mercurial/revset.py	Sun Apr 26 19:50:42 2015 +0900
+++ b/mercurial/revset.py	Sun Apr 26 22:20:03 2015 +0900
@@ -2635,19 +2635,7 @@
     return ret
 
 def prettyformat(tree):
-    def _prettyformat(tree, level, lines):
-        if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
-            lines.append((level, str(tree)))
-        else:
-            lines.append((level, '(%s' % tree[0]))
-            for s in tree[1:]:
-                _prettyformat(s, level + 1, lines)
-            lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')]
-
-    lines = []
-    _prettyformat(tree, 0, lines)
-    output = '\n'.join(('  '*l + s) for l, s in lines)
-    return output
+    return parser.prettyformat(tree, ('string', 'symbol'))
 
 def depth(tree):
     if isinstance(tree, tuple):