loader

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 9 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 Load

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

Load loads the module at root and everything it imports.

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 Diagnostic

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

Diagnostic is a load error with its position.

func (Diagnostic) String

func (d Diagnostic) String() string

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
}

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
}

Program is a loaded module graph.

Jump to

Keyboard shortcuts

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