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

// operand-literal.go
package expr

// -------- literal term
func newLiteralTerm(tk *Token) *term {
	return &term{
		tk:       *tk,
		parent:   nil,
		children: nil,
		position: posLeaf,
		priority: priValue,
		evalFunc: evalLiteral,
	}
}

// -------- eval func
func evalLiteral(ctx ExprContext, opTerm *term) (v any, err error) {
	v = opTerm.tk.Value
	return
}

// init
func init() {
	registerTermConstructor(SymString, newLiteralTerm)
	registerTermConstructor(SymInteger, newLiteralTerm)
	registerTermConstructor(SymFloat, newLiteralTerm)
	registerTermConstructor(SymFraction, newLiteralTerm)
	registerTermConstructor(SymBool, newLiteralTerm)
	registerTermConstructor(SymKwNil, newLiteralTerm)
}
