scope

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewScope

func NewScope(parent *Scope, names ...string) (scope *Scope, ids []Ident)

NewScope creates a Scope derived from parent (or root if parent == nil) with the given names. New Idents corresponding to the names are returned, as well. Invariant: for i, name in names: scope.Lookup(name) == ids[i] && parent.Lookup(name) != ids[i]

func ValidIdent

func ValidIdent(s string) bool

func ValidIdentPrefix

func ValidIdentPrefix(s string) int

ValidIdentPrefix returns length (in bytes) of the longest prefix of s that is a valid identifier.

Types

type Bindings

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

Bindings is a set of runtime bindings of Idents. Bindings are always read-only.

func NewBindings

func NewBindings(parent *Bindings, binds map[Ident]record.Record) *Bindings

NewBindings creates a Bindings derived from parent (or root if parent == nil) with the given value binds. The caller must not mutate the binds map after calling NewBindings.

func (*Bindings) AllIdents

func (binds *Bindings) AllIdents() (out []Ident)

func (*Bindings) AllValues

func (binds *Bindings) AllValues() map[string]record.Record

func (*Bindings) Get

func (binds *Bindings) Get(id Ident) (val record.Record, bound bool)

Get returns the value associated with id, if bound.

func (*Bindings) Scoped

func (binds *Bindings) Scoped(scp *Scope) ScopedBindings

func (*Bindings) String

func (binds *Bindings) String() string

type Func

type Func func(args ...record.Record) (record.Record, error)

type FuncTable

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

func NewFuncTable

func NewFuncTable(parent *FuncTable, funcs map[string]Func) *FuncTable

func (*FuncTable) Get

func (ft *FuncTable) Get(name string) Func

type Ident

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

Ident is a unique identifier in a particular Scope, to be bound to a (real-only) value at runtime in a Bindings of that Scope.

func (Ident) String

func (id Ident) String() string

func (Ident) Valid

func (id Ident) Valid() bool

type Scope

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

Scope is lexical scope, a collection of in-scope Idents at some location in a program source. It may have a parent, inheriting Idents. A Scope is "instantiated" at runtime with Bind by binding values to its Idents.

Scope is always read-only.

func (*Scope) Lookup

func (s *Scope) Lookup(name string) Ident

Lookup returns the Ident that name references relative to the current Scope, or nil if no such Ident. An Ident in an ancestor Scope is shadowed by an Ident of the same name in a child Scope.

func (*Scope) Parent

func (s *Scope) Parent() *Scope

Parent returns this Scope's parent, or nil if this is a root Scope.

type ScopedBindings

type ScopedBindings struct {
	Scope *Scope
	Binds *Bindings
}

ScopedBindings combines a Scope and Bindings to give the visible symbols and their bound values at a particular point in a program.

func (ScopedBindings) Lookup

func (sb ScopedBindings) Lookup(name string) (record.Record, bool)

Jump to

Keyboard shortcuts

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