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

// op-registry.go
package expr

const initialRegistryCapacity = 10

type termContructor func(tk *Token) *term

var constructorRegistry map[Symbol]termContructor = nil

func registerTermConstructor(sym Symbol, constructor termContructor) {
	if constructorRegistry == nil {
		constructorRegistry = make(map[Symbol]termContructor, initialRegistryCapacity)
	}
	constructorRegistry[sym] = constructor
}

func newTerm(tk *Token) (inst *term) {
	if constructorRegistry != nil {
		if construct, exists := constructorRegistry[tk.Sym]; exists {
			inst = construct(tk)
		}
	}
	return
}
