docs: document remaining packages and simplify AST types #45
@@ -19,7 +19,7 @@ func GetRegistry() *registry.Registry {
|
||||
(registry.RegisterEngine(r, normalorder.NewProcess, "normalorder", "lambda"))
|
||||
|
||||
// Marshalers
|
||||
(registry.RegisterCodec(r, lambda.Marshaler{}, "lambda"))
|
||||
(registry.RegisterCodec(r, lambda.Codec{}, "lambda"))
|
||||
(registry.RegisterCodec(r, saccharine.Codec{}, "saccharine"))
|
||||
|
||||
return r
|
||||
|
||||
@@ -6,12 +6,18 @@ import (
|
||||
"git.maximhutz.com/max/lambda/pkg/codec"
|
||||
)
|
||||
|
||||
// A Codec is a [codec.Codec] that serializes lambda calculus expressions.
|
||||
// Decode is not implemented and always returns an error.
|
||||
// Encode stringifies an expression using standard lambda notation.
|
||||
type Codec struct{}
|
||||
|
||||
// Decode parses a string as lambda calculus. Returns an error if it cannot.
|
||||
func (m Codec) Decode(string) (Expression, error) {
|
||||
return nil, fmt.Errorf("unimplemented")
|
||||
}
|
||||
|
||||
// Encode turns a lambda calculus expression into a string. Returns an error if
|
||||
// it cannot.
|
||||
func (m Codec) Encode(e Expression) (string, error) {
|
||||
return Stringify(e), nil
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
// Package lambda defines the AST for the untyped lambda calculus.
|
||||
package lambda
|
||||
|
||||
// Expression is the interface for all lambda calculus expression types.
|
||||
// It embeds the general expr.Expression interface for cross-mode compatibility.
|
||||
// An Expression is a node in the lambda calculus abstract syntax tree.
|
||||
// It is a sealed interface; only types in this package may implement it.
|
||||
type Expression interface {
|
||||
expression()
|
||||
}
|
||||
|
||||
// An Abstraction binds a single parameter over a body expression.
|
||||
type Abstraction struct {
|
||||
Parameter string
|
||||
Body Expression
|
||||
@@ -13,6 +15,7 @@ type Abstraction struct {
|
||||
|
||||
func (a Abstraction) expression() {}
|
||||
|
||||
// An Application applies an abstraction to a single argument.
|
||||
type Application struct {
|
||||
Abstraction Expression
|
||||
Argument Expression
|
||||
@@ -20,6 +23,7 @@ type Application struct {
|
||||
|
||||
func (a Application) expression() {}
|
||||
|
||||
// A Variable is a named reference to a bound or free variable.
|
||||
type Variable struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user