added type casts

This commit is contained in:
Aidan 2020-07-18 00:22:43 -07:00
parent 77ce00970f
commit 8278430882
No known key found for this signature in database
GPG key ID: 327711E983899316
4 changed files with 72 additions and 1 deletions

View file

@ -23,6 +23,28 @@ import (
"gitlab.com/whom/shs/ast"
)
func bool_cast(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
in = in.Eval(ft, vt, false)
if in.Tag == ast.LIST || in.Tag == ast.NUMBER {
log.Log(log.ERR,
"only strings successfully cast to bool",
"bool cast")
return nil
}
body := in.Value()
if body != ast.TRUE && body != ast.FALSE {
log.Log(log.ERR,
"cast to bool failed",
"bool cast")
return nil
}
res := &ast.Token{ Tag: ast.BOOL }
res.Set(body)
return res
}
func not(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
in = in.Eval(ft, vt, false)