validate

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package validate validates Scheme syntax and produces typed expressions.

The package converts syntax.SyntaxValue into typed ValidatedExpr values for the compiler, accumulating multiple errors without short-circuiting:

result := validate.ValidateExpression(ctx, env, expr)
if !result.Ok() {
    for _, err := range result.Errors {
        fmt.Println(err)
    }
}
validated := result.Expr

Validated Types

Hygiene

The validator supports local variable shadowing of special forms (R7RS 4.2.2) using Flatt's scope-set model for identifier resolution.

Index

Constants

View Source
const DefaultMaxOriginDepth = 10

DefaultMaxOriginDepth is the default maximum number of macro expansions to show in error messages. Set to 0 for unlimited depth.

Variables

This section is empty.

Functions

func BodyIsFrameReleasable

func BodyIsFrameReleasable(proc ValidatedBodyAndParams, selfName string, env *environment.EnvironmentFrame) bool

BodyIsFrameReleasable reports whether proc's activation frame may be released to the pool at its tail calls (the OpReleaseEnvFrame optimization — fib-shaped general tail recursion). Unlike OpSelfTailCall it does NOT rebind in place or hardcode a jump: it releases the dead frame and performs a normal apply (which re-resolves the callee). So it needs neither the define's stability nor a self-tail call — only that the body can never expose its frame to a continuation:

  • no capture operator in the body (no call/cc &c.),
  • no escaping closure, and
  • every callee is the self name or a capture-safe, non-rebindable primitive (bodyCalleesAllCaptureSafe) — a callee that could capture would pin the frame.

This is a conservative, per-body approximation of the interprocedural classifier (ClassifyFrameReclaim): it covers self-recursion over capture-safe primitives (fib, tak) but refuses a tail call to another user-defined function (mutual recursion), which the full call graph would admit. Sound either way; the call-graph precision is a later refinement.

func BodyIsSelfTailReusable

func BodyIsSelfTailReusable(
	proc ValidatedBodyAndParams,
	selfName string,
	env *environment.EnvironmentFrame,
) bool

BodyIsSelfTailReusable is the compiler entry point: it builds the production capture-operator identity test from env (hygiene-correct: a locally-shadowed call/cc is not the primitive) and runs the self-tail-reuse safety predicate. selfName is the closure's own bound name as a symbol Key.

NOTE: this is the IN-BODY safety half. The caller must additionally ensure the self BINDING is immutable against cross-unit redefinition — for a top-level define that means IsStable() at the emit site; for a lexical named-let loop the in-body ¬set! this predicate checks is the whole story.

func CallbackIsCaptureSafe

func CallbackIsCaptureSafe(arg ValidatedExpr, env *environment.EnvironmentFrame) bool

CallbackIsCaptureSafe reports whether a callback ARGUMENT at a call site is provably capture-safe — the D2 proof the inline-HOF dispatch (callback specialization Strategy A) requires before inlining a curated tail HOF's reclaiming loop with this callback substituted. Inlining a capturing callback into a frame-reclaiming loop would be a use-after-release, so this answers true only with positive proof; everything uncertain is false (the soundness asymmetry — a false negative merely forgoes the optimization).

Two positive forms:

  • a symbol resolving to a binding that is IsCaptureSafe() AND IsStable() — the same gate bodyCalleesAllCaptureSafe applies to a loop's callees: capture-safe (cannot invoke a Scheme procedure, so cannot capture) and stable (not rebindable to something that can), or
  • a lambda literal whose body ProcedureBodyIsCaptureSafe proves cannot capture the caller's continuation. selfName is "" — an argument callback is anonymous, so no callee is exempted as a self-recursive tail call.

Anything else — a procedure-invoking, unbound, or rebindable symbol; a lambda that runs a capture operator or a procedure-invoking callee; or a computed operator expression (neither symbol nor lambda) — returns false.

func ClassifyFrameReclaim

func ClassifyFrameReclaim(
	unit []ValidatedExpr,
	env *environment.EnvironmentFrame,
) map[string]bool

ClassifyFrameReclaim returns, for every top-level function define in unit, whether its frame is reclaimable at its tail calls. It is the exported entry point over the Layer-B/C internals: build the call graph, run the greatest-fixpoint mayCapture, and project to a name→verdict map. The verdict is conservative (any uncertainty ⇒ not reclaimable).

