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,52 +4,10 @@
// 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{ return &term{
tk: *tk, 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{
tk: *tk,
parent: nil,
children: nil,
position: posLeaf,
priority: priValue,
evalFunc: evalConst,
}
}
// -------- 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, parent: nil,
children: nil, children: nil,
position: posLeaf, position: posLeaf,
@ -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)
} }