# HG changeset patch # User Yuya Nishihara # Date 2015-06-15 13:55:34 # Node ID 82c918509ef5860496c6d1f3f0d7dd0f7e65024c # Parent 8b900b937e1c11b2018350da4b41054444422765 templater: extract function that parses template string It will be called recursively to parse nested template strings. diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -127,9 +127,9 @@ def tokenize(program, start, end): 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 @@ def compiletemplate(tmpl, context): 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):