Same-unit-define immutability is read from the producer's Stable bit via env.GetBinding(...).IsStable() — the single source of truth, backed by Option-B enforcement (the set!-gate + the cross-unit redefine guard). The tier-(a) vs tier-(b) distinction is therefore a property of WHICH env is passed, not a classifier argument: an env whose same-unit defines are NOT stamped Stable (WithImmutableTopLevel off, or a non-compiled env) yields mutable same-unit edges (tier-(a) behavior); an env whose defines ARE Stable (WithImmutableTopLevel on, compiled) yields immutable edges (tier-(b)).

PRECONDITION: env must be the post-compile env for unit (bindings stamped). An un-stamped (validate-only) env reports IsStable()==false uniformly, yielding the conservative tier-(a) verdict with no diagnostic — sound for the optimizer but a silent artifact for a measurement (guard with a positive control).

func LetBindingSelfTailReusable

func LetBindingSelfTailReusable(v *ValidatedLet, i int, env *environment.EnvironmentFrame) (int, bool)

LetBindingSelfTailReusable reports the arity and eligibility of the i-th binding of a recursively-scoped let (letrec / letrec* / named-let) for in-place self-tail reuse — the local-binding analogue of selfTailForDefine. ok is true iff

  • the binding's Init is a lambda whose body is self-tail-reusable on the binding name (bodyIsSelfTailReusable), AND
  • the binding name is immutable across the WHOLE let: never set! in any binding init or in the let body.

The second clause is the local immutability story. bodyIsSelfTailReusable only inspects the lambda's own body, but a sibling init or the let body could set! the name, which would make a hardcoded jump-to-pc=0 unsound. A lexical letrec binding cannot be mutated from outside the let, so set!-freedom within the let is sufficient (no IsStable() is needed, unlike a top-level define).

PRECONDITION: the caller must ensure v.Kind is recursive (letrec-family) so the lambda can see itself; in a plain let/let* the name is not in scope in the init.

func ProcedureBodyIsCaptureSafe

func ProcedureBodyIsCaptureSafe(proc ValidatedBodyAndParams, selfName string, env *environment.EnvironmentFrame) bool

ProcedureBodyIsCaptureSafe reports whether CALLING proc can never capture the caller's continuation — the property that lets the frame-reclaim classifier trust proc as a callee. It is exactly bodyCannotCaptureCaller (BodyIsFrameReleasable MINUS the escaping-closure check): a procedure that merely builds and returns a closure does not capture the caller's continuation when called, so it is safe as a callee even though its own frame is not releasable.

The compiler stamps a define's binding CaptureSafe from this verdict (compile_define.go), so a proven-safe Scheme procedure — stdlib (zero?, not) or a user helper — is trusted exactly like a capture-safe primitive, without a hand-maintained whitelist. Conservative on forward references: a callee not yet stamped reads IsCaptureSafe()==false, so proc is left unstamped (sound — a missed stamp only forgoes the optimization).

func WalkBindingRefs

func WalkBindingRefs(
	expr ValidatedExpr,
	visit func(sym *syntax.SyntaxSymbol, role RefRole, depth int),
)

WalkBindingRefs walks expr recursively, calling visit for every *syntax.SyntaxSymbol reference encountered, with its role and closure-nesting depth.

depth is the number of escaping closure boundaries crossed (0 = same closure as expr). Immediately-applied lambdas (ValidatedLambda or ValidatedCaseLambda as the Proc of a ValidatedCall or ValidatedApply) do NOT increment depth, since the closure does not escape.

ValidatedSetBang emits a synthetic RefSetBangTarget visit for its target name, then recurses into its value expression as a normal walk (the value's symbol references appear as RefInBody at the same depth).

Symbols are NEVER yielded with RefInClosureBody; "is this inside a closure?" is the depth > 0 predicate.

Role tagging is shallow: RefInCallProc and RefSetBangTarget are reported only on direct symbol children of the surrounding form. A symbol nested inside a non-leaf call-proc child — for example, the inner `f` and `g` in `((if c f g) x)`, or the inner symbols of `((f x) y)` — is reported as RefInBody, not RefInCallProc. The role describes the slot the symbol IS, not the slot of any enclosing non-symbol expression.

func WalkSubExprs

func WalkSubExprs(expr ValidatedExpr, fn func(child ValidatedExpr, role ChildRole))

WalkSubExprs calls fn for every direct sub-expression of expr, reporting each child's structural role:

  • RoleCallProc: the operator of ValidatedCall and ValidatedApply
  • RoleClosureBody: body of ValidatedLambda, ValidatedCaseLambda clause, or ValidatedDefine (function form)
  • RoleNormal: everything else (arguments, inits, branches, sequence bodies)

ValidatedSetBang: walks only the value expression (RoleNormal). The set! target is mutation (tracked by Mutable), not a reference.

ValidatedSymbol has no children — fn is not called. The caller handles symbols directly before calling WalkSubExprs.

Types

type ChildRole

type ChildRole int

ChildRole describes the structural position of a sub-expression within its parent validated form.

const (
	// RoleNormal is the default: arguments, init expressions, branch arms,
	// body of begin/let/dynamic-wind/with-continuation-mark, define-variable value.
	RoleNormal ChildRole = iota

	// RoleCallProc is the operator position of ValidatedCall and ValidatedApply.
	RoleCallProc

	// RoleClosureBody is a body expression inside a closure boundary:
	// ValidatedLambda, ValidatedCaseLambda clause, or ValidatedDefine (function form).
	RoleClosureBody
)

type LetKind

type LetKind int

LetKind encodes the two orthogonal dimensions of binding form semantics: init-visibility (do inits see the bindings?) and evaluation order (all-then-store vs sequential store-as-you-go).

| Kind       | Inits see bindings? | Eval order      |
|------------|---------------------|-----------------|
| Let        | No (outer scope)    | All-then-store  |
| LetStar    | Preceding only      | Sequential      |
| Letrec     | All (full scope)    | All-then-store  |
| LetrecStar | All (full scope)    | Sequential      |
const (
	LetKindLet        LetKind = iota // R7RS §4.2.2: inits in outer scope, all-then-store
	LetKindLetStar                   // R7RS §4.2.2: inits see preceding, sequential
	LetKindLetrec                    // R7RS §4.2.2: inits in full scope, all-then-store
	LetKindLetrecStar                // R7RS §4.2.2: inits in full scope, sequential
)

func (LetKind) InitsInScope

func (p LetKind) InitsInScope() bool

InitsInScope reports whether init expressions see the let bindings.

func (LetKind) Sequential

func (p LetKind) Sequential() bool

Sequential reports whether init expressions are stored immediately (left-to-right) rather than all-then-store.

func (LetKind) String

func (p LetKind) String() string

String returns the Scheme keyword for this kind.

type RefRole

type RefRole int

RefRole describes the structural slot a symbol reference occupies. It is the "what role does this use play" axis, orthogonal to depth.

const (
	// RefInBody is a normal-position reference: argument, return value,
	// init expression, branch arm, sequence body, set! value, etc.
	// This is the default for any non-call-proc, non-set!-target reference.
	RefInBody RefRole = iota

	// RefInCallProc is the operator position of a ValidatedCall or
	// ValidatedApply (the "callee" slot).
	RefInCallProc

	// RefSetBangTarget is the target name of a ValidatedSetBang (the
	// symbol being mutated). The value expression of the set! is walked
	// separately as RefInBody.
	RefSetBangTarget
)

type ValidatedApply

type ValidatedApply struct {
	Proc       ValidatedExpr
	PrefixArgs []ValidatedExpr
	FinalList  ValidatedExpr
	// contains filtered or unexported fields
}

ValidatedApply represents (apply proc arg1 ... args)

R7RS §6.10: apply calls proc with the elements of the list (append (list arg1 ...) args) as arguments.

func (*ValidatedApply) FormName

func (p *ValidatedApply) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedApply) SetFormName

func (p *ValidatedApply) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedApply) Source

func (p *ValidatedApply) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedBegin

type ValidatedBegin struct {
	// contains filtered or unexported fields
}

ValidatedBegin represents (begin expr...)

func (*ValidatedBegin) Body

func (p *ValidatedBegin) Body() []ValidatedExpr

Body returns the sequence of expressions in this begin form.

func (*ValidatedBegin) FormName

func (p *ValidatedBegin) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedBegin) SetFormName

func (p *ValidatedBegin) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedBegin) Source

func (p *ValidatedBegin) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedBodyAndParams

type ValidatedBodyAndParams interface {
	Params() *ValidatedParams
	Body() []ValidatedExpr
	Docstring() string
}

ValidatedBodyAndParams provides access to parameters and body for procedure forms.

type ValidatedCall

