added type casts
This commit is contained in:
parent
77ce00970f
commit
8278430882
4 changed files with 72 additions and 1 deletions
|
|
@ -29,6 +29,27 @@ import (
|
|||
// perhaps we simply write out arithmetic routines that operate on the strings
|
||||
// then we need not worry about storage length.
|
||||
|
||||
func num_cast(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
|
||||
in = in.Eval(f, a, false)
|
||||
if in.Tag != ast.STRING {
|
||||
log.Log(log.ERR,
|
||||
"only a string can successfully be cast to a number",
|
||||
"number_cast")
|
||||
return nil
|
||||
}
|
||||
|
||||
if !ast.StrIsNumber(in.Value()) {
|
||||
log.Log(log.ERR,
|
||||
"string failed number cast",
|
||||
"number_cast")
|
||||
return nil
|
||||
}
|
||||
|
||||
out := in.Copy()
|
||||
out.Tag = ast.NUMBER
|
||||
return out
|
||||
}
|
||||
|
||||
func add(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
|
||||
var res float64
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue