forms

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package forms provides a unified registry for special form handlers.

The package maps Scheme keywords (if, lambda, define, etc.) to their validation and compilation functions. This decouples the validate and machine packages by providing a shared dispatch table.

Registration

forms.RegisterValidator("if", validateIf)
forms.RegisterCompiler("if", compileIf)

Lookup

spec := forms.Lookup("if")
if spec != nil && spec.Validate != nil {
    result := spec.Validate(ctx, env, pair, validationResult)
}

The registry uses [any] for function parameter types to break circular import cycles. Type safety is enforced at call sites via runtime assertions.

Package forms provides a unified registry for special form handlers. It maps keywords to their validation and compilation functions, allowing both the validate and machine packages to share the same dispatch table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Names

func Names() []string

Names returns all registered form names.

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 RegisterCompiler

func RegisterCompiler(name string, fn CompilerFunc)

RegisterCompiler sets the compiler for an existing form or creates a new entry.

func RegisterValidator

func RegisterValidator(name string, fn ValidatorFunc)

RegisterValidator sets the validator for an existing form or creates a new entry.

Types

type CompilerFunc

type CompilerFunc func(ctc any, ctctx any, expr any) error

CompilerFunc is the signature for compilation functions. Parameters:

  • ctc: *machine.CompileTimeContinuation - compiler state
  • ctctx: machine.CompileTimeCallContext - call context
  • expr: validate.ValidatedExpr - the validated expression

Returns: error

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

	// Compile is called during compilation to emit bytecode.
	// If nil, the form cannot be compiled (error).
	Compile CompilerFunc
}

FormSpec defines how a special form is validated and compiled.

func Lookup

func Lookup(name string) *FormSpec

Lookup returns the FormSpec for a keyword, or nil if not found.

type ValidatorFunc

type ValidatorFunc func(ctx context.Context, env any, pair any, result any) any

ValidatorFunc is the signature for validation functions. Parameters:

  • ctx: context for cancellation
  • env: *environment.EnvironmentFrame - for checking local variable shadowing
  • pair: *syntax.SyntaxPair - the form to validate
  • result: *validate.ValidationResult - collects errors

Returns: validate.ValidatedExpr

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL