eval

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2018 License: BSD-2-Clause Imports: 39 Imported by: 0

Documentation

Overview

Package eval handles evaluation of parsed Elvish code and provides runtime facilities.

Index

Constants

View Source
const (
	// FnSuffix is the suffix for the variable names of functions. Defining a
	// function "foo" is equivalent to setting a variable named "foo~", and vice
	// versa.
	FnSuffix = "~"
	// NsSuffix is the suffix for the variable names of namespaces. Defining a
	// namespace foo is equivalent to setting a variable named "foo:", and vice
	// versa.
	NsSuffix = ":"
)

Variables

View Source
var (
	// ErrNoLibDir is thrown by "use" when the Evaler does not have a library
	// directory.
	ErrNoLibDir = errors.New("Evaler does not have a lib directory")
	// ErrRelativeUseNotFromMod is thrown by "use" when relative use is used
	// not from a module
	ErrRelativeUseNotFromMod = errors.New("Relative use not from module")
	// ErrRelativeUseGoesOutsideLib is thrown when a relative use goes out of
	// the library directory.
	ErrRelativeUseGoesOutsideLib = errors.New("Module outside library directory")
)
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 (
	// ClosedChan is a closed channel, suitable for use as placeholder channel input.
	ClosedChan = make(chan types.Value)
	// BlackholeChan is channel writes onto which disappear, suitable for use as
	// placeholder channel output.
	BlackholeChan = make(chan types.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 is an empty argument list. It can be used as an argument to Call.
	NoArgs = []types.Value{}
	// NoOpts is an empty option map. It can be used as an argument to Call.
	NoOpts = map[string]types.Value{}
)
View Source
var ErrArgs = errors.New("args error")
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 ErrImpure = errors.New("expression is impure")
View Source
var ErrInput = errors.New("input error")
View Source
var ErrInterrupted = errors.New("interrupted")
View Source
var ErrMoreThanOneRest = errors.New("more than one @ lvalue")

ErrMoreThanOneRest is thrown when the LHS of an assignment contains more than one rest variables.

View Source
var ErrNotInSameGroup = errors.New("not in the same process group")
View Source
var ErrStoreNotConnected = errors.New("store not connected")
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 Ns, fns ...*BuiltinFn)

AddBuiltinFns adds builtin functions to a namespace.

func Chdir added in v0.9.0

func Chdir(path string, store AddDirer) 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 EachExternal added in v0.11.0

func EachExternal(f func(string))

EachExternal calls f for each name that can resolve to an external command. TODO(xiaq): Windows support

func FromJSONInterface

func FromJSONInterface(v interface{}) types.Value

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

func MakeVariableName

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

func NewExternalCmdExit

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

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 PurelyEvalCompound added in v0.11.0

func PurelyEvalCompound(cn *parse.Compound) (string, error)

func RunTests added in v0.11.0

func RunTests(t *testing.T, evalTests []Test, makeEvaler func() *Evaler)

RunTests runs test cases. For each test case, a new Evaler is made by calling makeEvaler.

func ScanArgs added in v0.8.0

func ScanArgs(src []types.Value, dstPtrs ...interface{})

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

func ScanArgsOptionalInput added in v0.11.0

func ScanArgsOptionalInput(ec *Frame, src []types.Value, dstArgs ...interface{}) func(func(types.Value))

ScanArgsOptionalInput is like ScanArgs, but the argument can contain an optional iterable value at the end containing inputs to the function. 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(src []types.Value, dstPtrs ...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]types.Value, opts ...OptToScan)

ScanOpts scans options from a map.

func ScanOptsToStruct added in v0.10.0

func ScanOptsToStruct(m map[string]types.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 ShouldBeFn added in v0.6.0

func ShouldBeFn(v types.Value) error

func ShouldBeNs added in v0.11.0

func ShouldBeNs(v types.Value) error

func TakeNoArg added in v0.4.0

func TakeNoArg(args []types.Value)

func TakeNoOpt added in v0.4.0

func TakeNoOpt(opts map[string]types.Value)

Types

type AddDirer added in v0.11.0

type AddDirer interface {
	// AddDir adds a directory with the given weight to some storage.
	AddDir(dir string, weight float64) error
}

AddDirer wraps the AddDir function.

type BuiltinFn

type BuiltinFn struct {
	Name string
	Impl BuiltinFnImpl
}

BuiltinFn is a builtin function.

func (*BuiltinFn) Call

func (b *BuiltinFn) Call(ec *Frame, args []types.Value, opts map[string]types.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(*Frame, []types.Value, map[string]types.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 calls the receiver in a Frame with arguments and options.
	Call(ec *Frame, args []types.Value, opts map[string]types.Value)
}

Callable wraps the Call method.

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 []types.Value
	Op          Op
	Captured    Ns
	SrcMeta     *Source
}

Closure is a closure defined in elvish script.

func (*Closure) Call

func (c *Closure) Call(ec *Frame, args []types.Value, opts map[string]types.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.SourceRange
}

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

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 pathListSeparator. Changes to it are also propagated to the corresponding environment variable. Its elements cannot contain pathListSeparator or \0; attempting to put any in its elements will result in an error.

func (*EnvList) Get added in v0.10.0

func (envli *EnvList) Get() types.Value

Get returns a Value for an EnvPathList.

func (*EnvList) Set added in v0.10.0

func (envli *EnvList) Set(v types.Value) error

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

type Evaler

type Evaler struct {
	DaemonClient *daemon.Client

	Editor Editor
	// 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() *Evaler

NewEvaler creates a new Evaler.

func (*Evaler) Close added in v0.11.0

func (ev *Evaler) Close()

Close releases resources allocated when creating this Evaler.

func (*Evaler) Compile

func (ev *Evaler) Compile(n *parse.Chunk, src *Source) (Op, error)

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

func (*Evaler) EachModInTop added in v0.11.0

func (ev *Evaler) EachModInTop(f func(s string))

EachModInTop calls the passed function for each module that can be found from the top context.

func (*Evaler) EachNsInTop added in v0.11.0

func (ev *Evaler) EachNsInTop(f func(s string))

EachNsInTop calls the passed function for each namespace that can be used from the top context.

func (*Evaler) EachVariableInTop added in v0.11.0

func (ev *Evaler) EachVariableInTop(ns string, f func(s string))

EachVariableInTop calls the passed function for each variable name in namespace ns that can be found from the top context.

func (*Evaler) Eval

func (ev *Evaler) Eval(op Op, src *Source) 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, src *Source) 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) InstallBundled added in v0.11.0

func (ev *Evaler) InstallBundled(name, src string)

InstallBundled installs a bundled module to the Evaler.

func (*Evaler) InstallDaemonClient added in v0.11.0

func (ev *Evaler) InstallDaemonClient(client *daemon.Client)

InstallDaemonClient installs a daemon client to the Evaler.

func (*Evaler) InstallModule added in v0.11.0

func (ev *Evaler) InstallModule(name string, mod Ns)

InstallModule installs a module to the Evaler so that it can be used with "use $name" from script.

func (*Evaler) PurelyEvalCompound added in v0.11.0

func (ev *Evaler) PurelyEvalCompound(cn *parse.Compound) (string, error)

func (*Evaler) PurelyEvalPartialCompound added in v0.11.0

func (ev *Evaler) PurelyEvalPartialCompound(cn *parse.Compound, upto *parse.Indexing) (string, error)

func (*Evaler) PurelyEvalPrimary added in v0.11.0

func (ev *Evaler) PurelyEvalPrimary(pn *parse.Primary) types.Value

PurelyEvalPrimary evaluates a primary node without causing any side effects. If this cannot be done, it returns nil.

Currently, only string literals and variables with no @ can be evaluated.

func (*Evaler) SetArgs added in v0.11.0

func (ev *Evaler) SetArgs(args []string)

SetArgs sets the $args builtin variable.

func (*Evaler) SetLibDir added in v0.11.0

func (ev *Evaler) SetLibDir(libDir string)

SetLibDir sets the library directory, in which external modules are to be found.

func (*Evaler) Source