type ValidatedCall struct {
	// contains filtered or unexported fields
}

ValidatedCall represents (proc arg...)

func (*ValidatedCall) Body

func (p *ValidatedCall) Body() []ValidatedExpr

Body returns the argument expressions for this call.

func (*ValidatedCall) FormName

func (p *ValidatedCall) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedCall) Proc

func (p *ValidatedCall) Proc() ValidatedExpr

Proc returns the procedure expression being called.

func (*ValidatedCall) SetFormName

func (p *ValidatedCall) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedCall) Source

func (p *ValidatedCall) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedCaseLambda

type ValidatedCaseLambda struct {
	// contains filtered or unexported fields
}

ValidatedCaseLambda represents (case-lambda [clause] ...)

func (*ValidatedCaseLambda) Clauses

Clauses returns the list of case-lambda clauses.

func (*ValidatedCaseLambda) FormName

func (p *ValidatedCaseLambda) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedCaseLambda) SetFormName

func (p *ValidatedCaseLambda) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedCaseLambda) Source

func (p *ValidatedCaseLambda) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedCaseLambdaClause

type ValidatedCaseLambdaClause struct {
	// contains filtered or unexported fields
}

ValidatedCaseLambdaClause represents a single clause in case-lambda

func (*ValidatedCaseLambdaClause) Body

func (p *ValidatedCaseLambdaClause) Body() []ValidatedExpr

Body returns the body expressions.

func (*ValidatedCaseLambdaClause) Docstring

func (p *ValidatedCaseLambdaClause) Docstring() string

Docstring returns the Guile-style docstring extracted from the body, or "" if no docstring was present.

func (*ValidatedCaseLambdaClause) FormName

func (p *ValidatedCaseLambdaClause) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedCaseLambdaClause) Params

func (p *ValidatedCaseLambdaClause) Params() *ValidatedParams

Params returns the parameter list.

func (*ValidatedCaseLambdaClause) SetFormName

func (p *ValidatedCaseLambdaClause) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedCaseLambdaClause) Source

func (p *ValidatedCaseLambdaClause) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedDefine

type ValidatedDefine struct {
	IsFunction bool // True for (define (name ...) ...)

	// StableInUnit reports that this define's name is defined exactly once and
	// never set! within the compilation unit the validator saw, computed
	// syntactically by symbol Key (conservative over-approximation: a same-Key
	// local set! or shadowing define marks it non-stable — a false match costs
	// optimization, never soundness). It is the in-unit evidence the compiler
	// consumes (only for top-level/global defines) to populate
	// BindingMeta.Stable when top-level immutability is enabled (the default). Stamped
	// by finalizeStability after the whole unit is validated.
	StableInUnit bool
	// contains filtered or unexported fields
}

ValidatedDefine represents both forms: (define name expr) and (define (name params...) body...)

func (*ValidatedDefine) Body

func (p *ValidatedDefine) Body() []ValidatedExpr

Body returns the body expressions.

func (*ValidatedDefine) Docstring

func (p *ValidatedDefine) Docstring() string

Docstring returns the Guile-style docstring extracted from the body, or "" if no docstring was present.

func (*ValidatedDefine) FormName

func (p *ValidatedDefine) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedDefine) Name

func (p *ValidatedDefine) Name() *syntax.SyntaxSymbol

Name returns the name being defined.

func (*ValidatedDefine) Params

func (p *ValidatedDefine) Params() *ValidatedParams

Params returns the parameter list.

func (*ValidatedDefine) SetFormName

func (p *ValidatedDefine) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedDefine) Source

func (p *ValidatedDefine) Source() *syntax.SourceContext

Source returns the source context for error reporting.

func (*ValidatedDefine) SubExp

func (p *ValidatedDefine) SubExp() ValidatedExpr

SubExp returns the value expression for simple definitions.

type ValidatedDynamicWind

type ValidatedDynamicWind struct {
	Before ValidatedExpr
	Thunk  ValidatedExpr
	After  ValidatedExpr
	// contains filtered or unexported fields
}

ValidatedDynamicWind represents (dynamic-wind before thunk after)

R7RS §6.10: dynamic-wind calls thunk without arguments, returning the result(s). Before is called whenever execution enters the dynamic extent of the call to thunk, and after is called whenever it exits.

func (*ValidatedDynamicWind) FormName

func (p *ValidatedDynamicWind) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedDynamicWind) SetFormName

