validate

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 7 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

This section is empty.

Types

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
}

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

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

Body returns the body expressions for this clause.

func (*ValidatedCaseLambdaClause) FormName

func (p *ValidatedCaseLambdaClause) FormName() string

FormName returns the name of the form for error messages.

func (*ValidatedCaseLambdaClause) Params

Params returns the parameter list for this clause.

func (*ValidatedCaseLambdaClause) SetFormName

func (p *ValidatedCaseLambdaClause) SetFormName(nm string)

SetFormName sets the form name for error messages.

type ValidatedDefine

type ValidatedDefine struct {
	IsFunction bool // True for (define (name ...) ...)
	// 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 for function definitions.

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 for function definitions.

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

Source returns the source context for error reporting.

type ValidatedExpr

type ValidatedExpr interface {
	SetFormName(name string)
	FormName() string
	Source() *syntax.SourceContext // Original source for error messages
}

ValidatedExpr is the interface for all validated expressions

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 for this lambda.

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 for this lambda.

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 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

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 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
}

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