## Description The `Repr` type name was unclear — it was intended to represent a lambda calculus expression, not a "representation." This PR renames `Repr` to `Expr` throughout the registry package for clarity. - Rename `Repr` interface to `Expr` and `baseRepr` struct to `baseExpr`. - Rename `repr.go` to `expr.go`. - Rename `ID()` method to `Repr()` to indicate the representation type. - Rename `NewRepr` constructor to `NewExpr`. - Update all usages in codec, conversion, engine, process, and registry files. - Add command aliases `conv` and `eng` for `convert` and `engine` subcommands. ## Benefits - The naming better reflects the domain: an `Expr` is an expression, and `Repr()` returns its representation kind. - Command aliases reduce typing for common subcommands. ## Checklist - [x] Code follows conventional commit format. - [x] Branch follows naming convention (`<type>/<description>`). Always use underscores. - [x] Tests pass (if applicable). - [x] Documentation updated (if applicable). Reviewed-on: #44 Co-authored-by: M.V. Hutz <git@maximhutz.me> Co-committed-by: M.V. Hutz <git@maximhutz.me>
47 lines
984 B
Go
47 lines
984 B
Go
package registry
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.maximhutz.com/max/lambda/pkg/engine"
|
|
)
|
|
|
|
type Engine interface {
|
|
Load(Expr) (Process, error)
|
|
Name() string
|
|
InType() string
|
|
}
|
|
|
|
type convertedEngine[T any] struct {
|
|
engine engine.Engine[T]
|
|
name string
|
|
inType string
|
|
}
|
|
|
|
func (e convertedEngine[T]) InType() string { return e.inType }
|
|
|
|
func (e convertedEngine[T]) Name() string { return e.name }
|
|
|
|
func (e convertedEngine[T]) Load(expr Expr) (Process, error) {
|
|
t, ok := expr.Data().(T)
|
|
if !ok {
|
|
return nil, fmt.Errorf("'ncorrent format '%s' for engine '%s'", expr.Repr(), e.inType)
|
|
}
|
|
|
|
process, err := e.engine(t)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return convertedProcess[T]{process, e.inType}, nil
|
|
}
|
|
|
|
func RegisterEngine[T any](registry *Registry, e engine.Engine[T], name, inType string) error {
|
|
if _, ok := registry.engines[name]; ok {
|
|
return fmt.Errorf("engine '%s' already registered", name)
|
|
}
|
|
|
|
registry.engines[name] = &convertedEngine[T]{e, name, inType}
|
|
return nil
|
|
}
|