31 lines
673 B
Go
31 lines
673 B
Go
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// operand-expr.go
|
|
package expr
|
|
|
|
import "fmt"
|
|
|
|
// -------- expr term
|
|
func newExprTerm(root *term) *term {
|
|
tk := NewValueToken(root.tk.row, root.tk.col, SymExpression, root.source(), root)
|
|
return &term{
|
|
tk: *tk,
|
|
parent: nil,
|
|
children: nil,
|
|
position: posLeaf,
|
|
priority: priValue,
|
|
evalFunc: evalExpr,
|
|
}
|
|
}
|
|
|
|
// -------- eval expr
|
|
func evalExpr(ctx ExprContext, opTerm *term) (v any, err error) {
|
|
if expr, ok := opTerm.value().(*term); ok {
|
|
v, err = expr.compute(ctx)
|
|
} else {
|
|
err = fmt.Errorf("expression expected, got %T", opTerm.value())
|
|
}
|
|
return
|
|
}
|