env

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package env provides namespace management for the system

Index

Constants

View Source
const (
	// ErrNameAlreadyBound is raised when an attempt is made to bind a
	// Namespace entry that has already been bound
	ErrNameAlreadyBound = "name is already bound in namespace: %s"

	// ErrNameNotBound is raised when an attempt is mode to retrieve a value
	// from a Namespace that hasn't been bound
	ErrNameNotBound = "name is not bound in namespace: %s"

	// ErrSnapshotIncomplete is raised when an attempt is made to create a
	// Namespace snapshot in a situation where an unbound entry has been
	// retrieved
	ErrSnapshotIncomplete = "can't snapshot environment. entry not bound: %s"
)
View Source
const (
	// ErrSymbolNotDeclared is raised when an attempt to forcefully resolve an
	// undeclared symbol in the Namespace fails
	ErrSymbolNotDeclared = "symbol not declared in namespace: %s"

	// ErrSymbolNotBound is raised when an attempt to forcefully resolve an
	// unbound symbol in the Namespace fails
	ErrSymbolNotBound = "symbol not bound in namespace: %s"
)
View Source
const (
	// RootDomain stores built-ins
	RootDomain = data.Local("ale")

	// AnonymousDomain identifies an anonymous namespace
	AnonymousDomain = data.Local("*anon*")
)

Variables

This section is empty.

Functions

func MustResolveValue

func MustResolveValue(ns Namespace, s data.Symbol) data.Value

MustResolveValue attempts to resolve a value or explodes violently

func ResolveValue

func ResolveValue(ns Namespace, s data.Symbol) (data.Value, bool)

ResolveValue attempts to resolve a symbol to a bound value

func RootSymbol

func RootSymbol(name data.Local) data.Symbol

RootSymbol returns a symbol qualified by the root domain

Types

type Entry

type Entry interface {
	Owner() Namespace
	Name() data.Local
	Value() data.Value
	Bind(data.Value)
	IsBound() bool
	IsPrivate() bool
}

Entry represents a namespace entry

func MustResolveSymbol

func MustResolveSymbol(ns Namespace, s data.Symbol) Entry

MustResolveSymbol attempts to resolve a symbol or explodes violently

func ResolveSymbol

func ResolveSymbol(ns Namespace, s data.Symbol) (Entry, bool)

ResolveSymbol attempts to resolve a symbol. If it's a qualified symbol, it will be retrieved directly from the identified namespace. Otherwise, it will be searched in the current namespace

type Environment

type Environment struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Environment maintains a mapping of domain names to namespaces

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment creates a new synchronous namespace map

func (*Environment) Domains

func (e *Environment) Domains() data.Locals

func (*Environment) Get

func (e *Environment) Get(domain data.Local, res Resolver) Namespace

Get returns a mapped namespace or instantiates a new one to be cached

func (*Environment) GetAnonymous

func (e *Environment) GetAnonymous() Namespace

GetAnonymous returns an anonymous (non-resolvable) namespace

func (*Environment) GetQualified

func (e *Environment) GetQualified(n data.Local) Namespace

GetQualified returns the namespace for the specified domain.

func (*Environment) GetRoot

func (e *Environment) GetRoot() Namespace

GetRoot returns the root namespace, where built-ins go

func (*Environment) New

func (e *Environment) New(n data.Local) Namespace

New constructs a new namespace

func (*Environment) Snapshot

func (e *Environment) Snapshot() (*Environment, error)

type Namespace

type Namespace interface {
	Environment() *Environment
	Domain() data.Local
	Declared() data.Locals
	Declare(data.Local) Entry
	Private(data.Local) Entry
	Resolve(data.Local) (Entry, bool)
	Snapshot(*Environment) (Namespace, error)
}

Namespace represents a namespace

type Resolver

type Resolver func() Namespace

Resolver resolves a namespace instance

Jump to

Keyboard shortcuts

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