Patchwork [7,of,9] templater: inline compiletemplate() function into engine

login
register
mail settings
Submitter Yuya Nishihara
Date April 15, 2016, 1:15 p.m.
Message ID <8205edad95550991c2e3.1460726146@mimosa>
Download mbox | patch
Permalink /patch/14646/
State Accepted
Headers show

Comments

Yuya Nishihara - April 15, 2016, 1:15 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1459657420 -32400
#      Sun Apr 03 13:23:40 2016 +0900
# Node ID 8205edad95550991c2e31246b4b2c1093bf4c6d6
# Parent  3f45dae15bb24e63c37330352b37f8b4a53f43f6
templater: inline compiletemplate() function into engine

This allows the template engine to modify parsed tree.

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -247,11 +247,8 @@  def _parseexpr(expr):
 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 @@  class engine(object):
             # 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