hashicorp / hil

HIL is a small embedded language for string interpolations.
Mozilla Public License 2.0
395 stars 33 forks source link

Using hil as a predicate DSL #56

Open athoune opened 6 years ago

athoune commented 6 years ago

For now, hil always generate string, with hil.Parse and hil.Eval.

hil uses types, but some magic implicit conversion to string happens.

If you spy here : https://github.com/hashicorp/hil/blob/master/eval.go#L407 v.Exprs contains a chain of calls (and their arguments), something like Call(__builtin_BoolToString, Call(__builtin_IntCompare, Literal(TypeInt, 12), Literal(TypeInt, 2), Literal(TypeInt, 1))) for ${2 > 1} or Call(__builtin_IntToString, Literal(TypeInt, 42)) for ${ 42 }. The string conversion is in the executable AST tree.

I read all the steps, from scanner to parser to AST to eval, puts a lots of ugly fmt.Println, but I can't find where the implicit conversion to string happens.

Can you add some options for using hil as a simple script language that return typed result ?

athoune commented 6 years ago

OK, here, typeCheckOutput convert single value to string : https://github.com/hashicorp/hil/blob/master/check_types.go#L478

and Eval does the same : https://github.com/hashicorp/hil/blob/master/eval.go#L404