eval

package
v7.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: BSD-3-Clause Imports: 29 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 (
	// 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 interface{})
	// BlackholeChan is channel writes onto which disappear, suitable for use as
	// placeholder channel output.
	BlackholeChan = make(chan interface{})
	// 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 (
	// NoArgs is an empty argument list. It can be used as an argument to Call.
	NoArgs = []interface{}{}
	// NoOpts is an empty option map. It can be used as an argument to Call.
	NoOpts = map[string]interface{}{}
)
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 ErrImpure = errors.New("expression is impure")
View Source
var ErrInterrupted = errors.New("interrupted")
View Source
var ErrMoreThanOneRest = errors.New("more than one @ lvalue")

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

View Source
var ErrNoOptAccepted = errors.New("no option accepted")
View Source
var ErrNotInSameGroup = errors.New("not in the same process group")
View Source
var ErrStoreNotConnected = errors.New("store 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 ComposeExceptionsFromPipeline

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

func EachExternal(f func(string))

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

func MakeVariableRef

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

MakeVariableRef builds a variable reference.

func NewExternalCmdExit

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

func ParseIncompleteVariableRef

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

ParseIncompleteVariableRef parses an incomplete variable reference.

func ParseVariableRef

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

ParseVariableRef parses a variable reference.

func PurelyEvalCompound

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

func RunTests

func RunTests(evalTests []Test, makeEvaler func() *Evaler) error

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

func SplitIncompleteVariableRef

func SplitIncompleteVariableRef(text string) (explodePart, nsPart, name string)

SplitIncompleteVariableRef splits an incomplete variable reference into three parts: an optional explode operator (either "" or "@"), a namespace part, and a name part.

func SplitVariableRef

func SplitVariableRef(text string) (explodePart, nsPart, name string)

SplitVariableRef splits a variable reference into three parts: an optional explode operator (either "" or "@"), a namespace part, and a name part.

func TakeNoOpt

func TakeNoOpt(opts map[string]interface{})

Types

type AddDirer

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 {
	// contains filtered or unexported fields
}

BuiltinFn uses reflection to wrap Go functions into Elvish functions. Functions with simple signatures are handled by commonCallable, more elaborate cases are handled by CustomCallable interface, e.g. when importing the necessary types would have created a dependency loop.

Parameters are converted using ScanToGo.

Return values go to the channel part of the stdout port, after being converted using goToElv. If the last return value has type error and is not nil, it is turned into an exception and no ouputting happens. If the last return value is a nil error, it is ignored.

Note: reflect.Call is deliberately not used as it disables DCE (see https://github.com/u-root/u-root/issues/1477).

func NewBuiltinFn

func NewBuiltinFn(name string, impl interface{}) *BuiltinFn

NewBuiltinFn creates a new ReflectBuiltinFn instance.

func NewBuiltinFnCustom

func NewBuiltinFnCustom(name string, impl CustomCallable) *BuiltinFn

NewBuiltinFnCustom creates a new ReflectBuiltinFn instance.

func (*BuiltinFn) Call

func (b *BuiltinFn) Call(f *Frame, args []interface{}, opts map[string]interface{}) error

Call calls the implementation using reflection.

func (*BuiltinFn) Equal

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

Equal compares identity.

func (*BuiltinFn) Hash

func (b *BuiltinFn) Hash() uint32

Hash hashes the address.

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 $name>".

type Callable

type Callable interface {
	// Call calls the receiver in a Frame with arguments and options.
	Call(fm *Frame, args []interface{}, opts map[string]interface{}) error
}

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 []interface{}
	Op          Op
	Captured    Ns
	SrcMeta     *Source
	DefBegint   int
	DefEnd      int
}

Closure is a closure defined in elvish script.

func (*Closure) Call

func (c *Closure) Call(fm *Frame, args []interface{}, opts map[string]interface{}) error

Call calls a closure.

func (*Closure) Equal

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

Equal compares by identity.

func (*Closure) Hash

func (c *Closure) Hash() uint32

func (*Closure) Index

func (c *Closure) Index(k interface{}) (interface{}, bool)

func (*Closure) IterateKeys

func (c *Closure) IterateKeys(f func(interface{}) bool)

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

type CompilationError struct {
	Message string
	Context util.SourceRange
}

CompilationError represents a compilation error and can pretty print it.

func (*CompilationError) Error

func (ce *CompilationError) Error() string

func (*CompilationError) Pprint

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

Pprint pretty-prints a compilation error.

type CustomCallable

type CustomCallable interface {
	// Target returns the callable's target function, needed to examine arguments.
	Target() interface{}
	// Call invokes the target function.
	Call(f *Frame, args []interface{}, opts RawOptions, inputs Inputs) ([]interface{}, error)
}

CustomCallable is an interface for functions that have complex signatures not covered by commonCallable.

type Editor

type Editor interface {
	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

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

func (envli *EnvList) Get() interface{}

Get returns a Value for an EnvPathList.

func (*EnvList) Set

func (envli *EnvList) Set(v interface{}) error

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

type Evaler

type Evaler struct {
	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) AddAfterChdir

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

AddAfterChdir adds a function to run after changing directory.

func (*Evaler) AddBeforeChdir

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

AddBeforeChdir adds a function to run before changing directory.

func (*Evaler) Chdir

func (ev *Evaler) Chdir(path string) 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 runs the functions in beforeChdir immediately before changing the directory, and the functions in afterChdir immediately after (if chdir was successful). It returns nil as long as the directory changing part succeeds.

func (*Evaler) Close

func (ev *Evaler) Close() error

Close releases resources allocated when creating this Evaler. Currently this does nothing and always returns a nil error.

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) EachNsInTop

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

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, ports []*Port, src *Source) error

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