func (ev *Evaler) Source(name, path string) error

Source evaluates the content of a file.

func (*Evaler) SourceText

func (ev *Evaler) SourceText(src *Source) error

SourceText evaluates a chunk of elvish source.

type Exception added in v0.6.0

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

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 *Frame, argVals []types.Value, opts map[string]types.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 (ExternalCmdExit) Error

func (exit ExternalCmdExit) Error() 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 Fn

type Fn interface {
	types.Value
	Callable
}

Fn is a callable value.

type Frame added in v0.11.0

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

Frame contains information of the current running function, aknin to a call frame in native CPU execution. A Frame is only modified during and very shortly after creation; new Frame's are "forked" when needed.

func NewTopFrame added in v0.11.0

func NewTopFrame(ev *Evaler, src *Source, ports []*Port) *Frame

NewTopFrame creates a top-level Frame.

func (*Frame) CheckInterrupts added in v0.11.0

func (ec *Frame) CheckInterrupts()

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

func (Frame) EachModInTop added in v0.11.0

func (ev Frame) EachModInTop(f func(s string))

EachModInTop calls the passed function for each module that can be found from the top context.

func (Frame) EachNsInTop added in v0.11.0

func (ev Frame) EachNsInTop(f func(s string))

EachNsInTop calls the passed function for each namespace that can be used from the top context.

func (Frame) EachVariableInTop added in v0.11.0

func (ev Frame) EachVariableInTop(ns string, f func(s string))

EachVariableInTop calls the passed function for each variable name in namespace ns that can be found from the top context.

func (*Frame) ExecAndUnwrap added in v0.11.0

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

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

func (*Frame) InputChan added in v0.11.0

func (ec *Frame) InputChan() chan types.Value

InputChan returns a channel from which input can be read.

func (*Frame) InputFile added in v0.11.0

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

InputFile returns a file from which input can be read.

func (*Frame) Interrupts added in v0.11.0

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

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

func (*Frame) IterateInputs added in v0.11.0

func (ec *Frame) IterateInputs(f func(types.Value))

IterateInputs calls the passed function for each input element.

func (*Frame) OutputChan added in v0.11.0

func (ec *Frame) OutputChan() chan<- types.Value

OutputChan returns a channel onto which output can be written.

func (*Frame) OutputFile added in v0.11.0

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

OutputFile returns a file onto which output can be written.

func (*Frame) PCall added in v0.11.0

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

func (*Frame) PCaptureOutput added in v0.11.0

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

func (*Frame) PCaptureOutputInner added in v0.11.0

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

func (*Frame) PEval added in v0.11.0

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

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

func (*Frame) ResolveMod added in v0.11.0

func (ec *Frame) ResolveMod(name string) Ns

func (*Frame) ResolveVar added in v0.11.0

func (ec *Frame) ResolveVar(ns, name string) vartypes.Variable

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

func (*Frame) Unwrap added in v0.11.0

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

Unwrap creates an Unwrapper.

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 []types.Value) []types.Value

func (GlobPattern) Kind

func (GlobPattern) Kind() string

func (GlobPattern) Repr

func (gp GlobPattern) Repr(int) 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 *Frame) []vartypes.Variable

Exec executes an LValuesOp, producing Variable's.

type LValuesOpFunc

type LValuesOpFunc func(*Frame) []vartypes.Variable

LValuesOpFunc is the body of an LValuesOp.

type Ns added in v0.11.0

type Ns map[string]vartypes.Variable

Ns is a map from names to variables.

func (Ns) Equal added in v0.11.0

func (ns Ns) Equal(rhs interface{}) bool

func (Ns) Hash added in v0.11.0

func (ns Ns) Hash() uint32

func (Ns) Kind added in v0.11.0

func (Ns) Kind() string

func (Ns) Repr added in v0.11.0

func (ns Ns) Repr(int) string

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 *Frame)

Exec executes an Op.

type OpFunc

type OpFunc func(*Frame)

OpFunc is the body of an Op.

type OptToScan added in v0.11.0

type OptToScan struct {
	Name    string
	Ptr     interface{}
	Default types.Value
}

