##// END OF EJS Templates
templater: switch methods table on compileexp() of func args and inner expr...
Yuya Nishihara -
r25001:9668c1a4 default
parent child Browse files
Show More
@@ -100,12 +100,12 b' def compiletemplate(tmpl, context, strto'
100 parseres, pos = p.parse(pd)
100 parseres, pos = p.parse(pd)
101 parsed.append(parseres)
101 parsed.append(parseres)
102
102
103 return [compileexp(e, context) for e in parsed]
103 return [compileexp(e, context, methods) for e in parsed]
104
104
105 def compileexp(exp, context):
105 def compileexp(exp, context, curmethods):
106 t = exp[0]
106 t = exp[0]
107 if t in methods:
107 if t in curmethods:
108 return methods[t](exp, context)
108 return curmethods[t](exp, context)
109 raise error.ParseError(_("unknown method '%s'") % t)
109 raise error.ParseError(_("unknown method '%s'") % t)
110
110
111 # template evaluation
111 # template evaluation
@@ -157,7 +157,7 b' def runsymbol(context, mapping, key):'
157 return v
157 return v
158
158
159 def buildfilter(exp, context):
159 def buildfilter(exp, context):
160 func, data = compileexp(exp[1], context)
160 func, data = compileexp(exp[1], context, methods)
161 filt = getfilter(exp[2], context)
161 filt = getfilter(exp[2], context)
162 return (runfilter, (func, data, filt))
162 return (runfilter, (func, data, filt))
163
163
@@ -179,7 +179,7 b' def runfilter(context, mapping, data):'
179 "keyword '%s'") % (filt.func_name, dt))
179 "keyword '%s'") % (filt.func_name, dt))
180
180
181 def buildmap(exp, context):
181 def buildmap(exp, context):
182 func, data = compileexp(exp[1], context)
182 func, data = compileexp(exp[1], context, methods)
183 ctmpl = gettemplate(exp[2], context)
183 ctmpl = gettemplate(exp[2], context)
184 return (runmap, (func, data, ctmpl))
184 return (runmap, (func, data, ctmpl))
185
185
@@ -208,7 +208,7 b' def runmap(context, mapping, data):'
208
208
209 def buildfunc(exp, context):
209 def buildfunc(exp, context):
210 n = getsymbol(exp[1])
210 n = getsymbol(exp[1])
211 args = [compileexp(x, context) for x in getlist(exp[2])]
211 args = [compileexp(x, context, exprmethods) for x in getlist(exp[2])]
212 if n in funcs:
212 if n in funcs:
213 f = funcs[n]
213 f = funcs[n]
214 return (f, args)
214 return (f, args)
@@ -565,17 +565,21 b' def word(context, mapping, args):'
565 else:
565 else:
566 return tokens[num]
566 return tokens[num]
567
567
568 methods = {
568 # methods to interpret function arguments or inner expressions (e.g. {_(x)})
569 exprmethods = {
569 "string": lambda e, c: (runstring, e[1]),
570 "string": lambda e, c: (runstring, e[1]),
570 "rawstring": lambda e, c: (runrawstring, e[1]),
571 "rawstring": lambda e, c: (runrawstring, e[1]),
571 "symbol": lambda e, c: (runsymbol, e[1]),
572 "symbol": lambda e, c: (runsymbol, e[1]),
572 "group": lambda e, c: compileexp(e[1], c),
573 "group": lambda e, c: compileexp(e[1], c, exprmethods),
573 # ".": buildmember,
574 # ".": buildmember,
574 "|": buildfilter,
575 "|": buildfilter,
575 "%": buildmap,
576 "%": buildmap,
576 "func": buildfunc,
577 "func": buildfunc,
577 }
578 }
578
579
580 # methods to interpret top-level template (e.g. {x}, {x|_}, {x % "y"})
581 methods = exprmethods.copy()
582
579 funcs = {
583 funcs = {
580 "date": date,
584 "date": date,
581 "diff": diff,
585 "diff": diff,
General Comments 0
You need to be logged in to leave comments. Login now