expr/operand-const.go

74 lines
1.4 KiB
Go
Raw Normal View History

2024-03-26 08:45:18 +01:00
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
// All rights reserved.
2024-03-26 07:00:53 +01:00
// operand-const.go
package expr
// -------- bool const term
func newBoolTerm(tk *Token) *term {
return &term{
2024-04-09 05:32:50 +02:00
tk: *tk,
// class: classConst,
// kind: kindBool,
2024-03-26 07:00:53 +01:00
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{
2024-04-09 05:32:50 +02:00
tk: *tk,
// class: classConst,
// kind: kindFloat,
2024-03-26 07:00:53 +01:00
parent: nil,
children: nil,
position: posLeaf,
priority: priValue,
evalFunc: evalConst,
}
}
// -------- string const term
func newStringTerm(tk *Token) *term {
return &term{
2024-04-09 05:32:50 +02:00
tk: *tk,
// class: classConst,
// kind: kindString,
2024-03-26 07:00:53 +01:00
parent: nil,
children: nil,
position: posLeaf,
priority: priValue,
evalFunc: evalConst,
}
}
// -------- eval func
func evalConst(ctx ExprContext, self *term) (v any, err error) {
2024-03-26 07:00:53 +01:00
v = self.tk.Value
return
}
// init
func init() {
registerTermConstructor(SymString, newStringTerm)
registerTermConstructor(SymInteger, newIntegerTerm)
registerTermConstructor(SymFloat, newFloatTerm)
registerTermConstructor(SymBool, newBoolTerm)
}