|
|
|
@ -67,8 +67,8 @@ func ParseValue(val *Value) (interface{}, error) { |
|
|
|
|
// Return unquoted string
|
|
|
|
|
return strings.Trim(*val.String, `"`), nil |
|
|
|
|
} else if val.Bool != nil { |
|
|
|
|
// Return dereferenced boolean
|
|
|
|
|
return *val.Bool, nil |
|
|
|
|
// Return dereferenced Bool converted to bool
|
|
|
|
|
return bool(*val.Bool), nil |
|
|
|
|
} else if val.Float != nil { |
|
|
|
|
// Return dereferenced float
|
|
|
|
|
return *val.Float, nil |
|
|
|
@ -83,22 +83,32 @@ func ParseValue(val *Value) (interface{}, error) { |
|
|
|
|
return Vars[*val.VarVal], nil |
|
|
|
|
} else if val.Expr != nil { |
|
|
|
|
// Parse value of left side of expression
|
|
|
|
|
left, _ := ParseValue(val.Expr.Left) |
|
|
|
|
left, _ := callIfFunc(ParseValue(val.Expr.Left)) |
|
|
|
|
// If value is string, requote
|
|
|
|
|
if isStr(left) { |
|
|
|
|
left = requoteStr(left.(string)) |
|
|
|
|
} |
|
|
|
|
// Parse value of right side of expression
|
|
|
|
|
right, _ := ParseValue(val.Expr.Right) |
|
|
|
|
// If value is string, requote
|
|
|
|
|
if isStr(right) { |
|
|
|
|
right = requoteStr(right.(string)) |
|
|
|
|
// Create new nil string
|
|
|
|
|
var right string |
|
|
|
|
// For every right segment
|
|
|
|
|
for _, segment := range val.Expr.RightSegs { |
|
|
|
|
// Parse value of right segment, calling it if it is a function
|
|
|
|
|
rVal, _ := callIfFunc(ParseValue(segment.Right)) |
|
|
|
|
// If value is string, requote
|
|
|
|
|
if isStr(rVal) { |
|
|
|
|
rVal = requoteStr(rVal.(string)) |
|
|
|
|
} |
|
|
|
|
// Append right segment to right string
|
|
|
|
|
right = right + fmt.Sprintf( |
|
|
|
|
" %s %v", |
|
|
|
|
segment.Op, |
|
|
|
|
rVal, |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
// Create string expression from halves and operator
|
|
|
|
|
// Create string expression from segments and operator
|
|
|
|
|
exp := fmt.Sprintf( |
|
|
|
|
"%v %s %v", |
|
|
|
|
"%v %s", |
|
|
|
|
left, |
|
|
|
|
val.Expr.Op, |
|
|
|
|
right, |
|
|
|
|
) |
|
|
|
|
// Compile string expression
|
|
|
|
@ -132,6 +142,20 @@ func isStr(i interface{}) bool { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Call val if it is a function, otherwise pass through return values
|
|
|
|
|
func callIfFunc(val interface{}, err error) (interface{}, error) { |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
// If val is a pointer to a FuncCall
|
|
|
|
|
if IsFuncCall(val) { |
|
|
|
|
// Pass through return values of function call
|
|
|
|
|
return CallFunction(val.(*FuncCall)) |
|
|
|
|
} |
|
|
|
|
// Return given value
|
|
|
|
|
return val, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// UnwrapArgs takes a slice of Arg structs and returns a map
|
|
|
|
|
// storing the argument name and its value. If the argument has
|
|
|
|
|
// no name, its key will be an empty string
|
|
|
|
@ -164,8 +188,8 @@ func UnwrapArgs(args []*Arg) (map[string]interface{}, error) { |
|
|
|
|
|
|
|
|
|
// IsFuncCall checks if val is a FuncCall struct
|
|
|
|
|
func IsFuncCall(val interface{}) bool { |
|
|
|
|
// If type of val contains .FuncCall, return true
|
|
|
|
|
if strings.Contains(reflect.TypeOf(val).String(), ".FuncCall") { |
|
|
|
|
// If type of val is a pointer to FuncCall, return true
|
|
|
|
|
if reflect.TypeOf(val) == reflect.TypeOf(&FuncCall{}) { |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|