MCPcopy
hub / github.com/flosch/pongo2 / Evaluate

Method Evaluate

parser_expression.go:285–319  ·  view source on GitHub ↗
(ctx *ExecutionContext)

Source from the content-addressed store, hash-verified

283}
284
285func (expr *term) Evaluate(ctx *ExecutionContext) (*Value, *Error) {
286 f1, err := expr.factor1.Evaluate(ctx)
287 if err != nil {
288 return nil, err
289 }
290 if expr.factor2 != nil {
291 f2, err := expr.factor2.Evaluate(ctx)
292 if err != nil {
293 return nil, err
294 }
295 switch expr.opToken.Val {
296 case "*":
297 if f1.IsFloat() || f2.IsFloat() {
298 // Result will be float
299 return AsValue(f1.Float() * f2.Float()), nil
300 }
301 // Result will be int
302 return AsValue(f1.Integer() * f2.Integer()), nil
303 case "/":
304 if f1.IsFloat() || f2.IsFloat() {
305 // Result will be float
306 return AsValue(f1.Float() / f2.Float()), nil
307 }
308 // Result will be int
309 return AsValue(f1.Integer() / f2.Integer()), nil
310 case "%":
311 // Result will be int
312 return AsValue(f1.Integer() % f2.Integer()), nil
313 default:
314 return nil, ctx.Error("unimplemented", expr.opToken)
315 }
316 } else {
317 return f1, nil
318 }
319}
320
321func (expr *power) Evaluate(ctx *ExecutionContext) (*Value, *Error) {
322 p1, err := expr.power1.Evaluate(ctx)

Callers 1

ExecuteMethod · 0.95

Calls 6

AsValueFunction · 0.85
IsFloatMethod · 0.80
FloatMethod · 0.80
IntegerMethod · 0.80
EvaluateMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected