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

// operand-literal.go
package expr

import (
	"git.portale-stac.it/go-pkg/expr/kern"
	"git.portale-stac.it/go-pkg/expr/scan"
)

// -------- literal term
func newLiteralTerm(tk *scan.Token) *scan.Term {
	return &scan.Term{
		Tk:       *tk,
		Parent:   nil,
		Children: nil,
		Position: scan.PosLeaf,
		Priority: scan.PriValue,
		EvalFunc: evalLiteral,
	}
}

// -------- eval func
func evalLiteral(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
	v = opTerm.Tk.Value
	return
}

// init
func init() {
	scan.RegisterTermConstructor(scan.SymString, newLiteralTerm)
	scan.RegisterTermConstructor(scan.SymInteger, newLiteralTerm)
	scan.RegisterTermConstructor(scan.SymFloat, newLiteralTerm)
	scan.RegisterTermConstructor(scan.SymFraction, newLiteralTerm)
	scan.RegisterTermConstructor(scan.SymBool, newLiteralTerm)
	scan.RegisterTermConstructor(scan.SymKwNil, newLiteralTerm)
}
