// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
// All rights reserved.

// operand-const.go
package expr

// -------- bool const term
func newBoolTerm(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{
		tk:       *tk,
		class:    classConst,
		kind:     kindInteger,
		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,
		children: nil,
		position: posLeaf,
		priority: priValue,
		evalFunc: evalConst,
	}
}

// -------- eval func
func evalConst(ctx exprContext, self *term) (v any, err error) {
	v = self.tk.Value
	return
}

// init
func init() {
	registerTermConstructor(SymString, newStringTerm)
	registerTermConstructor(SymInteger, newIntegerTerm)
	registerTermConstructor(SymFloat, newFloatTerm)
	registerTermConstructor(SymBool, newBoolTerm)
}