MCPcopy
hub / github.com/TomWright/dasel / basicBinaryExpressionExecutorFn

Function basicBinaryExpressionExecutorFn

execution/execute_binary.go:15–54  ·  view source on GitHub ↗
(handler func(ctx context.Context, left *model.Value, right *model.Value, e ast.BinaryExpr) (*model.Value, error))

Source from the content-addressed store, hash-verified

13type binaryExpressionExecutorFn func(ctx context.Context, expr ast.BinaryExpr, value *model.Value, options *Options) (*model.Value, error)
14
15func basicBinaryExpressionExecutorFn(handler func(ctx context.Context, left *model.Value, right *model.Value, e ast.BinaryExpr) (*model.Value, error)) binaryExpressionExecutorFn {
16 return func(ctx context.Context, expr ast.BinaryExpr, value *model.Value, options *Options) (*model.Value, error) {
17 left, err := ExecuteAST(ctx, expr.Left, value, options)
18 if err != nil {
19 return nil, fmt.Errorf("error evaluating left expression: %w", err)
20 }
21
22 if !left.IsBranch() {
23 right, err := ExecuteAST(ctx, expr.Right, value, options)
24 if err != nil {
25 return nil, fmt.Errorf("error evaluating right expression: %w", err)
26 }
27 res, err := handler(ctx, left, right, expr)
28 if err != nil {
29 return nil, err
30 }
31 return res, nil
32 }
33
34 res := model.NewSliceValue()
35 res.MarkAsBranch()
36 if err := left.RangeSlice(func(i int, v *model.Value) error {
37 right, err := ExecuteAST(ctx, expr.Right, v, options)
38 if err != nil {
39 return fmt.Errorf("error evaluating right expression: %w", err)
40 }
41 r, err := handler(ctx, v, right, expr)
42 if err != nil {
43 return err
44 }
45 if err := res.Append(r); err != nil {
46 return err
47 }
48 return nil
49 }); err != nil {
50 return nil, err
51 }
52 return res, nil
53 }
54}
55
56var binaryExpressionExecutors = map[lexer.TokenKind]binaryExpressionExecutorFn{}
57

Callers 1

initFunction · 0.85

Calls 6

NewSliceValueFunction · 0.92
ExecuteASTFunction · 0.85
IsBranchMethod · 0.80
MarkAsBranchMethod · 0.80
RangeSliceMethod · 0.80
AppendMethod · 0.80

Tested by

no test coverage detected