docs: document remaining packages and simplify AST types #45

Merged
mvhutz merged 15 commits from docs/rest into main 2026-02-10 01:15:42 +00:00
2 changed files with 10 additions and 7 deletions
Showing only changes of commit 08bf248745 - Show all commits

View File

@@ -20,7 +20,7 @@ func GetRegistry() *registry.Registry {
// Marshalers
(registry.RegisterCodec(r, lambda.Marshaler{}, "lambda"))
(registry.RegisterCodec(r, saccharine.Marshaler{}, "saccharine"))
(registry.RegisterCodec(r, saccharine.Codec{}, "saccharine"))
return r
}

View File

@@ -1,14 +1,15 @@
// Package "saccharine" provides a simple language built on top of λ-calculus,
// to facilitate productive coding using it.
package saccharine
import (
"git.maximhutz.com/max/lambda/pkg/codec"
)
type Marshaler struct{}
// A Codec is a [codec.Codec] that serializes Saccharine expressions.
type Codec struct{}
func (m Marshaler) Decode(s string) (Expression, error) {
// Decode parses a string as Saccharine source code. Returns an error
// if it cannot.
func (c Codec) Decode(s string) (Expression, error) {
tokens, err := scan(s)
if err != nil {
return nil, err
@@ -17,8 +18,10 @@ func (m Marshaler) Decode(s string) (Expression, error) {
return parse(tokens)
}
func (m Marshaler) Encode(e Expression) (string, error) {
// Encode turns a Saccharine expression into a string. Returns an error if it
// cannot.
func (c Codec) Encode(e Expression) (string, error) {
return stringifyExpression(e), nil
}
var _ codec.Codec[Expression] = (*Marshaler)(nil)
var _ codec.Codec[Expression] = (*Codec)(nil)