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

// operator-plugin.go
package expr

//-------- plugin term

func newPluginTerm(tk *Token) (inst *term) {
	return &term{
		tk:       *tk,
		children: make([]*term, 0, 1),
		position: posPrefix,
		priority: priSign,
		evalFunc: evalPlugin,
	}
}

func evalPlugin(ctx ExprContext, opTerm *term) (v any, err error) {
	var childValue any
	var count int

	if childValue, err = opTerm.evalPrefix(ctx); err != nil {
		return
	}

	if count, err = importPluginFromSearchPath(childValue); err == nil {
		v = int64(count)
	}
	return
}

// init
func init() {
	registerTermConstructor(SymKwPlugin, newPluginTerm)
}
