Expressions now support function definition

This commit is contained in:
2024-04-02 04:36:03 +02:00
parent f58ec3ac32
commit 072dab4144
20 changed files with 376 additions and 143 deletions
+6 -4
View File
@@ -4,8 +4,6 @@
// operator-assign.go
package expr
import "fmt"
//-------- assign term
func newAssignTerm(tk *Token) (inst *term) {
@@ -27,12 +25,16 @@ func evalAssign(ctx exprContext, self *term) (v any, err error) {
leftTerm := self.children[0]
if leftTerm.tk.Sym != SymIdentifier {
err = fmt.Errorf("left operand of %q must be a variable", self.tk.source)
err = leftTerm.tk.Errorf("left operand of %q must be a variable", self.tk.source)
return
}
if v, err = self.children[1].compute(ctx); err == nil {
ctx.SetValue(leftTerm.tk.source, v)
if functor, ok := v.(Functor); ok {
ctx.RegisterFunc(leftTerm.source(), functor, 0, -1)
} else {
ctx.SetValue(leftTerm.tk.source, v)
}
}
return
}