Documentation ¶
Overview ¶
Package eval handles evaluation of nodes and consists the runtime of the shell.
Index ¶
- Constants
- Variables
- func ClosePorts(ports []*Port)
- func DeepEq(a, b Value) bool
- func IncIndent(indent, inc int) int
- func IsListOfFnValue(v Value) error
- func MakeVariableName(splice 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 ParseVariable(qname string) (splice bool, ns string, name string)
- func PprintError(e error)
- func ToBool(v Value) bool
- func ToString(v Value) string
- func WrapFn(inner interface{}) func(*EvalCtx, []Value)
- type Bool
- type Booler
- type BuiltinFn
- type Closure
- type EnvPathList
- func (epl *EnvPathList) Elems() <-chan Value
- 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 Error
- type EvalCtx
- func (ec *EvalCtx) IterateInputs(f func(Value))
- func (ec *EvalCtx) OutputChan() chan<- Value
- func (ec *EvalCtx) PCall(f Fn, args []Value) (err error)
- func (ec *EvalCtx) PCaptureOutput(f Fn, args []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) AllExecutables(names chan<- string)
- func (ev *Evaler) Compile(n *parse.Chunk) (Op, error)
- func (ev *Evaler) Eval(name, text string, n *parse.Chunk, ports []*Port) error
- func (ev *Evaler) EvalInteractive(text string, n *parse.Chunk) error
- func (ev *Evaler) Search(exe string) (string, error)
- func (ev *Evaler) Source(fname string) error
- func (ev *Evaler) SourceText(src string) error
- type ExternalCmd
- type ExternalCmdExit
- type File
- type Fn
- type FnAsIndexer
- type FnValue
- type GlobPattern
- type HasKeyer
- type IndexOneer
- type IndexOneerIndexer
- type IndexSetter
- type Indexer
- type IndexerAsFn
- type Iterator
- type IteratorValue
- type Kinder
- type LValuesOp
- type LValuesOpFunc
- type Lener
- type List
- type ListLike
- type ListReprBuilder
- type Map
- type MapLike
- type MapReprBuilder
- type MapStringString
- type MultiError
- type Namespace
- type Op
- type OpFunc
- type Pipe
- 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 ( Return flow = iota Break Continue )
Control flows.
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") )
var ( ErrBadGlobPattern = errors.New("bad GlobPattern; elvish bug") ErrCannotDetermineUsername = errors.New("cannot determine user name from glob pattern") )
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 ( ErrMustFollowWildcard = errors.New("must follow wildcard") ErrModifierMustBeString = errors.New("modifier must be string") )
var ( // ErrNeedIntIndex = errors.New("need integer index") ErrBadIndex = errors.New("bad index") ErrIndexOutOfRange = errors.New("index out of range") )
Error definitions.
var BuiltinSpecialNames []string
BuiltinSpecialNames contains all names of builtin special forms. It is useful for the syntax highlighter.
var ErrArityMismatch = errors.New("arity mismatch")
var ErrBadBase = errors.New("bad base")
var ErrCdNoArg = errors.New("implicit cd accepts no arguments")
var (
ErrIndexMustBeString = errors.New("index must be string")
)
var ErrMoreThanOneRest = errors.New("more than one @ lvalue")
var (
ErrOnlyStrOrRat = errors.New("only str or rat may be converted to rat")
)
Error definitions.
var (
ErrRoCannotBeSet = errors.New("read-only; 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 Logger = util.GetLogger("[eval] ")
var OK = Error{nil}
OK is an alias for the zero value of Error.
Functions ¶
func IsListOfFnValue ¶
func NewExternalCmdExit ¶
func NewExternalCmdExit(name string, ws syscall.WaitStatus, pid int) error
func ParseAndFixListIndex ¶
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 ParseVariable ¶
ParseVariable parses a variable name.
func PprintError ¶
func PprintError(e error)
PprintError pretty prints an error. It understands specialized error types defined in this package.
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.
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 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 }
Closure is a closure defined in elvish script.
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) Elems ¶
func (epl *EnvPathList) Elems() <-chan Value
func (*EnvPathList) Get ¶
func (epl *EnvPathList) Get() Value
func (*EnvPathList) IndexOne ¶
func (epl *EnvPathList) IndexOne(idx Value) Value
func (*EnvPathList) IndexSet ¶
func (epl *EnvPathList) IndexSet(idx, v Value)
func (*EnvPathList) Iterate ¶
func (epl *EnvPathList) Iterate(f func(Value) bool)
func (*EnvPathList) Kind ¶
func (epl *EnvPathList) Kind() string
func (*EnvPathList) Len ¶
func (epl *EnvPathList) Len() int
func (*EnvPathList) Repr ¶
func (epl *EnvPathList) Repr(indent int) string
func (*EnvPathList) Set ¶
func (epl *EnvPathList) Set(v Value)
type Error ¶
type Error struct {
Inner error
}
Error represents runtime errors in elvish constructs.
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 not modified, and new instances are created when needed.
func NewTopEvalCtx ¶
NewTopEvalCtx creates a top-level evalCtx.
func (*EvalCtx) IterateInputs ¶
IterateInput calls the passed function for each input element.
func (*EvalCtx) OutputChan ¶
OutputChan returns a channel 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 { Global Namespace Modules map[string]Namespace Stub *stub.Stub // contains filtered or unexported fields }
Evaler is used to evaluate elvish sources. It maintains runtime context shared among all evalCtx instances.
func (*Evaler) AllExecutables ¶
AllExecutables writes the names of all executable files in the search path to a channel.
func (*Evaler) Eval ¶
Eval evaluates a chunk node n. The supplied name and text are used in diagnostic messages.
func (*Evaler) EvalInteractive ¶
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 ExternalCmd ¶
type ExternalCmd struct {
Name string
}
ExternalCmd is an external command.
func (ExternalCmd) Call ¶
func (e ExternalCmd) Call(ec *EvalCtx, argVals []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 FnAsIndexer ¶
type FnAsIndexer struct { Fn // contains filtered or unexported fields }
FnAsIndexer adapts a Fn to an Indexer.
func (FnAsIndexer) Index ¶
func (ci FnAsIndexer) Index(idx []Value) []Value
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 IndexerAsFn ¶
type IndexerAsFn struct {
Indexer
}
IndexerAsFn adapts an Indexer to a Fn.
func (IndexerAsFn) Call ¶
func (ic IndexerAsFn) Call(ec *EvalCtx, args []Value)
type IteratorValue ¶
type LValuesOp ¶
type LValuesOp struct { Func LValuesOpFunc Begin, End int }
VariablesOp is an operation on an EvalCtx that produce Variable's.
type LValuesOpFunc ¶
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a list of Value's.
func (List) MarshalJSON ¶
type ListLike ¶
type ListLike interface { Lener Iterator 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) MarshalJSON ¶
type MapLike ¶
type MapLike interface { Lener IndexOneer HasKeyer }
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, v string)
type MapStringString ¶
MapStringString implements MapLike for map[string]string.
func (MapStringString) HasKey ¶
func (m MapStringString) HasKey(idx Value) bool
func (MapStringString) IndexOne ¶
func (m MapStringString) IndexOne(idx Value) Value
func (MapStringString) IndexSet ¶
func (m MapStringString) IndexSet(idx Value, val Value)
func (MapStringString) Kind ¶
func (MapStringString) Kind() string
func (MapStringString) Len ¶
func (m MapStringString) Len() int
func (MapStringString) Repr ¶
func (m MapStringString) Repr(indent int) string
type MultiError ¶
type MultiError struct {
Errors []Error
}
multiError is multiple errors packed into one. It is used for reporting errors of pipelines, in which multiple forms may error.
func (MultiError) Error ¶
func (me MultiError) Error() string
func (MultiError) Repr ¶
func (me MultiError) Repr(indent int) string
type PwdVariable ¶
type PwdVariable struct{}
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 (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 ValuesOpFunc ¶
type Variable ¶
Variable represents an elvish variable.
func NewPtrVariable ¶
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 ¶
- boilerplate.go
- builtin_func.go
- builtin_modules.go
- builtin_ns.go
- builtin_special.go
- closure.go
- compile_lvalue_op.go
- compile_op.go
- compile_values_op.go
- compiler.go
- env_path_list.go
- error.go
- eval.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