mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
add while and forever loops
This commit is contained in:
42
src/boolean.go
Normal file
42
src/boolean.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user