Documentation
¶
Overview ¶
Package forms provides a shared registry for special form validators.
The package maps Scheme keywords (if, lambda, define, etc.) to their validation functions. This decouples the validate and machine/compilation packages by providing a shared name table that both can reference.
Compiler dispatch lives in machine/compilation with fully typed function signatures (no [any] parameters).
Registration ¶
forms.RegisterValidator("if", validateIf)
Lookup ¶
spec := forms.Lookup("if")
if spec != nil && spec.Validate != nil {
result := spec.Validate(ctx, env, pair, validationResult)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(spec *FormSpec)
Register adds a FormSpec to the registry. If a spec with the same name exists, it is replaced.
func RegisterValidator ¶
func RegisterValidator(name string, fn ValidatorFunc)
RegisterValidator sets the validator for an existing form or creates a new entry.
func Verify ¶ added in v1.7.0
func Verify() error
Verify checks that every registered form has a validator. Returns an error listing any forms with missing validators, or nil if all are consistent.
Compiler registration consistency is checked separately by machine/compilation.VerifyCompilers, which has access to the typed compiler registry without requiring any type erasure.
Types ¶
type FormSpec ¶
type FormSpec struct {
// Name is the keyword that triggers this form (e.g., "if", "lambda").
Name string
// Validate is called during the validation phase to produce a ValidatedExpr.
// If nil, the form passes through as ValidatedLiteral.
Validate ValidatorFunc
}
FormSpec defines how a special form is validated.
The result parameter in ValidatorFunc uses [any] to break the forms → validate import cycle. Type safety is restored at registration time in validate/register.go.
Compiler dispatch lives in machine/compilation (typed, no [any]).
type ValidatedExpr ¶ added in v1.6.0
type ValidatedExpr interface {
SetFormName(name string)
FormName() string
Source() *syntax.SourceContext
}
ValidatedExpr is the interface for all validated expressions. It lives in the forms package (rather than validate) to break the validate → forms ← machine import cycle while preserving type safety.
type ValidatorFunc ¶
type ValidatorFunc func(ctx context.Context, env *environment.EnvironmentFrame, pair *syntax.SyntaxPair, result any) ValidatedExpr
ValidatorFunc is the signature for validation functions. The result parameter remains [any] (*validate.ValidationResult) because validate imports forms, so forms cannot import validate.