OptToScan 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 Port

type Port struct {
	File      *os.File
	Chan      chan types.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() types.Value

func (PwdVariable) Set

func (pwd PwdVariable) Set(v types.Value) error

type Source added in v0.11.0

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

Source describes a piece of source code.

func NewInteractiveSource added in v0.11.0

func NewInteractiveSource(code string) *Source

NewInteractiveSource returns a Source for a piece of code entered interactively.

func NewInternalSource added in v0.11.0

func NewInternalSource(name string) *Source

func NewModuleSource added in v0.11.0

func NewModuleSource(name, path, code string) *Source

NewModuleSource returns a Source for a piece of code used as a module.

func NewScriptSource added in v0.11.0

func NewScriptSource(name, path, code string) *Source

NewScriptSource returns a Source for a piece of code used as a script.

func (*Source) Equal added in v0.11.0

func (src *Source) Equal(other interface{}) bool

func (*Source) Hash added in v0.11.0

func (src *Source) Hash() uint32

func (*Source) IndexOne added in v0.11.0

func (src *Source) IndexOne(k types.Value) types.Value

func (*Source) Kind added in v0.11.0

func (src *Source) Kind() string

func (*Source) Repr added in v0.11.0

func (src *Source) Repr(int) string

type SrcType added in v0.11.0

type SrcType int

SrcType records the type of a piece of source code.

const (
	// SrcInternal is a special SrcType for internal operations.
	SrcInternal SrcType = iota
	// SrcInteractive is the type of source code entered interactively.
	SrcInteractive
	// SrcScript is the type of source code used as a script.
	SrcScript
	// SrcModule is the type of source code used as a module.
	SrcModule
)

func (SrcType) String added in v0.11.0

func (t SrcType) String() string

type Test added in v0.11.0

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

Test is a test case for TestEval.

func NewTest added in v0.11.0

func NewTest(text string) Test

NewTest returns a new Test with the specified source code.

func (Test) WantAnyErr added in v0.11.0

func (t Test) WantAnyErr() Test

WantAnyErr returns an altered Test that requires the source code to result in any error when evaluated.

func (Test) WantBytesOut added in v0.11.0

func (t Test) WantBytesOut(b []byte) Test

WantBytesOut returns an altered test that requires the source code to produce the specified output in the byte pipe when evaluated.

func (Test) WantBytesOutString added in v0.11.0

func (t Test) WantBytesOutString(s string) Test

WantBytesOutString is the same as WantBytesOut except that its argument is a string.

func (Test) WantErr added in v0.11.0

func (t Test) WantErr(err error) Test

WantErr returns an altered Test that requires the source code to result in the specified error when evaluted.

func (Test) WantOut added in v0.11.0

func (t Test) WantOut(vs ...types.Value) Test

WantOut returns an altered Test that requires the source code to produce the specified values in the value channel when evaluated.

func (Test) WantOutBools added in v0.11.0

func (t Test) WantOutBools(bs ...bool) Test

WantOutBools returns an altered Test that requires the source code to produce the specified boolean values in the value channel when evaluated.

func (Test) WantOutStrings added in v0.11.0

func (t Test) WantOutStrings(ss ...string) Test

WantOutStrings returns an altered Test that requires the source code to produce the specified string values in the value channel when evaluated.

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() types.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() types.Iterator

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() types.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 *Frame) []types.Value

Exec executes a ValuesOp and produces Value's.

type ValuesOpFunc

type ValuesOpFunc func(*Frame) []types.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.

Notes

Bugs

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

Directories

Path Synopsis
Package bundled keeps bundled modules.
Package bundled keeps bundled modules.
Package daemon implements the builtin daemon: module.
Package daemon implements the builtin daemon: module.
Package re implements the re: module for using regular expressions.
Package re implements the re: module for using regular expressions.
Package types contains basic types for the Elvish runtime.
Package types contains basic types for the Elvish runtime.
Package vartypes contains basic types for manipulating Elvish variables.
Package vartypes contains basic types for manipulating Elvish variables.

Jump to

Keyboard shortcuts

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