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

// term-constructor-registry.go
package scan

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
}
