about to start implimentation of if statments, and add not

This commit is contained in:
2023-03-11 15:26:25 +00:00
parent 3a449dec63
commit 27a1abe160
8 changed files with 65 additions and 19 deletions

40
src/not.go Normal file
View File

@@ -0,0 +1,40 @@
package main
import "strings"
var notCompiled = makeRegex(`( *)not (.|\n)+`)
type not struct {
value any
line int
code string
path string
}
func isnot(code UNPARSEcode) bool {
return notCompiled.MatchString(code.code)
}
func parseNot(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine int) (any, bool, ArErr, int) {
trimmed := strings.TrimSpace(code.code)
trimmed = trimmed[4:]
val, worked, err, step := translateVal(UNPARSEcode{
code: trimmed,
realcode: code.realcode,
line: code.line,
path: code.path,
}, index, codelines, isLine)
return not{
value: val,
line: code.line,
code: code.realcode,
path: code.path,
}, worked, err, step
}
func runNot(n not, stack stack, stacklevel int) (bool, ArErr) {
val, err := runVal(n.value, stack, stacklevel+1)
boolean := !anyToBool(val)
return boolean, err
}