func (*Evaler) EvalSource

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

EvalSource evaluates a chunk of Elvish source.

func (*Evaler) EvalWithStdPorts

func (ev *Evaler) EvalWithStdPorts(op Op, src *Source) error

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

func (*Evaler) InstallBundled

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

InstallBundled installs a bundled module to the Evaler.

func (*Evaler) InstallModule

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

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

func (*Evaler) PurelyEvalPartialCompound

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

func (*Evaler) PurelyEvalPrimary

func (ev *Evaler) PurelyEvalPrimary(pn *parse.Primary) interface{}

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

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

SetArgs sets the $args builtin variable.

func (*Evaler) SetLibDir

func (ev *Evaler) SetLibDir(libDir string)

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

func (*Evaler) SourceRC

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

SourceRC evaluates a rc.elv file. It evaluates the file in the global namespace. If the file defines a $-exports- map variable, the variable is removed and its content is poured into the global namespace, not overriding existing variables.

type Exception

type Exception struct {
	Cause     error
	Traceback *stackTrace
}

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

func (exc *Exception) Bool() bool

func (*Exception) Equal

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

Equal compares by identity.

func (*Exception) Error

func (exc *Exception) Error() string

func (*Exception) Hash

func (exc *Exception) Hash() uint32

func (*Exception) Index

func (exc *Exception) Index(k interface{}) (interface{}, bool)

func (*Exception) IterateKeys

func (exc *Exception) IterateKeys(f func(interface{}) bool)

func (*Exception) Kind

func (exc *Exception) Kind() string

func (*Exception) Pprint

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

func (*Exception) Repr

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(fm *Frame, argVals []interface{}, opts map[string]interface{}) error

Call calls an external command.

func (ExternalCmd) Equal

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

func (ExternalCmd) Hash

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

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

func (f Flow) Error() string

func (Flow) Pprint

func (f Flow) Pprint(string) string

func (Flow) Repr

func (f Flow) Repr(int) string

type Frame

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

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

NewTopFrame creates a top-level Frame.

func (*Frame) Call

func (fm *Frame) Call(f Callable, args []interface{}, opts map[string]interface{}) (err error)

Call calls a function with the given arguments and options. It does so in a protected environment so that exceptions thrown are wrapped in an Error.

func (*Frame) CallWithOutputCallback

func (fm *Frame) CallWithOutputCallback(fn Callable, args []interface{}, opts map[string]interface{}, valuesCb func(<-chan interface{}), bytesCb func(*os.File)) error

CallWithOutputCallback calls a function with the given arguments and options, feeding the outputs to the given callbacks. It does so in a protected environment so that exceptions thrown are wrapped in an Error.

func (*Frame) CaptureOutput

func (fm *Frame) CaptureOutput(fn Callable, args []interface{}, opts map[string]interface{}) (vs []interface{}, err error)

