Expressions now support function definition
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||
// All rights reserved.
|
||||
|
||||
// operand-expr.go
|
||||
package expr
|
||||
|
||||
import "errors"
|
||||
|
||||
// -------- expr term
|
||||
func newExprTerm(tk *Token) *term {
|
||||
return &term{
|
||||
tk: *tk,
|
||||
class: classVar,
|
||||
kind: kindUnknown,
|
||||
parent: nil,
|
||||
children: nil,
|
||||
position: posLeaf,
|
||||
priority: priValue,
|
||||
evalFunc: evalExpr,
|
||||
}
|
||||
}
|
||||
|
||||
// -------- eval expr
|
||||
func evalExpr(ctx exprContext, self *term) (v any, err error) {
|
||||
if expr, ok := self.value().(Expr); ok {
|
||||
v, err = expr.Eval(ctx, false)
|
||||
} else {
|
||||
err = errors.New("invalid body of function definition")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// init
|
||||
// func init() {
|
||||
// registerTermConstructor(SymExpression, newExprTerm)
|
||||
// }
|
||||
Reference in New Issue
Block a user