func (p *ValidatedDynamicWind) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedDynamicWind) Source

func (p *ValidatedDynamicWind) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedExpr

type ValidatedExpr = forms.ValidatedExpr

ValidatedExpr is the interface for all validated expressions. The canonical definition lives in forms.ValidatedExpr to break the validate → forms ← machine import cycle.

type ValidatedIf

type ValidatedIf struct {
	Test   ValidatedExpr
	Conseq ValidatedExpr
	Alt    ValidatedExpr // nil if no alternative (will produce void)
	// contains filtered or unexported fields
}

ValidatedIf represents (if test conseq [alt])

func (*ValidatedIf) FormName

func (p *ValidatedIf) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedIf) SetFormName

func (p *ValidatedIf) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedIf) Source

func (p *ValidatedIf) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedLambda

type ValidatedLambda struct {
	// contains filtered or unexported fields
}

ValidatedLambda represents (lambda (params...) body...)

func (*ValidatedLambda) Body

func (p *ValidatedLambda) Body() []ValidatedExpr

Body returns the body expressions.

func (*ValidatedLambda) Docstring

func (p *ValidatedLambda) Docstring() string

Docstring returns the Guile-style docstring extracted from the body, or "" if no docstring was present.

func (*ValidatedLambda) FormName

func (p *ValidatedLambda) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedLambda) Params

func (p *ValidatedLambda) Params() *ValidatedParams

Params returns the parameter list.

func (*ValidatedLambda) SetFormName

func (p *ValidatedLambda) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedLambda) Source

func (p *ValidatedLambda) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedLet

type ValidatedLet struct {
	Kind     LetKind
	Bindings []ValidatedLetBinding
	Tag      *syntax.SyntaxSymbol
	// contains filtered or unexported fields
}

ValidatedLet represents all four R7RS binding forms: let, let*, letrec, letrec*. The Kind field encodes which form this is — the type is shared because the four forms differ only in two orthogonal dimensions (init visibility and evaluation order), not in structure. Tag is non-nil for named let (compiled with letrec semantics).

func NewValidatedLet

func NewValidatedLet(
	formName string,
	source *syntax.SourceContext,
	kind LetKind,
	bindings []ValidatedLetBinding,
	body []ValidatedExpr,
) *ValidatedLet

NewValidatedLet constructs a ValidatedLet from pre-validated components. Used by the compiler for synthetic let forms (e.g., procedure inlining). Callers must ensure all bindings and body expressions are individually validated — this constructor does not re-validate its inputs.

This is the only exported constructor in the validate package. Other validated types are constructed exclusively within the package. Add exported constructors for other types only when an external consumer requires them.

func (*ValidatedLet) Body

func (p *ValidatedLet) Body() []ValidatedExpr

Body returns the body expressions.

func (*ValidatedLet) FormName

func (p *ValidatedLet) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedLet) SetFormName

func (p *ValidatedLet) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedLet) Source

func (p *ValidatedLet) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedLetBinding

type ValidatedLetBinding struct {
	Name    *syntax.SyntaxSymbol
	Init    ValidatedExpr
	Mutable bool
	Escapes bool
	// CaptureSafe requests that the compiler stamp this binding CaptureSafe+Stable
	// when it creates it (callback specialization Strategy A, the unify path). Set
	// only on a synthetic let-binding for a callback the call site has already
	// proven capture-safe via CallbackIsCaptureSafe, so the inlined HOF loop calling
	// it passes bodyCalleesAllCaptureSafe and reclaims. Never set by the validator
	// on user source — only by the inline-HOF dispatch.
	CaptureSafe bool
}

ValidatedLetBinding represents a single (name init-expr) binding pair. Mutable is true if the binding is targeted by set! in the body. Escapes is true if the binding is referenced in a non-call position.

type ValidatedLiteral

type ValidatedLiteral struct {
	Value syntax.SyntaxValue
	// contains filtered or unexported fields
}

ValidatedLiteral represents self-evaluating data (numbers, strings, booleans, etc.) It's also used for passthrough forms like define-syntax, syntax-case, etc.

func (*ValidatedLiteral) FormName

func (p *ValidatedLiteral) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedLiteral) SetFormName

func (p *ValidatedLiteral) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedLiteral) Source

func (p *ValidatedLiteral) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedParams

type ValidatedParams struct {
	Required []*syntax.SyntaxSymbol
	Rest     *syntax.SyntaxSymbol // nil if no rest parameter
	// contains filtered or unexported fields
}