CaptureOutput calls a function with the given arguments and options, capturing and returning the output. It does so in a protected environment so that exceptions thrown are wrapped in an Error.

func (*Frame) Close

func (fm *Frame) Close() error

Close releases resources allocated for this frame. It always returns a nil error. It may be called only once.

func (Frame) EachNsInTop

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

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) Eval

func (fm *Frame) Eval(op Op) (err error)

Eval evaluates an op. It does so in a protected environment so that exceptions thrown are wrapped in an Error.

func (*Frame) ExecAndUnwrap

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

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

func (*Frame) InputChan

func (fm *Frame) InputChan() chan interface{}

InputChan returns a channel from which input can be read.

func (*Frame) InputFile

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

InputFile returns a file from which input can be read.

func (*Frame) Interrupts

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

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

func (*Frame) IsInterrupted

func (fm *Frame) IsInterrupted() bool

IsInterrupted reports whether there has been an interrupt.

func (*Frame) IterateInputs

func (fm *Frame) IterateInputs(f func(interface{}))

IterateInputs calls the passed function for each input element.

func (*Frame) OutputChan

func (fm *Frame) OutputChan() chan<- interface{}

OutputChan returns a channel onto which output can be written.

func (*Frame) OutputFile

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

OutputFile returns a file onto which output can be written.

func (*Frame) ResolveVar

func (fm *Frame) ResolveVar(n, name string) vars.Var

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

func (*Frame) Unwrap

func (ctx *Frame) Unwrap(desc string, begin, end int, vs []interface{}) ValuesUnwrapper

Unwrap creates an Unwrapper.

type GlobFlag

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

func (GlobFlag) Has

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) Concat

func (gp GlobPattern) Concat(v interface{}) (interface{}, error)

func (GlobPattern) Equal

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

func (GlobPattern) Hash

func (gp GlobPattern) Hash() uint32

func (GlobPattern) Index

func (gp GlobPattern) Index(k interface{}) (interface{}, error)

func (GlobPattern) Kind

func (GlobPattern) Kind() string

func (GlobPattern) RConcat

func (gp GlobPattern) RConcat(v interface{}) (interface{}, error)

func (GlobPattern) Repr

func (gp GlobPattern) Repr(int) string

type Inputs

type Inputs func(func(interface{}))

type LValuesOp

type LValuesOp struct {
	Body       LValuesOpBody
	Begin, End int
}

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

func (LValuesOp) Exec

func (op LValuesOp) Exec(fm *Frame) ([]vars.Var, error)

Exec executes an LValuesOp, producing Variable's.

type LValuesOpBody

type LValuesOpBody interface {
	Invoke(*Frame) ([]vars.Var, error)
}

LValuesOpBody is the body of an LValuesOp.

type Ns

type Ns map[string]vars.Var

Ns is a map from names to variables.

func NewNs

func NewNs() Ns

NewNs creates an empty namespace.

func (Ns) Add

func (ns Ns) Add(name string, v vars.Var) Ns

Add adds a variable to the namespace and returns the namespace itself.

func (Ns) AddBuiltinFn

func (ns Ns) AddBuiltinFn(nsName, name string, impl interface{}) Ns

AddBuiltinFn adds a builtin function to a namespace. It returns the namespace itself.

func (Ns) AddBuiltinFnCustom

func (ns Ns) AddBuiltinFnCustom(nsName, name string, impl CustomCallable) Ns

AddBuiltinFnCustom adds a builtin function to a namespace. It returns the namespace itself.

func (Ns) AddBuiltinFns

func (ns Ns) AddBuiltinFns(nsName string, fns map[string]interface{}) Ns

AddBuiltinFns adds builtin functions to a namespace. It returns the namespace itself.

func (Ns) AddFn

func (ns Ns) AddFn(name string, v Callable) Ns

AddFn adds a function to a namespace. It returns the namespace itself.

func (Ns) AddNs

func (ns Ns) AddNs(name string, v Ns) Ns

AddNs adds a sub-namespace to a namespace. It returns the namespace itself.

func (Ns) Clone

func (ns Ns) Clone() Ns

Clone returns a shallow copy of the namespace.

func (Ns) Equal

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

func (Ns) HasName

func (ns Ns) HasName(name string) bool

HasName reports the namespace contains the given name.

