style: restructure cli and registry packages (#43)

## Description

The `internal/cli` package had grown to contain both CLI utilities (source/destination I/O) and registry-level abstractions (repr, conversion, engine, marshaler).
This PR separates concerns by moving registry types into `internal/registry` and keeping only CLI I/O types in `internal/cli`.
It also simplifies several core abstractions and aligns naming conventions.

- Move `Source`, `Destination` from `internal/config` to `internal/cli`.
- Move `Repr`, `Conversion`, `Engine`, `Process`, `Codec` from `internal/cli` to `internal/registry`.
- Rename "marshalers" to "codecs" throughout the codebase.
- Simplify `codec.Codec[T, U]` to `codec.Codec[T]` (string-based marshaling only).
- Add `codec.Conversion[T, U]` as a function type alias.
- Change `engine.Engine[T]` from an interface to a function type.
- Merge `Engine.Load()` + `Process.Set()` into a single `Engine.Load(Repr)` call.
- Convert `Saccharine2Lambda` from a struct to standalone conversion functions.
- Replace registry methods (`MustAddMarshaler`, `MustAddEngine`, `MustAddConversions`) with generic free functions (`RegisterCodec`, `RegisterEngine`, `RegisterConversion`).
- Remove unused `internal/config` package (`Config`, `GetLogger`, `ParseFromArgs`).
- Remove unused `pkg/emitter` package.
- Rename `Id()` to `ID()` per Go conventions.
- Add documentation comments and enable `checkPublicInterface` lint rule.
- Rename `reduce_one.go` to `reduce_once.go`.

### Decisions

- `Engine[T]` is now a function type (`func(T) (Process[T], error)`) rather than an interface, since the only method was `Load`.
- `Codec[T, U]` was split into `Codec[T]` (string marshaling) and `Conversion[T, U]` (type-to-type conversion function), which better reflects how they are actually used.
- Registration uses free generic functions (`RegisterCodec`, `RegisterEngine`, `RegisterConversion`) instead of methods on `Registry`, enabling type inference at the call site.

## Benefits

- Clearer separation of concerns between CLI I/O and the registry's internal type system.
- Simpler abstractions: fewer interfaces, fewer wrapper types, fewer indirections.
- Removing unused packages (`config`, `emitter`) reduces maintenance burden.
- Naming conventions (`ID`, codecs, `reduce_once`) are more idiomatic.

## Checklist

- [x] Code follows conventional commit format.
- [x] Branch follows naming convention (`<type>/<description>`).
- [x] Tests pass (if applicable).
- [x] Documentation updated (if applicable).

Reviewed-on: #43
Co-authored-by: M.V. Hutz <git@maximhutz.me>
Co-committed-by: M.V. Hutz <git@maximhutz.me>
This commit was merged in pull request #43.
This commit is contained in:
2026-02-07 05:39:32 +00:00
committed by Maxim Hutz
parent 58d0823069
commit bbe027e9f4
29 changed files with 250 additions and 453 deletions

View File

@@ -1,3 +1,5 @@
// Package normalorder contains an engine that reduces a 'lambda.Expression'
// in the normal order.
package normalorder
import (
@@ -5,20 +7,20 @@ import (
"git.maximhutz.com/max/lambda/pkg/lambda"
)
type Process struct {
type process struct {
expr lambda.Expression
}
func (e Process) Get() (lambda.Expression, error) {
func (e process) Get() (lambda.Expression, error) {
return e.expr, nil
}
func (e *Process) Set(l lambda.Expression) error {
func (e *process) Set(l lambda.Expression) error {
e.expr = l
return nil
}
func (e *Process) Step(i int) bool {
func (e *process) Step(i int) bool {
for range i {
next, reduced := ReduceOnce(e.expr)
if !reduced {
@@ -31,12 +33,10 @@ func (e *Process) Step(i int) bool {
return true
}
type Engine struct {
// NewProcess creates a new redution process.
func NewProcess(expression lambda.Expression) (engine.Process[lambda.Expression], error) {
return &process{expr: expression}, nil
}
func (e Engine) Load() engine.Process[lambda.Expression] {
return &Process{}
}
var _ engine.Process[lambda.Expression] = (*Process)(nil)
var _ engine.Engine[lambda.Expression] = (*Engine)(nil)
var _ engine.Process[lambda.Expression] = (*process)(nil)
var _ engine.Engine[lambda.Expression] = NewProcess