ValidatedParams represents a parameter list Handles: (a b c), (a b . rest), and just rest

type ValidatedProcedure

type ValidatedProcedure interface {
	ValidatedExpr
	ValidatedBodyAndParams
}

ValidatedProcedure represents a validated procedure form with parameters and body.

type ValidatedQuasiquote

type ValidatedQuasiquote struct {
	Template syntax.SyntaxValue // The raw template - quasiquote has complex runtime semantics
	// contains filtered or unexported fields
}

ValidatedQuasiquote represents (quasiquote template)

func (*ValidatedQuasiquote) FormName

func (p *ValidatedQuasiquote) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedQuasiquote) SetFormName

func (p *ValidatedQuasiquote) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedQuasiquote) Source

func (p *ValidatedQuasiquote) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedQuote

type ValidatedQuote struct {
	Datum syntax.SyntaxValue
	// contains filtered or unexported fields
}

ValidatedQuote represents (quote datum)

func (*ValidatedQuote) FormName

func (p *ValidatedQuote) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedQuote) SetFormName

func (p *ValidatedQuote) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedQuote) Source

func (p *ValidatedQuote) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedSetBang

type ValidatedSetBang struct {
	Name *syntax.SyntaxSymbol
	// contains filtered or unexported fields
}

ValidatedSetBang represents (set! name expr)

func (*ValidatedSetBang) FormName

func (p *ValidatedSetBang) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedSetBang) SetFormName

func (p *ValidatedSetBang) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedSetBang) Source

func (p *ValidatedSetBang) Source() *syntax.SourceContext

Source returns the source context for error reporting.

func (*ValidatedSetBang) SubExp

func (p *ValidatedSetBang) SubExp() ValidatedExpr

SubExp returns the value expression to be assigned.

type ValidatedSymbol

type ValidatedSymbol struct {
	Symbol *syntax.SyntaxSymbol
	// contains filtered or unexported fields
}

ValidatedSymbol represents a variable reference

func (*ValidatedSymbol) FormName

func (p *ValidatedSymbol) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedSymbol) SetFormName

func (p *ValidatedSymbol) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedSymbol) Source

func (p *ValidatedSymbol) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidatedWithContinuationMark

type ValidatedWithContinuationMark struct {
	Key  ValidatedExpr
	Val  ValidatedExpr
	Body ValidatedExpr
	// contains filtered or unexported fields
}

ValidatedWithContinuationMark represents (with-continuation-mark key val body)

Sets a continuation mark on the current frame during body evaluation. In tail position, the mark replaces any existing mark with the same key on the current frame. In non-tail position, the mark is removed after body completes.

func (*ValidatedWithContinuationMark) FormName

func (p *ValidatedWithContinuationMark) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedWithContinuationMark) SetFormName

func (p *ValidatedWithContinuationMark) SetFormName(nm string)

SetFormName sets the form name for error messages.

func (*ValidatedWithContinuationMark) Source

func (p *ValidatedWithContinuationMark) Source() *syntax.SourceContext

Source returns the source context for error reporting.

type ValidationError

type ValidationError struct {
	Source  *syntax.SourceContext
	Message string
	Form    string // p.g., "if", "define", "lambda"
}

ValidationError captures location and details for error reporting

func (ValidationError) Error

func (p ValidationError) Error() string

func (ValidationError) ErrorWithMaxOriginDepth

func (p ValidationError) ErrorWithMaxOriginDepth(maxDepth int) string

ErrorWithMaxOriginDepth returns the error message with a configurable origin chain depth.

type ValidationResult

type ValidationResult struct {
	Expr   ValidatedExpr     // nil if validation failed
	Errors []ValidationError // All errors encountered
	// contains filtered or unexported fields
}

ValidationResult collects all errors from validation

func ValidateExpression

func ValidateExpression(ctx context.Context, env *environment.EnvironmentFrame, expr syntax.SyntaxValue) *ValidationResult

ValidateExpression validates a syntax expression and returns a validated form or a list of errors. The env parameter provides the environment context for checking local variable shadowing of special forms (R7RS §4.2.2).

func (*ValidationResult) Error

func (p *ValidationResult) Error() string

func (*ValidationResult) Ok

func (p *ValidationResult) Ok() bool

Ok returns true if no validation errors were encountered.

Jump to

Keyboard shortcuts

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