func (Ns) Hash

func (ns Ns) Hash() uint32

func (Ns) Index

func (ns Ns) Index(k interface{}) (interface{}, bool)

func (Ns) IterateKeys

func (ns Ns) IterateKeys(f func(interface{}) bool)

func (Ns) Kind

func (Ns) Kind() string

func (Ns) PopName

func (ns Ns) PopName(name string) vars.Var

PopName removes a name from the namespace and returns the variable it used to contain.

func (Ns) Repr

func (ns Ns) Repr(int) string

type Op

type Op struct {
	Body       OpBody
	Begin, End int
}

Op is an operation on an Frame.

func (Op) Exec

func (op Op) Exec(fm *Frame) error

Exec executes an Op.

type OpBody

type OpBody interface {
	Invoke(*Frame) error
}

OpBody is the body of an Op.

type PipelineError

type PipelineError struct {
	Errors []*Exception
}

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

func (PipelineError) Error

func (pe PipelineError) Error() string

func (PipelineError) Repr

func (pe PipelineError) Repr(indent int) string

type Port

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

func (PwdVariable) Set

func (pwd PwdVariable) Set(v interface{}) error

type RawOptions

type RawOptions map[string]interface{}

func (RawOptions) Scan

func (rawOpts RawOptions) Scan(ptr interface{})

Scan takes a pointer to a struct and scan options into it. A field named FieldName corresponds to the option named field-name, unless the field has a explicit "name" tag.

type Source

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

Source describes a piece of source code.

func NewInteractiveSource

func NewInteractiveSource(code string) *Source

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

func NewInternalSource

func NewInternalSource(name string) *Source

func NewModuleSource

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

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

func NewScriptSource

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

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

func (*Source) Equal

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

func (*Source) Hash

func (src *Source) Hash() uint32

func (*Source) Index

func (src *Source) Index(k interface{}) (interface{}, bool)

func (*Source) IterateKeys

func (src *Source) IterateKeys(f func(interface{}) bool)

func (*Source) Kind

func (src *Source) Kind() string

func (*Source) Repr

func (src *Source) Repr(int) string

type SrcType

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

func (t SrcType) String() string

type Test

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

Test is a test case for TestEval.

func That

func That(text string) Test

That returns a new Test with the specified source code.

func (Test) DoesNothing

func (t Test) DoesNothing() Test

DoesNothing returns t unchanged. It is used to mark that a piece of code should simply does nothing. In particular, it shouldn't have any output and does not error.

func (Test) Errors

func (t Test) Errors() Test

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

func (Test) ErrorsWith

func (t Test) ErrorsWith(err error) Test

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

func (Test) Prints

func (t Test) Prints(s string) Test

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

func (Test) Puts

func (t Test) Puts(vs ...interface{}) Test

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

func (Test) PutsStrings

func (t Test) PutsStrings(ss []string) Test

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

type ValueUnwrapper

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

ValueUnwrapper unwraps one Value.

func (ValueUnwrapper) Any

func (u ValueUnwrapper) Any() interface{}

func (ValueUnwrapper) Callable

func (u ValueUnwrapper) Callable() Callable

func (ValueUnwrapper) FdOrClose

func (u ValueUnwrapper) FdOrClose() int

func (ValueUnwrapper) Int

func (u ValueUnwrapper) Int() int

func (ValueUnwrapper) NonNegativeInt

func (u ValueUnwrapper) NonNegativeInt() int

func (ValueUnwrapper) String

func (u ValueUnwrapper) String() string

type ValuesOp

type ValuesOp struct {
	Body       ValuesOpBody
	Begin, End int
}

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

func (ValuesOp) Exec

func (op ValuesOp) Exec(fm *Frame) ([]interface{}, error)

Exec executes a ValuesOp and produces Value's.

type ValuesOpBody

type ValuesOpBody interface {
	Invoke(*Frame) ([]interface{}, error)
}

ValuesOpBody is the body of ValuesOp.

type ValuesUnwrapper

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

ValuesUnwrapper unwraps []Value.

func (ValuesUnwrapper) One

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 vals contains basic facilities for manipulating values used in the Elvish runtime.
Package vals contains basic facilities for manipulating values used in the Elvish runtime.
Package vars contains basic types for manipulating Elvish variables.
Package vars 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