all constant value are now stored in the same data struct (same constructor). Also nil const added

This commit is contained in:
Celestino Amoroso 2024-04-20 05:39:49 +02:00
parent 04f934ab04
commit 15bbfacd47

View File

@ -4,22 +4,8 @@
// operand-const.go // operand-const.go
package expr package expr
// -------- bool const term // -------- const term
func newBoolTerm(tk *Token) *term { func newConstTerm(tk *Token) *term {
return &term{
tk: *tk,
// class: classConst,
// kind: kindBool,
parent: nil,
children: nil,
position: posLeaf,
priority: priValue,
evalFunc: evalConst,
}
}
// -------- integer const term
func newIntegerTerm(tk *Token) *term {
return &term{ return &term{
tk: *tk, tk: *tk,
parent: nil, parent: nil,
@ -30,34 +16,6 @@ func newIntegerTerm(tk *Token) *term {
} }
} }
// -------- float const term
func newFloatTerm(tk *Token) *term {
return &term{
tk: *tk,
// class: classConst,
// kind: kindFloat,
parent: nil,
children: nil,
position: posLeaf,
priority: priValue,
evalFunc: evalConst,
}
}
// -------- string const term
func newStringTerm(tk *Token) *term {
return &term{
tk: *tk,
// class: classConst,
// kind: kindString,
parent: nil,
children: nil,
position: posLeaf,
priority: priValue,
evalFunc: evalConst,
}
}
// -------- eval func // -------- eval func
func evalConst(ctx ExprContext, self *term) (v any, err error) { func evalConst(ctx ExprContext, self *term) (v any, err error) {
v = self.tk.Value v = self.tk.Value
@ -66,8 +24,9 @@ func evalConst(ctx ExprContext, self *term) (v any, err error) {
// init // init
func init() { func init() {
registerTermConstructor(SymString, newStringTerm) registerTermConstructor(SymString, newConstTerm)
registerTermConstructor(SymInteger, newIntegerTerm) registerTermConstructor(SymInteger, newConstTerm)
registerTermConstructor(SymFloat, newFloatTerm) registerTermConstructor(SymFloat, newConstTerm)
registerTermConstructor(SymBool, newBoolTerm) registerTermConstructor(SymBool, newConstTerm)
registerTermConstructor(SymKwNil, newConstTerm)
} }