loader

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: 10 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 loader reads a program's modules, parses and resolves them, and orders them for initialization (section 10).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Beside added in v0.3.3

func Beside(root string, cfg Config) []string

Beside lists the host's declaration files of the program rooted at root: the files beside it whose names end in .d.ant, but for prelude.d.ant, by the paths that read them, in the order of their names (section 10, Declaration files). A root that is a declaration file, or an input of a session, has none.

func Load

func Load(root string, cfg Config) (*Program, []Diagnostic)

Load loads the module at root and everything it imports.

func LoadRoots added in v0.3.0

func LoadRoots(roots []string, cfg Config) (*Program, []Diagnostic)

LoadRoots loads the modules at roots and everything they import as one graph, in which each module is loaded once however many roots reach it, so that the programs can be checked together. It returns every diagnostic of the load, and the program of the roots whose own graphs loaded without one: a root that does not load is left out, with every module that only it reaches. Under cfg.Recover it keeps every module that parsed, with what recovery kept of it, so that the program can be checked past its errors. The program has no Root. A root must not be a declaration file.

Types

type Config

type Config struct {
	// FS supplies sources by slash-separated path; nil means the operating system.
	FS fs.FS
	// Sources overrides the text of modules by path.
	Sources map[string]string
	// Mode is the parser mode for the root module, unless its path names a declaration file
	// (parser.ModeOf); imports always parse as programs.
	Mode parser.Mode
	// Extra names the prelude binds in this program, beyond the standard ones.
	Extra []string
	// Session, when set, makes the root an input of a session: its fields accumulate in this
	// scope and may be declared again.
	Session *ast.ModuleScope
	// Imports, for a session, are the imports of earlier inputs still in force: the root takes
	// them before its own, without their text, so its positions stay those of its source.
	Imports []*ast.Import
	// Recover makes Load go on past errors, for an editor: a module with syntax errors is
	// parsed as far as it goes (parser.ParseRecover), a module that cannot be read or is in a
	// cycle leaves its import's Module at -1, and the program comes back with the diagnostics
	// instead of nil. Such a program is for analysis only and must not be run. Mode is Program.
	Recover bool
}

Config says where sources come from.

type Declared added in v0.3.3

type Declared struct {
	Path string // as messages show it
	File *ast.File
	Src  string
	// Layout is kept when loading with Recover, as a module's is.
	Layout *parser.Layout
	// Names are the prelude names the file binds: the owners of its declarations and its
	// unqualified names.
	Names []string
	// Err is the file's syntax error when the load does not recover: the file then declares
	// nothing, and the program loads without it, since only the checker reads the file. Under
	// Recover the error is among the load's diagnostics, as a module's is.
	Err *Diagnostic
}

Declared is a host's declaration file, parsed.

type Diagnostic

type Diagnostic struct {
	Path string
	Pos  ast.Pos
	// End is where the expression the diagnostic is about ends, when it names one: Pos is then
	// its start. Else it is zero, and the span is found from Pos (diag.Span).
	End ast.Pos
	Msg string
	// Code names the rule the diagnostic reports (spec/check.md section 3).
	Code codes.Code
	// Warning marks a warning, which reports code the checker accepts (spec/check.md section 4).
	Warning bool
	// Help says how to fix it, when the message does not; Fixes are edits that would, and
	// Related are other places that explain it.
	Help    string
	Fixes   []Fix
	Related []Related
}

Diagnostic is a load error with its position.

func Settle added in v0.3.0

func Settle(diags []Diagnostic) []Diagnostic

Settle drops the diagnostics that only follow from a syntax error that recovery read past, as ant check and the language server report them: on a line with a syntax error, every other diagnostic, since the line was not read as written. It drops the warnings of a file that has an error too: a warning is about code the checker accepts (spec/check.md section 4).

func (Diagnostic) String

func (d Diagnostic) String() string

type Edit added in v0.3.0

type Edit struct {
	Path       string
	Start, End ast.Pos
	Text       string
}

Edit replaces the text of the module at Path from Start up to End with Text; Start == End inserts.

type Fix added in v0.3.0

type Fix struct {
	Title string
	Auto  bool
	Edits []Edit
}

Fix is a set of edits that removes a diagnostic. Auto marks one that is safe to apply unread: the only fix offered, and, for an error, the one edit that could be meant.

type Module

type Module struct {
	Path  string // canonical, the module's identity
	File  *ast.File
	Index int
	// Src, Layout, and Resolve are the module's source, layout, and the resolver's findings,
	// kept when loading with Recover.
	Src     string
	Layout  *parser.Layout
	Resolve *resolve.Info
	// Recovered is set when recovery read past a syntax error of the module, so that what the
	// parser dropped, declarations among it, is missing from File.
	Recovered bool
}

Module is one loaded module.

type Program

type Program struct {
	// Modules in initialization order: every module after the modules it imports, the root last.
	Modules []*Module
	Root    *Module
	// Declared is the host's declaration files of the program: those beside its root (section
	// 10, Declaration files), in the order of their names.
	Declared []*Declared
}

Program is a loaded module graph.

func (*Program) Unprovided added in v0.3.3

func (p *Program) Unprovided(provided func(name string) bool) *Diagnostic

Unprovided reports why the program cannot run in a host: the first read, in initialization order, of a name that a host's declaration file declares and the host does not provide, as provided tells. A declaration file declares and does not implement (section 10, Declaration files). It is nil for a program that reads no such name.

type Related struct {
	Path string
	Pos  ast.Pos
	Msg  string
}

Related is another place that explains a diagnostic, such as the test a field path did not narrow by.

Jump to

Keyboard shortcuts

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