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 ¶
- ValidatedIf: (if test conseq [alt])
- ValidatedDefine: (define name expr) or (define (name params...) body...)
- ValidatedLambda: (lambda (params...) body...)
- ValidatedCaseLambda: (case-lambda [clause] ...)
- ValidatedSetBang: (set! name expr)
- ValidatedQuote: (quote datum)
- ValidatedBegin: (begin expr...)
- ValidatedCall: (proc arg...)
- ValidatedSymbol: variable reference
- ValidatedLiteral: self-evaluating or passthrough
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
- type LetKind
- type ValidatedApply
- type ValidatedBegin
- type ValidatedBodyAndParams
- type ValidatedCall
- type ValidatedCaseLambda
- type ValidatedCaseLambdaClause
- func (p *ValidatedCaseLambdaClause) Body() []ValidatedExpr
- func (p *ValidatedCaseLambdaClause) FormName() string
- func (p *ValidatedCaseLambdaClause) Params() *ValidatedParams
- func (p *ValidatedCaseLambdaClause) SetFormName(nm string)
- func (p *ValidatedCaseLambdaClause) Source() *syntax.SourceContext
- type ValidatedDefine
- func (p *ValidatedDefine) Body() []ValidatedExpr
- func (p *ValidatedDefine) FormName() string
- func (p *ValidatedDefine) Name() *syntax.SyntaxSymbol
- func (p *ValidatedDefine) Params() *ValidatedParams
- func (p *ValidatedDefine) SetFormName(nm string)
- func (p *ValidatedDefine) Source() *syntax.SourceContext
- func (p *ValidatedDefine) SubExp() ValidatedExpr
- type ValidatedDynamicWind
- type ValidatedExpr
- type ValidatedIf
- type ValidatedLambda
- type ValidatedLet
- type ValidatedLetBinding
- type ValidatedLiteral
- type ValidatedParams
- type ValidatedProcedure
- type ValidatedQuasiquote
- type ValidatedQuote
- type ValidatedSetBang
- type ValidatedSymbol
- type ValidatedWithContinuationMark
- type ValidationError
- type ValidationResult
Constants ¶
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 LetKind ¶ added in v1.9.4
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 |
func (LetKind) InitsInScope ¶ added in v1.9.4
InitsInScope reports whether init expressions see the let bindings.
func (LetKind) Sequential ¶ added in v1.9.4
Sequential reports whether init expressions are stored immediately (left-to-right) rather than all-then-store.
type ValidatedApply ¶ added in v1.5.0
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 ¶ added in v1.5.0
func (p *ValidatedApply) FormName() string
FormName returns the name of the form for error messages.
func (*ValidatedApply) SetFormName ¶ added in v1.5.0
func (p *ValidatedApply) SetFormName(nm string)
SetFormName sets the form name for error messages.
func (*ValidatedApply) Source ¶ added in v1.5.0
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
}
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 ¶
func (p *ValidatedCaseLambda) Clauses() []*ValidatedCaseLambdaClause
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) 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 ¶ added in v1.4.0
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 ...) ...)
// 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) 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) 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 ¶ added in v1.9.4
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 (*ValidatedLet) Body ¶ added in v1.9.4
func (p *ValidatedLet) Body() []ValidatedExpr
Body returns the body expressions.
func (*ValidatedLet) FormName ¶ added in v1.9.4
func (p *ValidatedLet) FormName() string
FormName returns the name of the form for error messages.
func (*ValidatedLet) SetFormName ¶ added in v1.9.4
func (p *ValidatedLet) SetFormName(nm string)
SetFormName sets the form name for error messages.
func (*ValidatedLet) Source ¶ added in v1.9.4
func (p *ValidatedLet) Source() *syntax.SourceContext
Source returns the source context for error reporting.
type ValidatedLetBinding ¶ added in v1.9.4
type ValidatedLetBinding struct {
Name *syntax.SyntaxSymbol
Init ValidatedExpr
Mutable bool
}
ValidatedLetBinding represents a single (name init-expr) binding pair. Mutable is true if the binding is targeted by set! in the body.
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 ¶ added in v1.7.0
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 ¶ added in v1.7.0
func (p *ValidatedWithContinuationMark) FormName() string
FormName returns the name of the form for error messages.
func (*ValidatedWithContinuationMark) SetFormName ¶ added in v1.7.0
func (p *ValidatedWithContinuationMark) SetFormName(nm string)
SetFormName sets the form name for error messages.
func (*ValidatedWithContinuationMark) Source ¶ added in v1.7.0
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.