templater: inline compiletemplate() function into engine
authorYuya Nishihara <yuya@tcha.org>
Sun, 03 Apr 2016 13:23:40 +0900
changeset 28956 eea98190ed73
parent 28955 78759f78a44e
child 28957 d813132ea361
templater: inline compiletemplate() function into engine This allows the template engine to modify parsed tree.
mercurial/templater.py
--- a/mercurial/templater.py	Sun Apr 10 17:23:09 2016 +0900
+++ b/mercurial/templater.py	Sun Apr 03 13:23:40 2016 +0900
@@ -247,11 +247,8 @@
 def prettyformat(tree):
     return parser.prettyformat(tree, ('integer', 'string', 'symbol'))
 
-def compiletemplate(tmpl, context):
-    """Parse and compile template string to (func, data) pair"""
-    return compileexp(parse(tmpl), context, methods)
-
 def compileexp(exp, context, curmethods):
+    """Compile parsed template tree to (func, data) pair"""
     t = exp[0]
     if t in curmethods:
         return curmethods[t](exp, context)
@@ -955,7 +952,8 @@
             # put poison to cut recursion while compiling 't'
             self._cache[t] = (_runrecursivesymbol, t)
             try:
-                self._cache[t] = compiletemplate(self._loader(t), self)
+                x = parse(self._loader(t))
+                self._cache[t] = compileexp(x, self, methods)
             except: # re-raises
                 del self._cache[t]
                 raise