deps: Update hashicorp/hil to latest

pull/5605/head
James Nugent 10 years ago
parent ba45f44856
commit e1223b4491

4
Godeps/Godeps.json generated

@ -685,11 +685,11 @@
},
{
"ImportPath": "github.com/hashicorp/hil",
"Rev": "0457360d54ca4d081a769eaa1617e0462153fd70"
"Rev": "1586b586f59cfa528a751d4a62be88910d34e6e9"
},
{
"ImportPath": "github.com/hashicorp/hil/ast",
"Rev": "0457360d54ca4d081a769eaa1617e0462153fd70"
"Rev": "1586b586f59cfa528a751d4a62be88910d34e6e9"
},
{
"ImportPath": "github.com/hashicorp/logutils",

@ -22,6 +22,7 @@ func registerBuiltins(scope *ast.BasicScope) *ast.BasicScope {
scope.FuncMap["__builtin_IntToFloat"] = builtinIntToFloat()
scope.FuncMap["__builtin_IntToString"] = builtinIntToString()
scope.FuncMap["__builtin_StringToInt"] = builtinStringToInt()
scope.FuncMap["__builtin_StringToFloat"] = builtinStringToFloat()
// Math operations
scope.FuncMap["__builtin_IntMath"] = builtinIntMath()
@ -142,3 +143,18 @@ func builtinStringToInt() ast.Function {
},
}
}
func builtinStringToFloat() ast.Function {
return ast.Function{
ArgTypes: []ast.Type{ast.TypeString},
ReturnType: ast.TypeFloat,
Callback: func(args []interface{}) (interface{}, error) {
v, err := strconv.ParseFloat(args[0].(string), 64)
if err != nil {
return nil, err
}
return v, nil
},
}
}

@ -251,7 +251,7 @@ func (tc *typeCheckConcat) TypeCheck(v *TypeCheck) (ast.Node, error) {
}
return nil, fmt.Errorf(
"argument %d must be a string", i+1)
"output of an HIL expression must be a string (argument %d is %s)", i+1, t)
}
}

@ -41,7 +41,8 @@ func Eval(root ast.Node, config *EvalConfig) (interface{}, ast.Type, error) {
ast.TypeString: "__builtin_IntToString",
},
ast.TypeString: {
ast.TypeInt: "__builtin_StringToInt",
ast.TypeInt: "__builtin_StringToInt",
ast.TypeFloat: "__builtin_StringToFloat",
},
}

Loading…
Cancel
Save