From 08bf24874523c3b4e567cab46503c642a40f26f4 Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Mon, 9 Feb 2026 19:45:58 -0500 Subject: [PATCH] docs: codec --- cmd/lambda/registry.go | 2 +- pkg/saccharine/codec.go | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/lambda/registry.go b/cmd/lambda/registry.go index e0b3f57..404eda8 100644 --- a/cmd/lambda/registry.go +++ b/cmd/lambda/registry.go @@ -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 } diff --git a/pkg/saccharine/codec.go b/pkg/saccharine/codec.go index bbdb2c4..43c6e84 100644 --- a/pkg/saccharine/codec.go +++ b/pkg/saccharine/codec.go @@ -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)