style: rename repr to expr (#44)

## 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>
This commit was merged in pull request #44.
This commit is contained in:
2026-02-07 15:26:50 +00:00
committed by Maxim Hutz
parent bbe027e9f4
commit 1f486875fd
9 changed files with 54 additions and 50 deletions

View File

@@ -8,7 +8,7 @@ import (
)
type Codec interface {
codec.Codec[Repr]
codec.Codec[Expr]
InType() string
}
@@ -18,16 +18,16 @@ type convertedCodec[T any] struct {
inType string
}
func (c convertedCodec[T]) Decode(s string) (Repr, error) {
func (c convertedCodec[T]) Decode(s string) (Expr, error) {
t, err := c.codec.Decode(s)
if err != nil {
return nil, err
}
return NewRepr(c.inType, t), nil
return NewExpr(c.inType, t), nil
}
func (c convertedCodec[T]) Encode(r Repr) (string, error) {
func (c convertedCodec[T]) Encode(r Expr) (string, error) {
t, ok := r.Data().(T)
if !ok {
dataType := reflect.TypeOf(r.Data())

View File

@@ -10,7 +10,7 @@ type Conversion interface {
InType() string
OutType() string
Run(Repr) (Repr, error)
Run(Expr) (Expr, error)
}
type convertedConversion[T, U any] struct {
@@ -18,8 +18,8 @@ type convertedConversion[T, U any] struct {
inType, outType string
}
func (c convertedConversion[T, U]) Run(r Repr) (Repr, error) {
t, ok := r.Data().(T)
func (c convertedConversion[T, U]) Run(expr Expr) (Expr, error) {
t, ok := expr.Data().(T)
if !ok {
return nil, fmt.Errorf("could not parse '%v' as '%s'", t, c.inType)
}
@@ -29,7 +29,7 @@ func (c convertedConversion[T, U]) Run(r Repr) (Repr, error) {
return nil, err
}
return NewRepr(c.outType, u), nil
return NewExpr(c.outType, u), nil
}
func (c convertedConversion[T, U]) InType() string { return c.inType }

View File

@@ -7,7 +7,7 @@ import (
)
type Engine interface {
Load(Repr) (Process, error)
Load(Expr) (Process, error)
Name() string
InType() string
}
@@ -22,10 +22,10 @@ func (e convertedEngine[T]) InType() string { return e.inType }
func (e convertedEngine[T]) Name() string { return e.name }
func (e convertedEngine[T]) Load(r Repr) (Process, error) {
t, ok := r.Data().(T)
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'", r.ID(), e.inType)
return nil, fmt.Errorf("'ncorrent format '%s' for engine '%s'", expr.Repr(), e.inType)
}
process, err := e.engine(t)

24
internal/registry/expr.go Normal file
View File

@@ -0,0 +1,24 @@
package registry
// A Expr is a lambda calculus expression. It can have any type of
// Expresentation, so long as that class is known to the registry it is handled
// by.
type Expr interface {
// Repr returns the name of the underlying Expresentation. It is assumed if
// two expressions have the same Repr(), they have the same Expresentation.
Repr() string
// The base expression data.
Data() any
}
type baseExpr struct {
id string
data any
}
func (r baseExpr) Repr() string { return r.id }
func (r baseExpr) Data() any { return r.data }
func NewExpr(id string, data any) Expr { return baseExpr{id, data} }

View File

@@ -5,7 +5,7 @@ import (
)
type Process interface {
engine.Process[Repr]
engine.Process[Expr]
InType() string
}
@@ -17,13 +17,13 @@ type convertedProcess[T any] struct {
func (e convertedProcess[T]) InType() string { return e.inType }
func (b convertedProcess[T]) Get() (Repr, error) {
func (b convertedProcess[T]) Get() (Expr, error) {
s, err := b.process.Get()
if err != nil {
return nil, err
}
return NewRepr(b.inType, s), nil
return NewExpr(b.inType, s), nil
}
func (b convertedProcess[T]) Step(i int) bool {

View File

@@ -40,16 +40,18 @@ func (r *Registry) GetDefaultEngine(id string) (Engine, error) {
}
}
return nil, fmt.Errorf("no engine for '%s'", id)
return r.GetEngine("normalorder")
// return nil, fmt.Errorf("no engine for '%s'", id)
}
func (r *Registry) ConvertTo(repr Repr, outType string) (Repr, error) {
path, err := r.ConversionPath(repr.ID(), outType)
func (r *Registry) ConvertTo(expr Expr, outType string) (Expr, error) {
path, err := r.ConversionPath(expr.Repr(), outType)
if err != nil {
return nil, err
}
result := repr
result := expr
for _, conversion := range path {
result, err = conversion.Run(result)
if err != nil {
@@ -60,16 +62,16 @@ func (r *Registry) ConvertTo(repr Repr, outType string) (Repr, error) {
return result, err
}
func (r *Registry) Marshal(repr Repr) (string, error) {
m, ok := r.codecs[repr.ID()]
func (r *Registry) Marshal(expr Expr) (string, error) {
m, ok := r.codecs[expr.Repr()]
if !ok {
return "", fmt.Errorf("no marshaler for '%s'", repr.ID())
return "", fmt.Errorf("no marshaler for '%s'", expr.Repr())
}
return m.Encode(repr)
return m.Encode(expr)
}
func (r *Registry) Unmarshal(s string, outType string) (Repr, error) {
func (r *Registry) Unmarshal(s string, outType string) (Expr, error) {
m, ok := r.codecs[outType]
if !ok {
return nil, fmt.Errorf("no marshaler for '%s'", outType)

View File

@@ -1,24 +0,0 @@
package registry
// A Repr is a lambda calculus expression. It can have any type of
// representation, so long as that class is known to the registry it is handled
// by.
type Repr interface {
// ID returns the name of the underlying representation. It is assumed that
// if two expressions have the same Id(), they have the same representation.
ID() string
// The base expression data.
Data() any
}
type baseRepr struct {
id string
data any
}
func (r baseRepr) ID() string { return r.id }
func (r baseRepr) Data() any { return r.data }
func NewRepr(id string, data any) Repr { return baseRepr{id, data} }