mercurial/templater.py
changeset 28956 eea98190ed73
parent 28954 f97a0bcfd7a1
child 28957 d813132ea361
equal deleted inserted replaced
28955:78759f78a44e 28956:eea98190ed73
   245     return _unnesttemplatelist(tree)
   245     return _unnesttemplatelist(tree)
   246 
   246 
   247 def prettyformat(tree):
   247 def prettyformat(tree):
   248     return parser.prettyformat(tree, ('integer', 'string', 'symbol'))
   248     return parser.prettyformat(tree, ('integer', 'string', 'symbol'))
   249 
   249 
   250 def compiletemplate(tmpl, context):
       
   251     """Parse and compile template string to (func, data) pair"""
       
   252     return compileexp(parse(tmpl), context, methods)
       
   253 
       
   254 def compileexp(exp, context, curmethods):
   250 def compileexp(exp, context, curmethods):
       
   251     """Compile parsed template tree to (func, data) pair"""
   255     t = exp[0]
   252     t = exp[0]
   256     if t in curmethods:
   253     if t in curmethods:
   257         return curmethods[t](exp, context)
   254         return curmethods[t](exp, context)
   258     raise error.ParseError(_("unknown method '%s'") % t)
   255     raise error.ParseError(_("unknown method '%s'") % t)
   259 
   256 
   953         '''load, parse, and cache a template'''
   950         '''load, parse, and cache a template'''
   954         if t not in self._cache:
   951         if t not in self._cache:
   955             # put poison to cut recursion while compiling 't'
   952             # put poison to cut recursion while compiling 't'
   956             self._cache[t] = (_runrecursivesymbol, t)
   953             self._cache[t] = (_runrecursivesymbol, t)
   957             try:
   954             try:
   958                 self._cache[t] = compiletemplate(self._loader(t), self)
   955                 x = parse(self._loader(t))
       
   956                 self._cache[t] = compileexp(x, self, methods)
   959             except: # re-raises
   957             except: # re-raises
   960                 del self._cache[t]
   958                 del self._cache[t]
   961                 raise
   959                 raise
   962         return self._cache[t]
   960         return self._cache[t]
   963 
   961