Documentation ¶
Overview ¶
Package eval handles evaluation of nodes and consists the runtime of the shell.
Index ¶
- Constants
- Variables
- func AddBuiltinFns(ns Namespace, fns ...*BuiltinFn)
- func Chdir(path string, daemon *api.Client) error
- func ClosePorts(ports []*Port)
- func ComposeExceptionsFromPipeline(excs []*Exception) error
- func DeepEq(a, b Value) bool
- func MakeVariableName(explode bool, ns string, name string) string
- func NewExternalCmdExit(name string, ws syscall.WaitStatus, pid int) error
- func ParseAndFixListIndex(s string, n int) (bool, int, int)
- func ParseAndFixVariable(qname string) (explode bool, ns string, name string)
- func ParseVariable(text string) (explode bool, ns string, name string)
- func ParseVariableQName(qname string) (ns, name string)
- func ParseVariableSplice(text string) (explode, qname string)
- func ScanArgs(s []Value, args ...interface{})
- func ScanArgsAndOptionalIterate(ec *EvalCtx, s []Value, args ...interface{}) func(func(Value))
- func ScanArgsVariadic(s []Value, args ...interface{})
- func ScanOpts(m map[string]Value, opts ...Opt)
- func ShouldBeBool(v Value) error
- func ShouldBeFn(v Value) error
- func ShouldBeList(v Value) error
- func ShouldBeMap(v Value) error
- func TakeNoArg(args []Value)
- func TakeNoOpt(opts map[string]Value)
- func ToBool(v Value) bool
- func ToString(v Value) string
- func WrapStringToString(f func(string) string) func(*EvalCtx, []Value, map[string]Value)
- func WrapStringToStringError(f func(string) (string, error)) func(*EvalCtx, []Value, map[string]Value)
- type Bool
- type Booler
- type BuiltinFn
- type Callable
- type CallableValue
- type Closure
- type CompilationError
- type Editor
- type EnvPathList
- func (epl *EnvPathList) Get() Value
- func (epl *EnvPathList) IndexOne(idx Value) Value
- func (epl *EnvPathList) IndexSet(idx, v Value)
- func (epl *EnvPathList) Iterate(f func(Value) bool)
- func (epl *EnvPathList) Kind() string
- func (epl *EnvPathList) Len() int
- func (epl *EnvPathList) Repr(indent int) string
- func (epl *EnvPathList) Set(v Value)
- type EvalCtx
- func (ec *EvalCtx) Interrupts() <-chan struct{}
- func (ec *EvalCtx) IterateInputs(f func(Value))
- func (ec *EvalCtx) OutputChan() chan<- Value
- func (ec *EvalCtx) OutputFile() *os.File
- func (ec *EvalCtx) PCall(f Callable, args []Value, opts map[string]Value) (err error)
- func (ec *EvalCtx) PCaptureOutput(f Callable, args []Value, opts map[string]Value) (vs []Value, err error)
- func (ec *EvalCtx) PEval(op Op) (err error)
- func (ec *EvalCtx) ResolveVar(ns, name string) Variable
- type Evaler
- func (ev *Evaler) Compile(n *parse.Chunk, name, text string) (Op, error)
- func (ev *Evaler) EachExternal(f func(string))
- func (ev *Evaler) Eval(op Op, name, text string) error
- func (ev *Evaler) EvalWithPorts(ports []*Port, op Op, name, text string) error
- func (ev *Evaler) Search(exe string) (string, error)
- func (ev *Evaler) Source(fname string) error
- func (ev *Evaler) SourceText(name, src string) error
- type Exception
- type ExternalCmd
- type ExternalCmdExit
- type File
- type Flow
- type GlobFlag
- type GlobPattern
- type HasKeyer
- type IndexOneer
- type IndexOneerIndexer
- type IndexSetter
- type Indexer
- type Iterable
- type IterableValue
- type IterateKeyer
- type Kinder
- type LValuesOp
- type LValuesOpFunc
- type Lener
- type List
- type ListLike
- type ListReprBuilder
- type Map
- type MapLike
- type MapReprBuilder
- type MapStringString
- func (m MapStringString) HasKey(idx Value) bool
- func (m MapStringString) IndexOne(idx Value) Value
- func (m MapStringString) IndexSet(idx Value, val Value)
- func (m MapStringString) IterateKey(f func(Value) bool)
- func (MapStringString) Kind() string
- func (m MapStringString) Len() int
- func (m MapStringString) Repr(indent int) string
- type Namespace
- type Op
- type OpFunc
- type Opt
- type Pipe
- type PipelineError
- type Port
- type PwdVariable
- type Rat
- type Reprer
- type String
- type Stringer
- type Struct
- type Value
- type ValuesOp
- type ValuesOpFunc
- type Variable
- Bugs
Constants ¶
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".
const (
NoPretty = util.MinInt
)
Variables ¶
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") ErrInterrupted = errors.New("interrupted") )
Errors thrown by builtins.
var ( ErrBadGlobPattern = errors.New("bad GlobPattern; elvish bug") ErrCannotDetermineUsername = errors.New("cannot determine user name from glob pattern") )
Errors thrown when globbing.
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
var ( ErrExternalCmdOpts = errors.New("external commands don't accept elvish options") ErrCdNoArg = errors.New("implicit cd accepts no arguments") )
var ( ErrMustFollowWildcard = errors.New("must follow wildcard") ErrModifierMustBeString = errors.New("modifier must be string") ErrWildcardNoMatch = errors.New("wildcard has no match") )
var ( // ErrNeedIntIndex = errors.New("need integer index") ErrBadIndex = errors.New("bad index") ErrIndexOutOfRange = errors.New("index out of range") )
Error definitions.
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 )
var ( ErrNoArgAccepted = errors.New("no argument accepted") ErrNoOptAccepted = errors.New("no option accepted") )
var ( NoArgs = []Value{} NoOpts = map[string]Value{} )
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.
var ErrBadBase = errors.New("bad base")
ErrBadBase is thrown by the "base" builtin if the base is smaller than 2 or greater than 36.
var ErrDaemonOffline = errors.New("daemon is offline")
var (
ErrIndexMustBeString = errors.New("index must be string")
)
var ErrMoreThanOneRest = errors.New("more than one @ lvalue")
var ErrNoDataDir = errors.New("There is no data directory")
ErrNoDataDir is thrown by the "use" special form when there is no data directory.
var (
ErrOnlyStrOrRat = errors.New("only str or rat may be converted to rat")
)
Error definitions.
var (
ErrRoCannotBeSet = errors.New("read-only variable; cannot be set")
)
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.
var (
ErrValueMustBeString = errors.New("index must be string")
)
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.
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
AddBuiltinFns adds builtin functions to a namespace.
func Chdir ¶ added in v0.9.0
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 ComposeExceptionsFromPipeline ¶ added in v0.6.0
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 NewExternalCmdExit ¶
func NewExternalCmdExit(name string, ws syscall.WaitStatus, pid int) error
func ParseAndFixListIndex ¶ added in v0.3.0
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
ParseAndFixVariable parses a variable name. It "fixes" $@ to $@args.
func ParseVariableQName ¶ added in v0.5.0
func ParseVariableSplice ¶ added in v0.5.0
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
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 ShouldBeBool ¶ added in v0.6.0
func ShouldBeFn ¶ added in v0.6.0
func ShouldBeList ¶ added in v0.6.0
func ShouldBeMap ¶ added in v0.6.0
func ToBool ¶
ToBool converts a Value to bool. When the Value type implements Bool(), it is used. Otherwise it is considered true.
func ToString ¶
ToString converts a Value to String. When the Value type implements String(), it is used. Otherwise Repr(NoPretty) is used.
func WrapStringToString ¶ added in v0.9.0
Types ¶
type Booler ¶
type Booler interface {
Bool() bool
}
Booler is anything that can be converted to a bool.
type BuiltinFn ¶
BuiltinFn is a builtin function.
type Callable ¶ added in v0.7.0
Callable is anything may be called on an evalCtx with a list of Value's.
type CallableValue ¶ added in v0.7.0
type Closure ¶
type Closure struct { ArgNames []string // The name for the rest argument. If empty, the function has fixed arity. // If equal to unnamedRestArg, the rest argument is unnamed but can be // accessed via $args. RestArg string Op Op Captured map[string]Variable SourceName string Source string }
Closure is a closure defined in elvish script.
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 Editor ¶ added in v0.4.0
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 EnvPathList ¶
EnvPathList 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.
EnvPathList implements both Value and Variable interfaces. It also satisfied ListLike.
func (*EnvPathList) Get ¶
func (epl *EnvPathList) Get() Value
Get returns a Value for an EnvPathList.
func (*EnvPathList) IndexOne ¶
func (epl *EnvPathList) IndexOne(idx Value) Value
IndexOne returns the result of one indexing operation.
func (*EnvPathList) IndexSet ¶
func (epl *EnvPathList) IndexSet(idx, v Value)
IndexSet sets one value in an EnvPathList.
func (*EnvPathList) Iterate ¶
func (epl *EnvPathList) Iterate(f func(Value) bool)
Iterate iterates an EnvPathList.
func (*EnvPathList) Len ¶
func (epl *EnvPathList) Len() int
Len returns the length of an EnvPathList.
func (*EnvPathList) Repr ¶
func (epl *EnvPathList) Repr(indent int) string
Repr returns the representation of an EnvPathList, as if it were an ordinary list.
func (*EnvPathList) Set ¶
func (epl *EnvPathList) Set(v Value)
Set sets an EnvPathList. The underlying environment variable is set.
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 ¶
NewTopEvalCtx creates a top-level evalCtx.
func (*EvalCtx) Interrupts ¶ added in v0.5.0
func (ec *EvalCtx) Interrupts() <-chan struct{}
func (*EvalCtx) IterateInputs ¶
IterateInputs calls the passed function for each input element.
func (*EvalCtx) OutputChan ¶
OutputChan returns a channel onto which output can be written.
func (*EvalCtx) OutputFile ¶ added in v0.9.0
OutputFile returns a file onto which output can be written.
func (*EvalCtx) PCaptureOutput ¶
func (*EvalCtx) PEval ¶
PEval evaluates an op in a protected environment so that calls to errorf are wrapped in an Error.
func (*EvalCtx) ResolveVar ¶
ResolveVar resolves a variable. When the variable cannot be found, nil is returned.
type Evaler ¶
type Evaler struct { Builtin Namespace 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) Compile ¶
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
EachExternal calls f for each name that can resolve to an external command.
func (*Evaler) Eval ¶
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
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 ¶
Search tries to resolve an external command and return the full (possibly relative) path.
func (*Evaler) SourceText ¶
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.
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) 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 GlobPattern ¶
GlobPattern is en ephemeral Value generated when evaluating tilde and wildcards.
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 IndexOneer ¶
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 IndexSetter ¶
type IndexSetter interface { IndexOneer IndexSet(idx Value, v Value) }
IndexSetter is a Value whose elements can be get as well as set.
type IterableValue ¶ added in v0.7.0
type IterateKeyer ¶ added in v0.6.0
IterateKeyer is anything with keys that can be iterated.
type LValuesOp ¶
type LValuesOp struct { Func LValuesOpFunc Begin, End int }
LValuesOp is an operation on an EvalCtx that produce Variable's.
type LValuesOpFunc ¶
LValuesOpFunc is the body of an LValuesOp.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a list of Value's.
func NewListFromVector ¶ added in v0.9.0
func (List) MarshalJSON ¶
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 (Map) IterateKey ¶ added in v0.6.0
func (Map) MarshalJSON ¶
type MapLike ¶
type MapLike interface { Lener IndexOneer HasKeyer IterateKeyer }
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
type MapStringString ¶ added in v0.2.0
MapStringString implements MapLike for map[string]string.
func (MapStringString) HasKey ¶ added in v0.2.0
func (m MapStringString) HasKey(idx Value) bool
func (MapStringString) IndexOne ¶ added in v0.2.0
func (m MapStringString) IndexOne(idx Value) Value
func (MapStringString) IndexSet ¶ added in v0.2.0
func (m MapStringString) IndexSet(idx Value, val Value)
func (MapStringString) IterateKey ¶ added in v0.6.0
func (m MapStringString) IterateKey(f func(Value) bool)
func (MapStringString) Kind ¶ added in v0.2.0
func (MapStringString) Kind() string
func (MapStringString) Len ¶ added in v0.2.0
func (m MapStringString) Len() int
func (MapStringString) Repr ¶ added in v0.2.0
func (m MapStringString) Repr(indent int) string
type Opt ¶ added in v0.8.0
Opt is a data structure for an option that is intended to be used in ScanOpts.
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 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.
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.
type Stringer ¶
type Stringer interface {
String() string
}
Stringer is anything that can be converted to a string.
type Value ¶
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 ValuesOp ¶
type ValuesOp struct { Func ValuesOpFunc Begin, End int }
ValuesOp is an operation on an EvalCtx that produce Value's.
type Variable ¶
Variable represents an elvish variable.
func MakeRoVariableFromCallback ¶ added in v0.3.0
MakeRoVariableFromCallback makes a read-only variable from a get callback.
func MakeVariableFromCallback ¶ added in v0.3.0
MakeVariableFromCallback makes a variable from a set callback and a get callback.
func NewPtrVariable ¶
func NewPtrVariableWithValidator ¶ added in v0.3.0
func NewRoVariable ¶
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.
Source Files ¶
- args_walker.go
- boilerplate.go
- builtin_fn.go
- builtin_namespace.go
- builtin_special.go
- chdir.go
- closure.go
- compilation_error.go
- compile_lvalue.go
- compile_op.go
- compile_value.go
- compiler.go
- daemon_namespace.go
- editor.go
- embedded_modules.go
- env_path_list.go
- eval.go
- exception.go
- external_cmd.go
- file.go
- glob.go
- list.go
- map.go
- mapstringstring.go
- must.go
- pipe.go
- port.go
- pwd.go
- search.go
- shared.go
- string.go
- struct.go
- util.go
- validator.go
- value.go
- variable.go