resolver

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package resolver provides file resolution infrastructure for the Scheme compiler. It owns the concrete FileResolver implementations that locate and open source files on the OS filesystem, embedded filesystems, and virtual fs.FS instances.

The resolver package deals in file paths, not library names. Library identity and semantics are handled by the compilation package.

FileResolver is defined in environment.FileResolver and is not redeclared here. The FileEnumerator interface extends resolvers with file discovery capability.

Index

Constants

View Source
const SchemeIncludePathEnv = "SCHEME_INCLUDE_PATH"

SchemeIncludePathEnv is the environment variable name for the Scheme include path.

Variables

This section is empty.

Functions

func LibraryExtensions

func LibraryExtensions() []string

LibraryExtensions returns a copy of the recognized Scheme library file extensions.

func WalkOSSchemeFiles

func WalkOSSchemeFiles(baseDir string, auth security.Authorizer, fn func(relPath string)) error

WalkOSSchemeFiles walks baseDir on the OS filesystem, calling fn with the slash-separated path of each .sld/.scm file relative to baseDir. Hidden directories and unauthorized files are silently skipped. Returns the WalkDir error so callers can observe unexpected walk failures.

Types

type ChainFileResolver

type ChainFileResolver struct {
	// contains filtered or unexported fields
}

ChainFileResolver tries multiple resolvers in order, falling through to the next on ErrFileNotFound. Non-file-not-found errors (security denials, I/O errors) propagate immediately.

func NewChainFileResolver

func NewChainFileResolver(resolvers []environment.FileResolver) *ChainFileResolver

NewChainFileResolver creates a resolver that tries each resolver in order. Panics if resolvers is empty.

func (*ChainFileResolver) EnumerateFiles

func (p *ChainFileResolver) EnumerateFiles() ([]string, error)

EnumerateFiles unions file enumerations from all child resolvers that implement FileEnumerator. Results are concatenated in resolver order with no deduplication; ordering implies priority. Best-effort: walk errors are accumulated and returned alongside partial results, matching OSFileResolver and FSFileResolver semantics.

func (*ChainFileResolver) ResolveAndOpen

func (p *ChainFileResolver) ResolveAndOpen(ctx context.Context, path string) (fs.File, string, error)

ResolveAndOpen tries each resolver in order, returning the first successful result. Falls through on ErrFileNotFound; other errors propagate immediately.

type EmbedFileResolver

type EmbedFileResolver struct {
	// contains filtered or unexported fields
}

EmbedFileResolver resolves files from an embedded filesystem (or any fs.FS). No path resolution or security checks — paths are looked up directly.

EmbedFileResolver does NOT implement FileEnumerator because embedded filesystems typically contain a known, fixed set of files that do not need runtime discovery.

func NewEmbedFileResolver

func NewEmbedFileResolver(fsys fs.FS) *EmbedFileResolver

NewEmbedFileResolver creates a resolver backed by the given filesystem. Panics if fsys is nil.

func (*EmbedFileResolver) ResolveAndOpen

func (p *EmbedFileResolver) ResolveAndOpen(_ context.Context, path string) (fs.File, string, error)

ResolveAndOpen finds a file by name and returns an open handle plus the resolved path.

type FSFileResolver

type FSFileResolver struct {
	// contains filtered or unexported fields
}

FSFileResolver resolves files from a virtual filesystem (fs.FS). Used when an embedder provides WithSourceFS. All paths are relative to the FS root. Absolute paths are rejected.

Resolution priority:

  1. Relative to current load directory (from LoadPathStack)
  2. Library registry search paths
  3. Relative to FS root (path as-is)

func NewFSFileResolver

func NewFSFileResolver(fsys fs.FS, env *environment.EnvironmentFrame) *FSFileResolver

NewFSFileResolver creates a resolver backed by the given filesystem. Panics if fsys is nil.

func (*FSFileResolver) EnumerateFiles

func (p *FSFileResolver) EnumerateFiles() ([]string, error)

EnumerateFiles walks the virtual filesystem to discover all .sld/.scm files. When registry search paths are configured, only those directories are walked. When no registry paths exist, the FS root "." is walked as a fallback. Hidden directories (starting with ".") are skipped.

Best-effort: non-existent directories and unauthorized files are skipped. Walk errors are joined and returned alongside partial results.

func (*FSFileResolver) ResolveAndOpen

func (p *FSFileResolver) ResolveAndOpen(_ context.Context, path string) (fs.File, string, error)

ResolveAndOpen finds a file by name and returns an open handle plus the resolved path.

type FileEnumerator

type FileEnumerator interface {
	EnumerateFiles() ([]string, error)
}

FileEnumerator is an optional interface that FileResolvers can implement to support file discovery. EnumerateFiles returns slash-separated relative paths to .sld/.scm files found by the resolver.

Results are returned in discovery order with no deduplication; callers are responsible for library-level dedup and interpretation of paths.

type OSFileResolver

type OSFileResolver struct {
	// contains filtered or unexported fields
}

OSFileResolver resolves files from the operating system filesystem, using the load path stack, library registry, SCHEME_INCLUDE_PATH, and CWD as fallback directories. It also enforces security authorization.

func NewOSFileResolver

func NewOSFileResolver(env *environment.EnvironmentFrame) *OSFileResolver

NewOSFileResolver creates a resolver that finds files on the OS filesystem.

func (*OSFileResolver) EnumerateFiles

func (p *OSFileResolver) EnumerateFiles() ([]string, error)

EnumerateFiles walks the OS filesystem to discover .sld/.scm files. Searches the same directories as ResolveAndOpen: library registry paths, SCHEME_INCLUDE_PATH, and CWD.

Best-effort: non-existent directories and unauthorized files are skipped. Walk errors are joined and returned alongside partial results.

func (*OSFileResolver) ResolveAndOpen

func (p *OSFileResolver) ResolveAndOpen(_ context.Context, path string) (fs.File, string, error)

ResolveAndOpen finds a file by name and returns an open handle plus the resolved path.

Absolute paths bypass the Finder — fs.FS does not support them — and are opened directly via openAuthorized. Relative paths are searched through a sourceload.Finder backed by os.DirFS("/"), which searches the current load directory (from the load path stack), library registry paths, SCHEME_INCLUDE_PATH, and CWD in that order.

Jump to

Keyboard shortcuts

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