add while and forever loops

This commit is contained in:
2023-03-12 01:10:31 +00:00
parent 27a1abe160
commit 4619f1c278
23 changed files with 655 additions and 112 deletions

42
src/boolean.go Normal file
View File

@@ -0,0 +1,42 @@
package main
import "strings"
func anyToBool(x any) bool {
switch x := x.(type) {
case string:
return x != ""
case number:
return x.Cmp(newNumber()) != 0
case bool:
return x
case nil:
return false
case ArMap:
return len(x) != 0
case builtinFunc:
return true
case Callable:
return true
case ArClass:
return true
default:
return true
}
}
var booleanCompile = makeRegex(`( )*(true|false|null)( )*`)
func isBoolean(code UNPARSEcode) bool {
return booleanCompile.MatchString(code.code)
}
func parseBoolean(code UNPARSEcode) (any, bool, ArErr, int) {
trim := strings.TrimSpace(code.code)
if trim == "true" {
return true, true, ArErr{}, 1
} else if trim == "false" {
return false, true, ArErr{}, 1
}
return nil, true, ArErr{}, 1
}