PaesslerAG/gval

Add option to override functions to parse string/float/bool

lafriks opened this issue · 1 comments

Currently when defining language there is no way to override how float/string/bool are handled and to override behavior for example to be more strict for operations not to allow autocasting for example false || 1 will result in 1 being treated as boolean true or 1+'1' resulting into 2

Hello lafriks,

that's partially correct. The conversion is done by the Boolean Float operators. When you use only interface operators gval will not cast.

gval.InfixOperator("+", f func(a, b string) (interface{}, error){
numA, okA := a.(float64)
if !okA{
  return nil, yourError
}
...
return numA+numB, nil
}

When Go 1.18 is released I will do some experiments with generics that could lead to have a feature like this directly integrated into the language but I can't make any promises on this front.