resolve

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package resolve annotates a parsed module: every identifier gets a reference, every binding a slot, and every scope its size. It enforces the scope rules the parser leaves to it: no redeclaration in one scope, no declaration shadowing an import or a prelude name, and a function on a type belongs to a type of its own module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PreludeHelp added in v0.3.0

func PreludeHelp(name string) string

PreludeHelp is the help for a declaration that takes the prelude name name.

Types

type Binding

type Binding struct {
	Name string
	Pos  ast.Pos
	Node ast.Node
	// Type is set for a type declared in a block, Import for an import's binding.
	Type, Import bool
}

Binding is a name a scope declares and the node that declares it.

type Error

type Error struct {
	Pos  ast.Pos
	Msg  string
	Code codes.Code
	// Help says how to fix the error, when the message does not.
	Help string
}

Error is a scope error. It is a syntax error in the sense of section 10.

func Resolve

func Resolve(f *ast.File, opts Options) []*Error

Resolve annotates f and returns the scope errors it finds.

func (*Error) Error

func (e *Error) Error() string

type Info

type Info struct {
	// Defs maps each identifier to the node that declares it: a *ast.NameTarget, a *ast.Param,
	// a *ast.FuncDecl, a *ast.TypeDecl, a *ast.Import that binds a namespace, a *ast.ImportName,
	// or the *ast.Lambda whose x it is. A prelude name or an unbound one has no entry.
	Defs map[*ast.Ident]ast.Node
	// Uses maps each declaring node to the identifiers that refer to it, in source order.
	Uses map[ast.Node][]*ast.Ident
	// Scopes maps the node that opens a scope to it: the *ast.File for the module's, a
	// function's or lambda's body *ast.Block for its parameters and locals, a *ast.Block, the
	// body of a for loop for its variable, and the body of a select clause for its binding.
	Scopes map[ast.Node]*Scope
}

Info is what the resolver learned about a module's names: where each identifier is declared and the names each scope holds.

func NewInfo

func NewInfo() *Info

NewInfo returns an empty Info.

type Options

type Options struct {
	// Session allows a top-level name to be declared again, replacing the earlier binding.
	Session bool
	// Fields carries the module fields of earlier inputs in a session, so a later input can
	// refer to them and redeclare them. It is updated in place.
	Fields *ast.ModuleScope
	// Extra names the prelude binds in this program, such as host namespaces.
	Extra []string
	// Info, when set, is filled with what the resolver learned about the module's names, for an
	// editor.
	Info *Info
}

Options adjusts the rules for a session.

type Scope

type Scope struct {
	Parent *Scope
	Names  []Binding
}

Scope is a lexical scope: the names declared in it, in order, and the scope around it.

Jump to

Keyboard shortcuts

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