namespace

package
v0.0.0-...-31ab3be Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package namespace provides namespace management for the system

Index

Constants

View Source
const (
	SymbolNotDeclared = "symbol not declared in namespace: %s"
	SymbolNotBound    = "symbol not bound in namespace: %s"
)

Error messages

View Source
const (
	// RootDomain stores built-ins
	RootDomain = data.Name("ale")

	// AnonymousDomain identifies an anonymous namespace
	AnonymousDomain = data.Name("*anon*")
)
View Source
const (
	NameAlreadyBound = "name is already bound in namespace: %s"
	NameNotBound     = "name is not bound in namespace: %s"
)

Error messages

Variables

This section is empty.

Functions

func MustResolveValue

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

MustResolveValue attempts to resolve a value or explodes violently

func ResolveValue

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

ResolveValue attempts to resolve a symbol to a bound value

func RootSymbol

func RootSymbol(name data.Name) data.Symbol

RootSymbol returns a symbol qualified by the root domain

Types

type Entry

type Entry interface {
	Owner() Type
	Name() data.Name
	Value() data.Value
	IsBound() bool
	Bind(data.Value)
}

Entry represents a namespace entry

func MustResolveSymbol

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

MustResolveSymbol attempts to resolve a symbol or explodes violently

func ResolveSymbol

func ResolveSymbol(ns Type, 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 Manager

type Manager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Manager maintains a mapping of domain names to namespaces

func NewManager

func NewManager() *Manager

NewManager creates a new synchronous namespace map

func (*Manager) Get

func (m *Manager) Get(domain data.Name, res Resolver) Type

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

func (*Manager) GetAnonymous

func (m *Manager) GetAnonymous() Type

GetAnonymous returns an anonymous (non-resolvable) namespace

func (*Manager) GetQualified

func (m *Manager) GetQualified(n data.Name) Type

GetQualified returns the namespace for the specified domain.

func (*Manager) GetRoot

func (m *Manager) GetRoot() Type

GetRoot returns the root namespace, where built-ins go

func (*Manager) New

func (m *Manager) New(n data.Name) Type

New constructs a new namespace

type Resolver

type Resolver func() Type

Resolver resolves a namespace instance

type Type

type Type interface {
	Manager() *Manager
	Domain() data.Name
	Declare(data.Name) Entry
	Resolve(data.Name) (Entry, bool)
}

Type represents a namespace

Jump to

Keyboard shortcuts

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