Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aymerick committed May 20, 2015
1 parent fe1cef3 commit 1a9eb74
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,25 @@ func (v *EvalVisitor) evalNodeWith(node ast.Node, ctx reflect.Value) string {
return result
}

// evaluates all path parts
func (v *EvalVisitor) evalPath(ctx reflect.Value, parts []string, exprRoot bool) reflect.Value {
for i := 0; i < len(parts); i++ {
part := parts[i]

// "[foo bar]"" => "foo bar"
if (len(part) >= 2) && (part[0] == '[') && (part[len(part)-1] == ']') {
part = part[1 : len(part)-1]
}

ctx = v.evalField(ctx, part, exprRoot)
if !ctx.IsValid() {
break
}
}

return ctx
}

// evaluates field in given context
func (v *EvalVisitor) evalField(ctx reflect.Value, fieldName string, exprRoot bool) reflect.Value {
result := zero
Expand Down Expand Up @@ -273,7 +292,7 @@ func (v *EvalVisitor) evalFunc(funcVal reflect.Value, exprRoot bool) reflect.Val
if exprRoot {
// create function arg with all params/hash
expr := v.curExpr()
arg = v.HelperArg(expr)
arg = v.helperArg(expr)

// ok, that expression was a function call
v.exprFunc[expr] = true
Expand All @@ -297,25 +316,6 @@ func (v *EvalVisitor) evalFunc(funcVal reflect.Value, exprRoot bool) reflect.Val
return resArr[0]
}

// evaluates all path parts
func (v *EvalVisitor) evalPath(ctx reflect.Value, parts []string, exprRoot bool) reflect.Value {
for i := 0; i < len(parts); i++ {
part := parts[i]

// "[foo bar]"" => "foo bar"
if (len(part) >= 2) && (part[0] == '[') && (part[len(part)-1] == ']') {
part = part[1 : len(part)-1]
}

ctx = v.evalField(ctx, part, exprRoot)
if !ctx.IsValid() {
break
}
}

return ctx
}

//
// Stringification
//
Expand Down Expand Up @@ -408,7 +408,7 @@ func (v *EvalVisitor) findHelper(name string) Helper {
}

// Computes helper argument from an expression
func (v *EvalVisitor) HelperArg(node *ast.Expression) *HelperArg {
func (v *EvalVisitor) helperArg(node *ast.Expression) *HelperArg {
var params []interface{}
var hash map[string]interface{}

Expand Down Expand Up @@ -606,7 +606,7 @@ func (v *EvalVisitor) VisitExpression(node *ast.Expression) interface{} {
// helper call
if helperName := node.HelperName(); helperName != "" {
if helper := v.findHelper(helperName); helper != nil {
result = helper(v.HelperArg(node))
result = helper(v.helperArg(node))
done = true
}
}
Expand Down

0 comments on commit 1a9eb74

Please sign in to comment.