added type casts
This commit is contained in:
parent
77ce00970f
commit
8278430882
4 changed files with 72 additions and 1 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue