changeset 25781:82c918509ef5

templater: extract function that parses template string It will be called recursively to parse nested template strings.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 15 Jun 2015 22:55:34 +0900
parents 8b900b937e1c
children babd2c93bd99
files mercurial/templater.py
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Mon Jun 15 23:00:42 2015 +0900
+++ b/mercurial/templater.py	Mon Jun 15 22:55:34 2015 +0900
@@ -127,9 +127,9 @@
         pos += 1
     yield ('end', None, pos)
 
-def compiletemplate(tmpl, context):
+def _parsetemplate(tmpl, start, stop):
     parsed = []
-    pos, stop = 0, len(tmpl)
+    pos = start
     p = parser.parser(elements)
     while pos < stop:
         n = tmpl.find('{', pos, stop)
@@ -148,7 +148,10 @@
 
         parseres, pos = p.parse(tokenize(tmpl, n + 1, stop))
         parsed.append(parseres)
+    return parsed, pos
 
+def compiletemplate(tmpl, context):
+    parsed, pos = _parsetemplate(tmpl, 0, len(tmpl))
     return [compileexp(e, context, methods) for e in parsed]
 
 def compileexp(exp, context, curmethods):