codewalk

package
v1.74.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package codewalk adapts the interpreter's syntax walker for source analysis. The resolver's historical interpretation of malformed forms, qualification, template references and custom definitions is internal tooling policy.

Index

Constants

View Source
const (
	ScopeFunction  = hook.ScopeFunction
	ScopeAnonymous = hook.ScopeAnonymous
	ScopeLocal     = hook.ScopeLocal
	ScopeFunctions = hook.ScopeFunctions
	ScopeMacros    = hook.ScopeMacros
	ScopeLoop      = hook.ScopeLoop
	ScopeTest      = hook.ScopeTest
)
View Source
const (
	Parameters  = hook.Parameters
	Constructor = hook.Constructor
	Benchmark   = hook.Benchmark
)
View Source
const (
	OpQuote           = "quote"
	OpQuasiquote      = "quasiquote"
	OpLambda          = "lambda"
	OpExpr            = "expr"
	OpDefun           = "defun"
	OpDefmacro        = "defmacro"
	OpDeftype         = "deftype"
	OpLet             = "let"
	OpLetSeq          = "let*"
	OpFlet            = "flet"
	OpLabels          = "labels"
	OpMacrolet        = "macrolet"
	OpHandlerBind     = "handler-bind"
	OpCond            = "cond"
	OpSetBang         = "set!"
	OpThreadFirst     = "thread-first"
	OpThreadLast      = "thread-last"
	OpUnquote         = "unquote"
	OpUnquoteSplicing = "unquote-splicing"
)

Operator names carried by walker events. These constants let consumers select events without maintaining a separate special-form spelling table.

End balances each Form, including forms whose visitor skips the children.

View Source
const FormalsOccurrence lisp.WalkEvent = End + 1

FormalsOccurrence reports a literal signature before grammar validation.

Variables

View Source
var Forms func(*lisp.CodeWalker, *lisp.LVal) *lisp.LVal

Forms walks runtime syntax with only Form events. Lexical tracking, expansion, and the visitor's ability to skip children are unchanged. Callers that only check calls need not construct events for every leaf.

View Source
var Occurrences func(w *lisp.CodeWalker, budget int, form *lisp.LVal) (complete bool)

Occurrences walks form like the runtime walker but visits every occurrence of shared structure, in its own lexical context, instead of walking a node once per scope. budget bounds the lists walked; the result is false when the walk stopped because it ran out.

View Source
var PackageForms func([]*lisp.LVal) []*lisp.LVal

PackageForms selects top-level forms and nested package declarations for prescan. It omits quoted data and quasiquote, including template holes.

Functions

func Calls added in v1.74.0

func Calls(exprs []*lisp.LVal, visit func(*lisp.LVal), formals func(Node))

Calls visits executable calls without validating binding grammar. It skips quoted data, quasiquote, signatures and binding structure. The formals callback optionally receives signature events by value before grammar validation. A nil formals callback avoids constructing events. Calls allocates no walk state.

func IsOp added in v1.74.0

func IsOp(form *lisp.LVal, op string) bool

IsOp reports whether form's head is the operator op, spelled bare or lisp:-qualified. op must be one of the Op constants, which init checks against CodeWalker's registry; this is the cheap test for hot walks that only ask about one operator.

func Operator added in v1.74.0

func Operator(form *lisp.LVal) string

Operator returns the canonical operator name of form's head, as Syntax reports it, or "" for anything that is not a classified form.

func Syntax added in v1.74.0

func Syntax(node, parent *lisp.LVal, depth int, visit SyntaxVisitor, stop ...*bool)

Syntax visits raw syntax without expansion, lexical tracking, memoization or a depth cap. It uses CodeWalker's operator registry, but leaves traversal policy to its visitor. Tools that intentionally inspect malformed forms or quoted structure can preserve that policy without decoding operator names. A visitor may recursively call Syntax to select particular children. An optional stop flag ends the walk when the visitor sets it to true.

Types

type Binding

type Binding = hook.Binding

Binding describes a custom definition-like form. Children before FormalsIndex are outer-scope code except NameIndex; later children are its body. BindingForm must validate the indices and formals.

type FormalsRole added in v1.74.0

type FormalsRole = hook.FormalsRole

type Node

type Node = hook.Node[lisp.LVal, lisp.WalkEvent]

Node is a source event. Owner contains a definition's form; Formals holds its signature; Init is a let initializer. Outer selects the enclosing scope for a parallel initializer or flet closure. Template marks template symbols. Scope describes lexical scope categories. Role describes a signature's use. The walker reuses this node: copy it to retain an event.

type ScopeCategory added in v1.74.0

type ScopeCategory = hook.ScopeCategory

type SyntaxVisitor added in v1.74.0

type SyntaxVisitor = func(node, parent *lisp.LVal, op string, depth int) bool

SyntaxVisitor receives a raw node, its parent, the canonical operator name of a list's head (including template-hole markers), and its syntax depth. Returning false skips its children. Unlike evaluated-code events, syntax events include quoted data, structural lists, empty lists and every leaf.

type Walker

type Walker struct {
	Visit       func(*Node) bool
	BindingForm func(*lisp.LVal) *Binding
	// Reference, when set, receives references and set! targets instead of
	// Visit. Resolution does not need an event's other fields for these
	// frequent leaves, so this avoids constructing and copying an event.
	Reference func(*lisp.LVal)
	// Form, when set, receives forms, operator names and depths instead of
	// Form events. Its result has the same meaning as Visit's result.
	Form func(*lisp.LVal, string, int) bool
	// Formals receives original signatures, including empty and malformed lists.
	// Owner is the operator form. Binding is its local function entry, if present.
	Formals func(*Node)
	// End, when set, receives completed form depths instead of End events.
	End func(int)
	// EndDepth optionally selects the depth that needs an End callback.
	// The caller updates it as selected forms nest; -1 selects no form.
	EndDepth *int
	// SkipLiterals omits self-evaluating leaves from Visit.
	SkipLiterals bool
	// DeclarationsOnly omits definition signatures, bodies and End events.
	// Prescan uses it for defun, defmacro and deftype declaration metadata.
	DeclarationsOnly bool
	// SyntacticCalls visits calls without rejecting malformed binding grammar.
	// It skips quote and quasiquote, formals lists and binding structure.
	SyntacticCalls bool
	// contains filtered or unexported fields
}

Walker preserves source occurrences and has no nesting cap or implicit macro expansion. The resolver controls expansion through Visit.

func (*Walker) Walk

func (w *Walker) Walk(form *lisp.LVal) *lisp.LVal

Walk visits form without modifying it. A false Visit skips a Form's children.

Directories

Path Synopsis
Package hook breaks the lisp/codewalk import cycle.
Package hook breaks the lisp/codewalk import cycle.

Jump to

Keyboard shortcuts

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