eval

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2017 License: BSD-2-Clause Imports: 36 Imported by: 0

Documentation

Overview

Package eval handles evaluation of nodes and consists the runtime of the shell.

Index

Constants

View Source
const FnPrefix = "&"

FnPrefix is the prefix for the variable names of functions. Defining a function "foo" is equivalent to setting a variable named FnPrefix + "foo".

View Source
const (
	NoPretty = util.MinInt
)

Variables

View Source
var (
	ErrArgs              = errors.New("args error")
	ErrInput             = errors.New("input error")
	ErrStoreNotConnected = errors.New("store not connected")
	ErrNoMatchingDir     = errors.New("no matching directory")
	ErrNotInSameGroup    = errors.New("not in the same process group")
)

Errors thrown by builtins.

View Source
var (
	ErrBadGlobPattern          = errors.New("bad GlobPattern; elvish bug")
	ErrCannotDetermineUsername = errors.New("cannot determine user name from glob pattern")
)

Errors thrown when globbing.

View Source
var (
	ErrCanOnlyAssignList          = errors.New("can only assign compatible values")
	ErrPathMustBeString           = errors.New("path must be string")
	ErrPathCannotContainColonZero = errors.New(`path cannot contain colon or \0`)
)

Errors

View Source
var (
	ErrExternalCmdOpts = errors.New("external commands don't accept elvish options")
	ErrCdNoArg         = errors.New("implicit cd accepts no arguments")
)
View Source
var (
	ErrMustFollowWildcard   = errors.New("must follow wildcard")
	ErrModifierMustBeString = errors.New("modifier must be string")
	ErrWildcardNoMatch      = errors.New("wildcard has no match")
)
View Source
var (
	// ErrNeedIntIndex    = errors.New("need integer index")
	ErrBadIndex        = errors.New("bad index")
	ErrIndexOutOfRange = errors.New("index out of range")
	ErrAssocWithSlice  = errors.New("assoc with slice not yet supported")
)

Error definitions.

View Source
var (
	// ClosedChan is a closed channel, suitable for use as placeholder channel input.
	ClosedChan = make(chan Value)
	// BlackholeChan is channel writes onto which disappear, suitable for use as
	// placeholder channel output.
	BlackholeChan = make(chan Value)
	// DevNull is /dev/null.
	DevNull *os.File
	// DevNullClosedInput is a port made up from DevNull and ClosedChan,
	// suitable as placeholder input port.
	DevNullClosedChan *Port
)
View Source
var (
	ErrNoArgAccepted = errors.New("no argument accepted")
	ErrNoOptAccepted = errors.New("no option accepted")
)
View Source
var (
	NoArgs = []Value{}
	NoOpts = map[string]Value{}
)
View Source
var ErrArityMismatch = errors.New("arity mismatch")

ErrArityMismatch is thrown by a closure when the number of arguments the user supplies does not match with what is required.

View Source
var ErrBadBase = errors.New("bad base")

ErrBadBase is thrown by the "base" builtin if the base is smaller than 2 or greater than 36.

View Source
var ErrDaemonOffline = errors.New("daemon is offline")
View Source
var ErrGetBlackhole = errors.New("cannot get blackhole variable")

ErrGetBlackhole is raised when attempting to get the value of a blackhole variable.

View Source
var (
	ErrIndexMustBeString = errors.New("index must be string")
)
View Source
var ErrInterrupted = errors.New("interrupted")
View Source
var ErrMoreThanOneRest = errors.New("more than one @ lvalue")
View Source
var ErrNoDataDir = errors.New("There is no data directory")

ErrNoDataDir is thrown by the "use" special form when there is no data directory.

View Source
var ErrOnlyStrOrRat = errors.New("only str or rat may be converted to rat")
View Source
var ErrReplacementMustBeString = errors.New("replacement must be string")
View Source
var (
	ErrRoCannotBeSet = errors.New("read-only variable; cannot be set")
)
View Source
var ErrStoreUnconnected = errors.New("store unconnected")

ErrStoreUnconnected is thrown by ResolveVar when a shared: variable needs to be resolved but the store is not connected.

View Source
var IsBuiltinSpecial = map[string]bool{}

IsBuiltinSpecial is the set of all names of builtin special forms. It is intended for external consumption, e.g. the syntax highlighter.

View Source
var OK = &Exception{}

OK is a pointer to the zero value of Exception, representing the absence of exception.

Functions

func AddBuiltinFns added in v0.9.0

func AddBuiltinFns(ns Namespace, fns ...*BuiltinFn)

AddBuiltinFns adds builtin functions to a namespace.

func Chdir added in v0.9.0

func Chdir(path string, daemon *api.Client) error

Chdir changes the current directory. On success it also updates the PWD environment variable and records the new directory in the directory history. It returns nil as long as the directory changing part succeeds.

func ClosePorts

func ClosePorts(ports []*Port)

ClosePorts closes a list of Ports.

func ComposeExceptionsFromPipeline added in v0.6.0

func ComposeExceptionsFromPipeline(excs []*Exception) error

ComposeExceptionsFromPipeline takes a slice of Exception pointers and composes a suitable error. If all elements of the slice are either nil or OK, a nil is returned. If there is exactly non-nil non-OK Exception, it is returned. Otherwise, a PipelineError built from the slice is returned, with nil items turned into OK's for easier access from elvishscript.

func MakeVariableName

func MakeVariableName(explode bool, ns string, name string) string

func NewExternalCmdExit

func NewExternalCmdExit(name string, ws syscall.WaitStatus, pid int) error

func ParseAndFixListIndex added in v0.3.0

func ParseAndFixListIndex(s string, n int) (bool, int, int)

ParseAndFixListIndex parses a list index and returns whether the index is a slice and "real" (-1 becomes n-1) indicies. It throws errors when the index is invalid or out of range.

func ParseAndFixVariable added in v0.4.0

func ParseAndFixVariable(qname string) (explode bool, ns string, name string)

ParseAndFixVariable parses a variable name. It "fixes" $@ to $@args.

func ParseVariable

func ParseVariable(text string) (explode bool, ns string, name string)

func ParseVariableQName added in v0.5.0

func ParseVariableQName(qname string) (ns, name string)

func ParseVariableSplice added in v0.5.0

func ParseVariableSplice(text string) (explode, qname string)

func ScanArgs added in v0.8.0

func ScanArgs(s []Value, args ...interface{})

ScanArgs scans arguments into pointers to supported argument types. If the arguments cannot be scanned, an error is thrown.

func ScanArgsAndOptionalIterate added in v0.8.0

func ScanArgsAndOptionalIterate(ec *EvalCtx, s []Value, args ...interface{}) func(func(Value))

ScanArgsAndOptionalIterate is like ScanArgs, but the argument can contain an optional iterable value at the end. The return value is a function that iterates the iterable value if it exists, or the input otherwise.

func ScanArgsVariadic added in v0.8.0

func ScanArgsVariadic(s []Value, args ...interface{})

ScanArgsVariadic is like ScanArgs, but the last element of args should be a pointer to a slice, and the rest of arguments will be scanned into it.

func ScanOpts added in v0.8.0

func ScanOpts(m map[string]Value, opts ...Opt)

ScanOpts scans options from a map.

func ScanOptsToStruct added in v0.10.0

func ScanOptsToStruct(m map[string]Value, structPtr interface{})

ScanOptsToStruct scan options from a map like ScanOpts except the destination is a struct whose fields correspond to the options to be parsed. A field named FieldName corresponds to the option named field-name, unless the field has a explicit "name" tag.

func ShouldBeBool added in v0.6.0

func ShouldBeBool(v Value) error

func ShouldBeFn added in v0.6.0

func ShouldBeFn(v Value) error

func ShouldBeList added in v0.6.0

func ShouldBeList(v Value) error

func ShouldBeMap added in v0.6.0

func ShouldBeMap(v Value) error

func TakeNoArg added in v0.4.0

func TakeNoArg(args []Value)

func TakeNoOpt added in v0.4.0

func TakeNoOpt(opts map[string]Value)

func ToBool

func ToBool(v Value) bool

ToBool converts a Value to bool. When the Value type implements Bool(), it is used. Otherwise it is considered true.

func ToString

func ToString(v Value) string

ToString converts a Value to String. When the Value type implements String(), it is used. Otherwise Repr(NoPretty) is used.

Types

type Assocer added in v0.10.0

type Assocer interface {
	Assoc(k, v Value) Value
}

Assocer is anything tha can return a slightly modified version of itself as a new Value.

type BlackholeVariable added in v0.10.0

type BlackholeVariable struct{}

BlackholeVariable represents a blackhole variable. Assignments to a blackhole variable will be discarded, and getting a blackhole variable raises an error.

func (BlackholeVariable) Get added in v0.10.0

func (bv BlackholeVariable) Get() Value

func (BlackholeVariable) Set added in v0.10.0

func (bv BlackholeVariable) Set(Value)

type Bool

type Bool bool

Bool represents truthness.

func (Bool) Bool

func (b Bool) Bool() bool

func (Bool) Equal added in v0.10.0

func (b Bool) Equal(rhs interface{}) bool

func (Bool) Hash added in v0.10.0

func (b Bool) Hash() uint32

func (Bool) Kind

func (Bool) Kind() string

func (Bool) Repr

func (b Bool) Repr(int) string

type Booler

type Booler interface {
	Bool() bool
}

Booler is anything that can be converted to a bool.

type BuiltinFn

type BuiltinFn struct {
	Name string
	Impl BuiltinFnImpl
}

BuiltinFn is a builtin function.

func (*BuiltinFn) Call

func (b *BuiltinFn) Call(ec *EvalCtx, args []Value, opts map[string]Value)

Call calls a builtin function.

func (*BuiltinFn) Equal added in v0.10.0

func (b *BuiltinFn) Equal(rhs interface{}) bool

Equal compares based on identity.

func (*BuiltinFn) Hash added in v0.10.0

func (b *BuiltinFn) Hash() uint32

func (*BuiltinFn) Kind

func (*BuiltinFn) Kind() string

Kind returns "fn".

func (*BuiltinFn) Repr

func (b *BuiltinFn) Repr(int) string

Repr returns an opaque representation "<builtin xxx>".

type BuiltinFnImpl added in v0.10.0

type BuiltinFnImpl func(*EvalCtx, []Value, map[string]Value)

func WrapStringToString added in v0.9.0

func WrapStringToString(f func(string) string) BuiltinFnImpl

func WrapStringToStringError added in v0.9.0

func WrapStringToStringError(f func(string) (string, error)) BuiltinFnImpl

type Callable added in v0.7.0

type Callable interface {
	Call(ec *EvalCtx, args []Value, opts map[string]Value)
}

Callable is anything may be called on an evalCtx with a list of Value's.

type CallableValue added in v0.7.0

type CallableValue interface {
	Value
	Callable
}

type Closure

type Closure struct {
	ArgNames []string
	// The name for the rest argument. If empty, the function has fixed arity.
	RestArg     string
	OptNames    []string
	OptDefaults []Value
	Op          Op
	Captured    map[string]Variable
	SourceName  string
	Source      string
}

Closure is a closure defined in elvish script.

func (*Closure) Call

func (c *Closure) Call(ec *EvalCtx, args []Value, opts map[string]Value)

Call calls a closure.

func (*Closure) Equal added in v0.10.0

func (c *Closure) Equal(rhs interface{}) bool

Equal compares by identity.

func (*Closure) Hash added in v0.10.0

func (c *Closure) Hash() uint32

func (*Closure) Kind

func (*Closure) Kind() string

Kind returns "fn".

func (*Closure) Repr

func (c *Closure) Repr(int) string

Repr returns an opaque representation "<closure 0x23333333>".

type CompilationError added in v0.6.0

type CompilationError struct {
	Message string
	Context util.SourceContext
}

CompilationError represents a compilation error and can pretty print it.

func (*CompilationError) Error added in v0.6.0

func (ce *CompilationError) Error() string

func (*CompilationError) Pprint added in v0.6.0

func (ce *CompilationError) Pprint(indent string) string

Pprint pretty-prints a compilation error.

type Dissocer added in v0.10.0

type Dissocer interface {
	Dissoc(k Value) Value
}

Assocer is anything tha can return a slightly modified version of itself with the specified key removed, as a new value.

type Editor added in v0.4.0

type Editor interface {
	Active() bool
	ActiveMutex() *sync.Mutex
	Notify(string, ...interface{})
}

Editor is the interface that the line editor has to satisfy. It is needed so that this package does not depend on the edit package.

type EnvList added in v0.10.0

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

EnvList is a variable whose value is constructed from an environment variable by splitting at colons. Changes to it are also propagated to the corresponding environment variable. Its elements cannot contain colons or \0; attempting to put colon or \0 in its elements will result in an error.

func (*EnvList) Get added in v0.10.0

func (envli *EnvList) Get() Value

Get returns a Value for an EnvPathList.

func (*EnvList) Set added in v0.10.0

func (envli *EnvList) Set(v Value)

Set sets an EnvPathList. The underlying environment variable is set.

type Equaler added in v0.10.0

type Equaler interface {
	Equal(interface{}) bool
}

Equaler is anything that knows how to compare itself against other values.

type EvalCtx

type EvalCtx struct {
	*Evaler
	// contains filtered or unexported fields
}

EvalCtx maintains an Evaler along with its runtime context. After creation an EvalCtx is seldom modified, and new instances are created when needed.

func NewTopEvalCtx

func NewTopEvalCtx(ev *Evaler, name, text string, ports []*Port) *EvalCtx

NewTopEvalCtx creates a top-level evalCtx.

func (*EvalCtx) CheckInterrupts added in v0.10.0

func (ec *EvalCtx) CheckInterrupts()

CheckInterrupts checks whether there has been an interrupt, and throws ErrInterrupted if that is the case

func (*EvalCtx) ExecAndUnwrap added in v0.10.0

func (ctx *EvalCtx) ExecAndUnwrap(desc string, op ValuesOp) ValuesUnwrapper

ExecAndUnwrap executes a ValuesOp and creates an Unwrapper for the obtained values.

func (*EvalCtx) InputChan added in v0.10.0

func (ec *EvalCtx) InputChan() chan Value

InputChan returns a channel from which input can be read.

func (*EvalCtx) InputFile added in v0.10.0

func (ec *EvalCtx) InputFile() *os.File

InputFile returns a file from which input can be read.

func (*EvalCtx) Interrupts added in v0.5.0

func (ec *EvalCtx) Interrupts() <-chan struct{}

Interrupts returns a channel that is closed when an interrupt signal comes.

func (*EvalCtx) IterateInputs

func (ec *EvalCtx) IterateInputs(f func(Value))

IterateInputs calls the passed function for each input element.

func (*EvalCtx) OutputChan

func (ec *EvalCtx) OutputChan() chan<- Value

OutputChan returns a channel onto which output can be written.

func (*EvalCtx) OutputFile added in v0.9.0

func (ec *EvalCtx) OutputFile() *os.File

OutputFile returns a file onto which output can be written.

func (*EvalCtx) PCall

func (ec *EvalCtx) PCall(f Callable, args []Value, opts map[string]Value) (err error)

func (*EvalCtx) PCaptureOutput

func (ec *EvalCtx) PCaptureOutput(f Callable, args []Value, opts map[string]Value) (vs []Value, err error)

func (*EvalCtx) PCaptureOutputInner added in v0.10.0

func (ec *EvalCtx) PCaptureOutputInner(f Callable, args []Value, opts map[string]Value, valuesCb func(<-chan Value), bytesCb func(*os.File)) error

func (*EvalCtx) PEval

func (ec *EvalCtx) PEval(op Op) (err error)

PEval evaluates an op in a protected environment so that calls to errorf are wrapped in an Error.

func (*EvalCtx) ResolveVar

func (ec *EvalCtx) ResolveVar(ns, name string) Variable

ResolveVar resolves a variable. When the variable cannot be found, nil is returned.

func (*EvalCtx) Unwrap added in v0.10.0

func (ctx *EvalCtx) Unwrap(desc string, begin, end int, vs []Value) ValuesUnwrapper

Unwrap creates an Unwrapper.

type Evaler

type Evaler struct {
	Global  Namespace
	Modules map[string]Namespace
	Daemon  *api.Client
	ToSpawn *daemon.Daemon
	Editor  Editor
	DataDir string
	// contains filtered or unexported fields
}

Evaler is used to evaluate elvish sources. It maintains runtime context shared among all evalCtx instances.

func NewEvaler

func NewEvaler(daemon *api.Client, toSpawn *daemon.Daemon,
	dataDir string, extraModules map[string]Namespace) *Evaler

NewEvaler creates a new Evaler.

func (*Evaler) Builtin added in v0.9.0

func (ev *Evaler) Builtin() Namespace

func (*Evaler) Compile

func (ev *Evaler) Compile(n *parse.Chunk, name, text string) (Op, error)

Compile compiles elvish code in the global scope. If the error is not nil, it always has type CompilationError.

func (*Evaler) EachExternal added in v0.6.0

func (ev *Evaler) EachExternal(f func(string))

EachExternal calls f for each name that can resolve to an external command.

func (*Evaler) Eval

func (ev *Evaler) Eval(op Op, name, text string) error

Eval sets up the Evaler with standard ports and evaluates an Op. The supplied name and text are used in diagnostic messages.

func (*Evaler) EvalWithPorts added in v0.9.0

func (ev *Evaler) EvalWithPorts(ports []*Port, op Op, name, text string) error

EvalWithPorts sets up the Evaler with the given ports and evaluates an Op. The supplied name and text are used in diagnostic messages.

func (*Evaler) Search

func (ev *Evaler) Search(exe string) (string, error)

Search tries to resolve an external command and return the full (possibly relative) path.

func (*Evaler) Source

func (ev *Evaler) Source(fname string) error

Source evaluates the content of a file.

func (*Evaler) SourceText

func (ev *Evaler) SourceText(name, src string) error

SourceText evaluates a chunk of elvish source.

type Exception added in v0.6.0

type Exception struct {
	Cause     error
	Traceback *util.SourceContext
}

Exception represents an elvish exception. It is both a Value accessible to elvishscript, and the type of error returned by public facing evaluation methods like (*Evaler)PEval.

func (*Exception) Bool added in v0.6.0

func (exc *Exception) Bool() bool

func (*Exception) Equal added in v0.10.0

func (exc *Exception) Equal(rhs interface{}) bool

Equal compares by identity.

func (*Exception) Error added in v0.6.0

func (exc *Exception) Error() string

func (*Exception) Hash added in v0.10.0

func (exc *Exception) Hash() uint32

func (*Exception) Kind added in v0.6.0

func (exc *Exception) Kind() string

func (*Exception) Pprint added in v0.6.0

func (exc *Exception) Pprint(indent string) string

func (*Exception) Repr added in v0.6.0

func (exc *Exception) Repr(indent int) string

type ExternalCmd

type ExternalCmd struct {
	Name string
}

ExternalCmd is an external command.

func (ExternalCmd) Call

func (e ExternalCmd) Call(ec *EvalCtx, argVals []Value, opts map[string]Value)

Call calls an external command.

func (ExternalCmd) Equal added in v0.10.0

func (e ExternalCmd) Equal(a interface{}) bool

func (ExternalCmd) Hash added in v0.10.0

func (e ExternalCmd) Hash() uint32

func (ExternalCmd) Kind

func (ExternalCmd) Kind() string

func (ExternalCmd) Repr

func (e ExternalCmd) Repr(int) string

type ExternalCmdExit

type ExternalCmdExit struct {
	syscall.WaitStatus
	CmdName string
	Pid     int
}

ExternalCmdExit contains the exit status of external commands. If the command was stopped rather than terminated, the Pid field contains the pid of the process.

func FakeExternalCmdExit

func FakeExternalCmdExit(name string, exit int, sig syscall.Signal) ExternalCmdExit

func (ExternalCmdExit) Error

func (exit ExternalCmdExit) Error() string

type File

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

func (File) Equal added in v0.10.0

func (f File) Equal(rhs interface{}) bool

func (File) Hash added in v0.10.0

func (f File) Hash() uint32

func (File) Kind

func (File) Kind() string

func (File) Repr

func (f File) Repr(int) string

type Flow added in v0.6.0

type Flow uint

Flow is a special type of error used for control flows.

const (
	Return Flow = iota
	Break
	Continue
)

Control flows.

func (Flow) Error added in v0.6.0

func (f Flow) Error() string

func (Flow) Pprint added in v0.6.0

func (f Flow) Pprint(string) string

func (Flow) Repr added in v0.6.0

func (f Flow) Repr(int) string

type GlobFlag added in v0.6.0

type GlobFlag uint
const (
	NoMatchOK GlobFlag = 1 << iota
)

func (GlobFlag) Has added in v0.6.0

func (f GlobFlag) Has(g GlobFlag) bool

type GlobPattern

type GlobPattern struct {
	glob.Pattern
	Flags GlobFlag
	Buts  []string
}

GlobPattern is en ephemeral Value generated when evaluating tilde and wildcards.

func (GlobPattern) Equal added in v0.10.0

func (gp GlobPattern) Equal(a interface{}) bool

func (GlobPattern) Hash added in v0.10.0

func (gp GlobPattern) Hash() uint32

func (GlobPattern) Index

func (gp GlobPattern) Index(modifiers []Value) []Value

func (GlobPattern) Kind

func (GlobPattern) Kind() string

func (GlobPattern) Repr

func (gp GlobPattern) Repr(int) string

type HasKeyer

type HasKeyer interface {
	HasKey(k Value) bool
}

type Hasher added in v0.10.0

type Hasher interface {
	Hash() uint32
}

Hasher is anything that knows how to compute its hash code.

type IndexOneAssocer added in v0.10.0

type IndexOneAssocer interface {
	IndexOneer
	Assocer
}

IndexOneAssocer combines IndexOneer and Assocer.

type IndexOneer

type IndexOneer interface {
	IndexOne(idx Value) Value
}

IndexOneer is anything that can be indexed by one Value and yields one Value.

type IndexOneerIndexer

type IndexOneerIndexer struct {
	IndexOneer
}

IndexOneerIndexer adapts an IndexOneer to an Indexer by calling all the indicies on the IndexOner and collect the results.

func (IndexOneerIndexer) Index

func (ioi IndexOneerIndexer) Index(vs []Value) []Value

type Indexer

type Indexer interface {
	Index(idx []Value) []Value
}

Indexer is anything that can be indexed by Values and yields Values.

type Iterable added in v0.7.0

type Iterable interface {
	Iterate(func(Value) bool)
}

Iterable is anything that can be iterated.

type IterableValue added in v0.7.0

type IterableValue interface {
	Iterable
	Value
}

type IterateKeyer added in v0.6.0

type IterateKeyer interface {
	IterateKey(func(Value) bool)
}

IterateKeyer is anything with keys that can be iterated.

type IteratePairer added in v0.10.0

type IteratePairer interface {
	IteratePair(func(Value, Value) bool)
}

IteratePairer is anything with key-value pairs that can be iterated.

type Kinder

type Kinder interface {
	Kind() string
}

Kinder is anything with kind string.

type LValuesOp

type LValuesOp struct {
	Func       LValuesOpFunc
	Begin, End int
}

LValuesOp is an operation on an EvalCtx that produce Variable's.

func (LValuesOp) Exec

func (op LValuesOp) Exec(ec *EvalCtx) []Variable

Exec executes an LValuesOp, producing Variable's.

type LValuesOpFunc

type LValuesOpFunc func(*EvalCtx) []Variable

LValuesOpFunc is the body of an LValuesOp.

type Lener

type Lener interface {
	Len() int
}

Lener is anything with a length.

type List

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

List is a list of Value's.

func NewList

func NewList(vs ...Value) List

NewList creates a new List.

func NewListFromVector added in v0.9.0

func NewListFromVector(vec vector.Vector) List

func (List) Assoc added in v0.10.0

func (l List) Assoc(idx, v Value) Value

func (List) Equal added in v0.10.0

func (l List) Equal(rhs interface{}) bool

func (List) Hash added in v0.10.0

func (l List) Hash() uint32

func (List) IndexOne

func (l List) IndexOne(idx Value) Value

func (List) Iterate

func (l List) Iterate(f func(Value) bool)

func (List) Kind

func (List) Kind() string

func (List) Len

func (l List) Len() int

func (List) MarshalJSON

func (l List) MarshalJSON() ([]byte, error)

func (List) Repr

func (l List) Repr(indent int) string

type ListLike

type ListLike interface {
	Lener
	Iterable
	IndexOneer
}

type ListReprBuilder

type ListReprBuilder struct {
	Indent int
	// contains filtered or unexported fields
}

ListReprBuilder helps to build Repr of list-like Values.

func (*ListReprBuilder) String

func (b *ListReprBuilder) String() string

func (*ListReprBuilder) WriteElem

func (b *ListReprBuilder) WriteElem(v string)

type Map

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

Map is a map from string to Value.

func ConvertToMap added in v0.10.0

func ConvertToMap(m map[Value]Value) Map

ConvertToMap converts a native Go map to Map.

func NewMap

func NewMap(inner hashmap.HashMap) Map

NewMap creates a new Map from an inner HashMap.

func (Map) Assoc added in v0.10.0

func (m Map) Assoc(k, v Value) Value

func (Map) Dissoc added in v0.10.0

func (m Map) Dissoc(k Value) Value

func (Map) Equal added in v0.10.0

func (m Map) Equal(a interface{}) bool

func (Map) HasKey

func (m Map) HasKey(k Value) bool

func (Map) Hash added in v0.10.0

func (m Map) Hash() uint32

func (Map) IndexOne

func (m Map) IndexOne(idx Value) Value

func (Map) IterateKey added in v0.6.0

func (m Map) IterateKey(f func(Value) bool)

func (Map) IteratePair added in v0.10.0

func (m Map) IteratePair(f func(Value, Value) bool)

func (Map) Kind

func (Map) Kind() string

func (Map) Len

func (m Map) Len() int

func (Map) MarshalJSON

func (m Map) MarshalJSON() ([]byte, error)

func (Map) Repr

func (m Map) Repr(indent int) string

type MapReprBuilder

type MapReprBuilder struct {
	ListReprBuilder
}

MapReprBuilder helps building the Repr of a Map. It is also useful for implementing other Map-like values. The zero value of a MapReprBuilder is ready to use.

func (*MapReprBuilder) String

func (b *MapReprBuilder) String() string

func (*MapReprBuilder) WritePair

func (b *MapReprBuilder) WritePair(k string, indent int, v string)

type Namespace

type Namespace map[string]Variable

Namespace is a map from name to variables.

type Op

type Op struct {
	Func       OpFunc
	Begin, End int
}

Op is an operation on an EvalCtx.

func (Op) Exec

func (op Op) Exec(ec *EvalCtx)

Exec executes an Op.

type OpFunc

type OpFunc func(*EvalCtx)

OpFunc is the body of an Op.

type Opt added in v0.8.0

type Opt struct {
	Name    string
	Ptr     interface{}
	Default Value
}

Opt is a data structure for an option that is intended to be used in ScanOpts.

type Pipe added in v0.2.0

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

func (Pipe) Equal added in v0.10.0

func (p Pipe) Equal(rhs interface{}) bool

func (Pipe) Hash added in v0.10.0

func (p Pipe) Hash() uint32

func (Pipe) Kind added in v0.2.0

func (Pipe) Kind() string

func (Pipe) Repr added in v0.2.0

func (p Pipe) Repr(int) string

type PipelineError added in v0.6.0

type PipelineError struct {
	Errors []*Exception
}

PipelineError represents the errors of pipelines, in which multiple commands may error.

func (PipelineError) Error added in v0.6.0

func (pe PipelineError) Error() string

func (PipelineError) Repr added in v0.6.0

func (pe PipelineError) Repr(indent int) string

type Port

type Port struct {
	File      *os.File
	Chan      chan Value
	CloseFile bool
	CloseChan bool
}

Port conveys data stream. It always consists of a byte band and a channel band.

func (*Port) Close

func (p *Port) Close()

Close closes a Port.

func (*Port) Fork

func (p *Port) Fork() *Port

Fork returns a copy of a Port with the Close* flags unset.

type PwdVariable

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

PwdVariable is a variable whose value always reflects the current working directory. Setting it changes the current working directory.

func (PwdVariable) Get

func (PwdVariable) Get() Value

func (PwdVariable) Set

func (pwd PwdVariable) Set(v Value)

type Rat

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

Rat is a rational number.

func ToRat

func ToRat(v Value) (Rat, error)

ToRat converts a Value to rat. A str can be converted to a rat if it can be parsed. A rat is returned as-is. Other types of values cannot be converted.

func (Rat) Equal added in v0.10.0

func (r Rat) Equal(a interface{}) bool

func (Rat) Hash added in v0.10.0

func (r Rat) Hash() uint32

func (Rat) Kind

func (Rat) Kind() string

func (Rat) Repr

func (r Rat) Repr(int) string

func (Rat) String

func (r Rat) String() string

type Reprer

type Reprer interface {
	// Repr returns a string that represents a Value. The string either be a
	// literal of that Value that is preferably deep-equal to it (like `[a b c]`
	// for a list), or a string enclosed in "<>" containing the kind and
	// identity of the Value(like `<fn 0xdeadcafe>`).
	//
	// If indent is at least 0, it should be pretty-printed with the current
	// indentation level of indent; the indent of the first line has already
	// been written and shall not be written in Repr. The returned string
	// should never contain a trailing newline.
	Repr(indent int) string
}

Reprer is anything with a Repr method.

type String

type String string

String is just a string.

func (String) Assoc added in v0.10.0

func (s String) Assoc(idx, v Value) Value

func (String) Call

func (s String) Call(ec *EvalCtx, args []Value, opts map[string]Value)

Call resolves a command name to either a Fn variable or external command and calls it.

func (String) Equal added in v0.10.0

func (s String) Equal(rhs interface{}) bool

func (String) Hash added in v0.10.0

func (s String) Hash() uint32

func (String) IndexOne added in v0.5.0

func (s String) IndexOne(idx Value) Value

func (String) Iterate added in v0.5.0

func (s String) Iterate(f func(v Value) bool)

func (String) Kind

func (String) Kind() string

func (String) Len

func (s String) Len() int

func (String) Repr

func (s String) Repr(int) string

func (String) String

func (s String) String() string

type Stringer

type Stringer interface {
	String() string
}

Stringer is anything that can be converted to a string.

type Struct

type Struct struct {
	Descriptor *StructDescriptor
	Fields     []Value
}

Struct is like a Map with fixed keys.

func (*Struct) Assoc added in v0.10.0

func (s *Struct) Assoc(k, v Value) Value

func (*Struct) Equal added in v0.10.0

func (s *Struct) Equal(rhs interface{}) bool

Equal returns true if the rhs is MapLike and all pairs are equal.

func (*Struct) HasKey

func (s *Struct) HasKey(k Value) bool

func (*Struct) Hash added in v0.10.0

func (s *Struct) Hash() uint32

func (*Struct) IndexOne

func (s *Struct) IndexOne(idx Value) Value

func (*Struct) IterateKey added in v0.6.0

func (s *Struct) IterateKey(f func(Value) bool)

func (*Struct) IteratePair added in v0.10.0

func (s *Struct) IteratePair(f func(Value, Value) bool)

func (*Struct) Kind

func (*Struct) Kind() string

func (*Struct) Len

func (s *Struct) Len() int

func (*Struct) Repr

func (s *Struct) Repr(indent int) string

type StructDescriptor added in v0.10.0

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

func NewStructDescriptor added in v0.10.0

func NewStructDescriptor(fields ...string) *StructDescriptor

type Value

type Value interface {
	Kinder
	Equaler
	Hasher
	Reprer
}

Value is an elvish value.

func FromJSONInterface

func FromJSONInterface(v interface{}) Value

FromJSONInterface converts a interface{} that results from json.Unmarshal to a Value.

type ValueUnwrapper added in v0.10.0

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

ValueUnwrapper unwraps one Value.

func (ValueUnwrapper) Any added in v0.10.0

func (u ValueUnwrapper) Any() Value

func (ValueUnwrapper) Callable added in v0.10.0

func (u ValueUnwrapper) Callable() Callable

func (ValueUnwrapper) FdOrClose added in v0.10.0

func (u ValueUnwrapper) FdOrClose() int

func (ValueUnwrapper) Int added in v0.10.0

func (u ValueUnwrapper) Int() int

func (ValueUnwrapper) Iterable added in v0.10.0

func (u ValueUnwrapper) Iterable() Iterable

func (ValueUnwrapper) NonNegativeInt added in v0.10.0

func (u ValueUnwrapper) NonNegativeInt() int

func (ValueUnwrapper) String added in v0.10.0

func (u ValueUnwrapper) String() String

type ValuesOp

type ValuesOp struct {
	Func       ValuesOpFunc
	Begin, End int
}

ValuesOp is an operation on an EvalCtx that produce Value's.

func (ValuesOp) Exec

func (op ValuesOp) Exec(ec *EvalCtx) []Value

Exec executes a ValuesOp and produces Value's.

type ValuesOpFunc

type ValuesOpFunc func(*EvalCtx) []Value

ValuesOpFunc is the body of ValuesOp.

type ValuesUnwrapper added in v0.10.0

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

ValuesUnwrapper unwraps []Value.

func (ValuesUnwrapper) One added in v0.10.0

One unwraps the value to be exactly one value.

type Variable

type Variable interface {
	Set(v Value)
	Get() Value
}

Variable represents an elvish variable.

func MakeRoVariableFromCallback added in v0.3.0

func MakeRoVariableFromCallback(get func() Value) Variable

MakeRoVariableFromCallback makes a read-only variable from a get callback.

func MakeVariableFromCallback added in v0.3.0

func MakeVariableFromCallback(set func(Value), get func() Value) Variable

MakeVariableFromCallback makes a variable from a set callback and a get callback.

func NewPtrVariable

func NewPtrVariable(v Value) Variable

func NewPtrVariableWithValidator added in v0.3.0

func NewPtrVariableWithValidator(v Value, vld func(Value) error) Variable

func NewRoVariable

func NewRoVariable(v Value) Variable

Notes

Bugs

  • We rely on the fact that os.Unsetenv always returns nil.

  • When evaluating closures, async access to global variables and ports can be problematic.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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