bass

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2022 License: MIT Imports: 40 Imported by: 6

Documentation

Index

Constants

View Source
const TraceSize = 1000

Variables

Clock is used to determine the current time.

View Source
var ErrBadSyntax = errors.New("bad syntax")
View Source
var ErrEndOfSource = errors.New("end of source")
View Source
var ErrInterrupted = errors.New("interrupted")
View Source
var ErrNoRuntimePool = errors.New("runtime not initialized")

ErrNoRuntimePool is returned when the context.Context does not have a runtime pool set.

View Source
var Ground = NewEmptyScope()

Ground is the scope providing the standard library.

View Source
var Identity = Continue(func(v Value) Value {
	return v
})
View Source
var LinuxPlatform = Platform{
	OS: "linux",
}

LinuxPlatform is the minimum configuration to select a Linux runtime.

View Source
var Protocols = map[Symbol]Protocol{
	"raw":        RawProtocol{},
	"json":       JSONProtocol{},
	"unix-table": UnixTableProtocol{},
}

Protocols defines the set of supported protocols for reading responses.

View Source
var Secrets = NewEmptyScope()
View Source
var Stdin = &Source{
	NewJSONSource("stdin", os.Stdin),
}
View Source
var Stdout = &Sink{
	NewJSONSink("stdout", os.Stdout),
}

Functions

func BindConst

func BindConst(a, b Value) error

func CacheThunkPath

func CacheThunkPath(ctx context.Context, tp ThunkPath) (string, error)

CacheThunkPath exports a thunk path to a local cache under $XDG_CACHE_HOME.

If the path is a file, a path to the cached file will be returned.

If the path is a directory, a path to a cached directory containing its immediate files will be returned. Note that sub-directories are not recursively exported.

A cached directory will be marked as cached by placing a .cached file in it to distinguish from a directory created in order to export a child path.

It does not preserve things like file permissions and timestamps. It is only for accessing the content of files.

func DecodeProto

func DecodeProto(ctx context.Context, name Symbol, sink PipeSink, r io.Reader) error

DecodeProto uses the named protocol to decode values from r into the sink.

func Details

func Details(val Value) string

func Dump

func Dump(dst io.Writer, val any)

func Each

func Each(list List, cb func(Value) error) error

func EachBindingList

func EachBindingList(binding List, cb func(Symbol, Range) error) error

func EncodeList added in v0.5.0

func EncodeList(list List, enc zapcore.ArrayEncoder) error

func ForkTrace added in v0.5.0

func ForkTrace(ctx context.Context) context.Context

func IsApplicative

func IsApplicative(val Value) bool

IsApplicative returns true iff the value is an Applicative.

func IsList

func IsList(val Value) bool

func IsOperative

func IsOperative(val Value) bool

IsOperative returns true iff the value is an Operative or a Builtin operative.

func IsPathLike added in v0.5.0

func IsPathLike(arg string) bool

func Logger

func Logger() *zap.Logger

func LoggerTo

func LoggerTo(w io.Writer) *zap.Logger

func MarshalJSON

func MarshalJSON(val any) ([]byte, error)

func NewEncoder

func NewEncoder(w io.Writer) *json.Encoder

func NewError added in v0.5.0

func NewError(msg string, kv ...Value) error

func NewRawDecoder added in v0.5.0

func NewRawDecoder(r io.Reader) *json.Decoder

func PrintBindingDocs

func PrintBindingDocs(ctx context.Context, scope *Scope, form, val Value)

func RawUnmarshalJSON added in v0.5.0

func RawUnmarshalJSON(payload []byte, dest any) error

func RunMain

func RunMain(ctx context.Context, scope *Scope, args ...Value) error

func UnmarshalJSON

func UnmarshalJSON(payload []byte, dest any) error

func WithRuntimePool

func WithRuntimePool(ctx context.Context, pool RuntimePool) context.Context

func WithTrace

func WithTrace(ctx context.Context, trace *Trace) context.Context

Types

type Annotate

type Annotate struct {
	// Value the inner form whose value will be annotated.
	Value

	// Range is the source code location of the inner form.
	Range Range

	// Comment is a literal comment ahead of or following the inner form.
	Comment string

	// Meta is an optional binding form that will be evaluated to attach metadata
	// to the inner form's value.
	Meta *Bind
}

func Caller

func Caller(ctx context.Context, offset int) Annotate

func (Annotate) Decode

func (value Annotate) Decode(dest any) error

func (Annotate) Eval

func (value Annotate) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

func (Annotate) MarshalJSON

func (value Annotate) MarshalJSON() ([]byte, error)

func (Annotate) MetaBind

func (value Annotate) MetaBind() Bind

func (Annotate) String

func (value Annotate) String() string

type AnnotateBinding

type AnnotateBinding struct {
	Bindable
	Range    Range
	MetaBind Bind
}

func (AnnotateBinding) Bind

func (binding AnnotateBinding) Bind(ctx context.Context, scope *Scope, cont Cont, val Value, doc ...Annotated) ReadyCont

func (AnnotateBinding) Decode

func (value AnnotateBinding) Decode(dest any) error

func (AnnotateBinding) EachBinding

func (binding AnnotateBinding) EachBinding(cb func(Symbol, Range) error) error

type Annotated

type Annotated struct {
	// Value is the inner value.
	Value

	// Meta contains metadata about the inner value.
	Meta *Scope
}

func (Annotated) Decode

func (value Annotated) Decode(dest any) error

func (Annotated) MarshalJSON

func (value Annotated) MarshalJSON() ([]byte, error)

type Applicative

type Applicative interface {
	Combiner

	Unwrap() Combiner
}

func Wrap

func Wrap(comb Combiner) Applicative

type ArityError

type ArityError struct {
	Name     string
	Need     int
	Variadic bool
	Have     int
}

func (ArityError) Error

func (err ArityError) Error() string

type Bind

type Bind []Value

func (Bind) Bind added in v0.5.0

func (bind Bind) Bind(ctx context.Context, bindScope *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (Bind) Decode

func (value Bind) Decode(dest any) error

func (Bind) EachBinding added in v0.5.0

func (bind Bind) EachBinding(cb func(Symbol, Range) error) error

func (Bind) Equal

func (value Bind) Equal(ovalue Value) bool

func (Bind) Eval

func (value Bind) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

func (Bind) MarshalJSON

func (value Bind) MarshalJSON() ([]byte, error)

func (Bind) String

func (value Bind) String() string

type BindMismatchError

type BindMismatchError struct {
	Need Value
	Have Value
}

func (BindMismatchError) Error

func (err BindMismatchError) Error() string

type Bindable

type Bindable interface {
	Value

	// Bind assigns values to symbols in the given scope.
	Bind(context.Context, *Scope, Cont, Value, ...Annotated) ReadyCont

	// EachBinding calls the fn for each symbol that will be bound.
	EachBinding(func(Symbol, Range) error) error
}

Bindable is any value which may be used to destructure a value into bindings in a scope.

type Bindings

type Bindings map[Symbol]Value

Bindings maps Symbols to Values in a scope.

func (Bindings) Scope

func (bindings Bindings) Scope(parents ...*Scope) *Scope

NewScope constructs a new *Scope with initial bindings.

type Bool

type Bool bool

func (Bool) Bind

func (binding Bool) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (Bool) Decode

func (value Bool) Decode(dest any) error

func (Bool) EachBinding

func (Bool) EachBinding(func(Symbol, Range) error) error

func (Bool) Equal

func (value Bool) Equal(other Value) bool

func (Bool) Eval

func (value Bool) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Bool) String

func (value Bool) String() string

type Builtin

type Builtin struct {
	Name      string
	Formals   Value
	Func      reflect.Value
	Operative bool
}

func Op

func Op(name, signature string, f any) *Builtin

func (Builtin) Call

func (builtin Builtin) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (*Builtin) Decode

func (value *Builtin) Decode(dest any) error

func (*Builtin) Equal

func (value *Builtin) Equal(other Value) bool

func (*Builtin) Eval

func (value *Builtin) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*Builtin) MarshalJSON

func (value *Builtin) MarshalJSON() ([]byte, error)

func (*Builtin) String

func (value *Builtin) String() string

type CannotBindError

type CannotBindError struct {
	Have Value
}

func (CannotBindError) Error

func (err CannotBindError) Error() string

type Combiner

type Combiner interface {
	Value

	Call(context.Context, Value, *Scope, Cont) ReadyCont
}

func Func

func Func(name, formals string, f any) Combiner

type CommandPath

type CommandPath struct {
	Command string `json:"command"`
}

CommandPath represents a command path in an abstract runtime environment, typically resolved by consulting $PATH.

func (CommandPath) Bind

func (binding CommandPath) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (CommandPath) Call

func (combiner CommandPath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (CommandPath) Decode

func (value CommandPath) Decode(dest any) error

func (CommandPath) EachBinding

func (CommandPath) EachBinding(func(Symbol, Range) error) error

func (CommandPath) Equal

func (value CommandPath) Equal(other Value) bool

func (CommandPath) Eval

func (value CommandPath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (CommandPath) Extend

func (path CommandPath) Extend(ext Path) (Path, error)

func (*CommandPath) FromValue

func (value *CommandPath) FromValue(val Value) error

func (CommandPath) Name

func (value CommandPath) Name() string

func (CommandPath) String

func (value CommandPath) String() string

func (CommandPath) Unwrap

func (app CommandPath) Unwrap() Combiner

type CompleteOpt

type CompleteOpt struct {
	Binding Symbol
	Value   Annotated
}

type CompleteOpts

type CompleteOpts []CompleteOpt

func (CompleteOpts) Len

func (opts CompleteOpts) Len() int

func (CompleteOpts) Less

func (opts CompleteOpts) Less(i, j int) bool

func (CompleteOpts) Swap

func (opts CompleteOpts) Swap(i, j int)

type Config

type Config struct {
	Runtimes []RuntimeConfig `json:"runtimes"`
}

Config is set by the user and read by the Bass language and runtimes which run on the same machine.

func LoadConfig

func LoadConfig(defaultConfig Config) (*Config, error)

LoadConfig loads a Config from the JSON file at the given path.

type Cons

type Cons Pair

func (Cons) Bind

func (binding Cons) Bind(ctx context.Context, scope *Scope, cont Cont, value Value, _ ...Annotated) ReadyCont

func (Cons) Decode

func (value Cons) Decode(dest any) error

func (Cons) EachBinding

func (binding Cons) EachBinding(cb func(Symbol, Range) error) error

func (Cons) Equal

func (value Cons) Equal(other Value) bool

func (Cons) Eval

func (value Cons) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

Eval evaluates both values in the pair.

func (Cons) First

func (value Cons) First() Value

func (Cons) MarshalJSON

func (value Cons) MarshalJSON() ([]byte, error)

func (Cons) MarshalLogArray added in v0.5.0

func (cons Cons) MarshalLogArray(enc zapcore.ArrayEncoder) error

func (Cons) Rest

func (value Cons) Rest() Value

func (Cons) String

func (value Cons) String() string

type Cont

type Cont interface {
	Value

	Call(Value, error) ReadyCont
	Traced(*Trace) Cont
}

func Continue

func Continue(cont func(Value) Value) Cont

func WithFrame

func WithFrame(ctx context.Context, frame *Annotate, cont Cont) Cont

type Continuation

type Continuation struct {
	Continue    func(Value) Value
	Trace       *Trace
	TracedDepth int
}

func (*Continuation) Call

func (cont *Continuation) Call(res Value, err error) ReadyCont

func (*Continuation) Decode

func (value *Continuation) Decode(dest any) error

func (*Continuation) Equal

func (value *Continuation) Equal(other Value) bool

func (*Continuation) Eval

func (value *Continuation) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*Continuation) MarshalJSON

func (value *Continuation) MarshalJSON() ([]byte, error)

func (*Continuation) String

func (value *Continuation) String() string

func (*Continuation) Traced

func (value *Continuation) Traced(trace *Trace) Cont

type CrossSource added in v0.5.0

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

func (*CrossSource) Next added in v0.5.0

func (cross *CrossSource) Next(ctx context.Context) (Value, error)

func (*CrossSource) String added in v0.5.0

func (cross *CrossSource) String() string

type Decodable

type Decodable interface {
	FromValue(Value) error
}

Decodable types typically implement json.Unmarshaler as well.

type DecodeError

type DecodeError struct {
	Source      any
	Destination any
}

func (DecodeError) Error

func (err DecodeError) Error() string

type Decoder added in v0.5.0

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

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode added in v0.5.0

func (dec *Decoder) Decode(dest any) error

type DirPath

type DirPath struct {
	Path string `json:"dir"`
}

DirPath represents a directory path in an abstract filesystem.

Its interpretation is context-dependent; it may refer to a path in a runtime environment, or a path on the local machine.

func (DirPath) Bind

func (binding DirPath) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (DirPath) Call

func (combiner DirPath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (DirPath) Decode

func (value DirPath) Decode(dest any) error

func (DirPath) Dir

func (value DirPath) Dir() DirPath

func (DirPath) EachBinding

func (DirPath) EachBinding(func(Symbol, Range) error) error

func (DirPath) Equal

func (value DirPath) Equal(other Value) bool

func (DirPath) Eval

func (value DirPath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (DirPath) Extend

func (dir DirPath) Extend(ext Path) (Path, error)

func (DirPath) FromSlash

func (value DirPath) FromSlash() string

func (*DirPath) FromValue

func (value *DirPath) FromValue(val Value) error

func (DirPath) IsDir

func (value DirPath) IsDir() bool

func (DirPath) Name

func (value DirPath) Name() string

func (DirPath) String

func (value DirPath) String() string

func (DirPath) Unwrap

func (combiner DirPath) Unwrap() Combiner

type Empty

type Empty struct{}

func (Empty) Bind

func (binding Empty) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (Empty) Decode

func (value Empty) Decode(dest any) error

func (Empty) EachBinding

func (Empty) EachBinding(func(Symbol, Range) error) error

func (Empty) Equal

func (Empty) Equal(other Value) bool

func (Empty) Eval

func (value Empty) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Empty) First

func (Empty) First() Value

func (Empty) MarshalJSON

func (Empty) MarshalJSON() ([]byte, error)

func (Empty) MarshalLogArray added in v0.5.0

func (Empty) MarshalLogArray(enc zapcore.ArrayEncoder) error

func (Empty) Rest

func (Empty) Rest() Value

func (Empty) String

func (Empty) String() string

func (*Empty) UnmarshalJSON

func (*Empty) UnmarshalJSON(payload []byte) error

type Encodable

type Encodable interface {
	ToValue() Value
}

Encodable types typically implement json.Marshaler as well.

type EncodeError

type EncodeError struct {
	Value Value
}

func (EncodeError) Error

func (err EncodeError) Error() string

type ExtendError

type ExtendError struct {
	Parent Path
	Child  Path
}

func (ExtendError) Error

func (err ExtendError) Error() string

type ExtendOperative

type ExtendOperative struct {
	Path Path
}

ExtendOperative is an operative which constructs a Extend.

func (ExtendOperative) Call

func (op ExtendOperative) Call(_ context.Context, val Value, _ *Scope, cont Cont) ReadyCont

Call constructs a thunk, passing arguments as values on stdin.

func (ExtendOperative) Decode

func (value ExtendOperative) Decode(dest any) error

func (ExtendOperative) Equal

func (value ExtendOperative) Equal(other Value) bool

func (ExtendOperative) Eval

func (value ExtendOperative) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (ExtendOperative) String

func (value ExtendOperative) String() string

type ExtendPath

type ExtendPath struct {
	Parent Value
	Child  FilesystemPath
}

ExtendPath extends a parent path expression with a child path.

func (ExtendPath) Bind

func (binding ExtendPath) Bind(ctx context.Context, scope *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (ExtendPath) Decode

func (value ExtendPath) Decode(dest any) error

func (ExtendPath) EachBinding

func (ExtendPath) EachBinding(func(Symbol, Range) error) error

func (ExtendPath) Equal

func (value ExtendPath) Equal(other Value) bool

func (ExtendPath) Eval

func (value ExtendPath) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

Eval evaluates the Parent value into a Path and extends it with Child.

func (ExtendPath) String

func (value ExtendPath) String() string

type FSPath

type FSPath struct {
	ID   string        `json:"fs"`
	FS   fs.FS         `json:"-"`
	Path FileOrDirPath `json:"path"`
}

FSPath is a Path representing a file or directory relative to a filesystem.

This type will typically never occur in production code. It is only used for embedded filesystems, i.e. in Bass's stdlib and test suites.

JSON tags are specified just for keeping up appearances - this type needs to be marshalable just to support .SHA256, .Name, .Avatar, etc. on a Thunk that embeds it.

func NewFSDir

func NewFSDir(id string, fs fs.FS) FSPath

func NewFSPath

func NewFSPath(id string, fs fs.FS, path FileOrDirPath) FSPath

func NewInMemoryFSDir

func NewInMemoryFSDir(fileContentPairs ...Value) (FSPath, error)

NewInMemoryFSDir is exposed as (mkfs) - it takes alternating file paths and content and constructs an in-memory filesystem path.

func (FSPath) Call

func (combiner FSPath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (FSPath) Decode

func (value FSPath) Decode(dest any) error

func (FSPath) Equal

func (value FSPath) Equal(other Value) bool

func (FSPath) Eval

func (value FSPath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (FSPath) Extend

func (path FSPath) Extend(ext Path) (Path, error)

func (FSPath) Name

func (path FSPath) Name() string

func (FSPath) String

func (value FSPath) String() string

func (FSPath) Unwrap

func (app FSPath) Unwrap() Combiner

type FileOrDirPath

type FileOrDirPath struct {
	File *FilePath
	Dir  *DirPath
}

FileOrDirPath is an enum type that accepts a FilePath or a DirPath.

func NewFileOrDirPath

func NewFileOrDirPath(path FilesystemPath) FileOrDirPath

func ParseFileOrDirPath

func ParseFileOrDirPath(arg string) FileOrDirPath

ParseFileOrDirPath parses arg as a path using the host machine's separator convention.

If the path is '.' or has a trailing slash, a DirPath is returned.

Otherwise, a FilePath is returned.

func (FileOrDirPath) Extend

func (path FileOrDirPath) Extend(ext Path) (FileOrDirPath, error)

Extend extends the value with the given path and returns it wrapped in another FileOrDirPath.

func (FileOrDirPath) FilesystemPath

func (path FileOrDirPath) FilesystemPath() FilesystemPath

FilesystemPath returns the value present.

func (*FileOrDirPath) FromValue

func (path *FileOrDirPath) FromValue(val Value) error

FromValue decodes val into a FilePath or a DirPath, setting whichever worked as the internal value.

func (FileOrDirPath) MarshalJSON

func (path FileOrDirPath) MarshalJSON() ([]byte, error)

func (FileOrDirPath) String

func (path FileOrDirPath) String() string

String calls String on whichever value is present.

func (FileOrDirPath) ToValue

func (path FileOrDirPath) ToValue() Value

ToValue returns the value present.

func (*FileOrDirPath) UnmarshalJSON

func (path *FileOrDirPath) UnmarshalJSON(payload []byte) error

UnmarshalJSON unmarshals a FilePath or DirPath from JSON.

type FilePath

type FilePath struct {
	Path string `json:"file"`
}

FilePath represents a file path in an abstract filesystem.

Its interpretation is context-dependent; it may refer to a path in a runtime environment, or a path on the local machine.

func (FilePath) Bind

func (binding FilePath) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (FilePath) Call

func (combiner FilePath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (FilePath) Decode

func (value FilePath) Decode(dest any) error

func (FilePath) Dir

func (value FilePath) Dir() DirPath

func (FilePath) EachBinding

func (FilePath) EachBinding(func(Symbol, Range) error) error

func (FilePath) Equal

func (value FilePath) Equal(other Value) bool

func (FilePath) Eval

func (value FilePath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (FilePath) Extend

func (path_ FilePath) Extend(ext Path) (Path, error)

func (FilePath) FileOrDir

func (app FilePath) FileOrDir() FileOrDirPath

func (FilePath) FromSlash

func (value FilePath) FromSlash() string

func (*FilePath) FromValue

func (value *FilePath) FromValue(val Value) error

func (FilePath) IsDir

func (value FilePath) IsDir() bool

func (FilePath) Name

func (value FilePath) Name() string

func (FilePath) String

func (value FilePath) String() string

func (FilePath) Unwrap

func (app FilePath) Unwrap() Combiner

type FilesystemPath

type FilesystemPath interface {
	Path

	// FromSlash uses filepath.FromSlash to convert the path to host machine's
	// path separators.
	FromSlash() string

	// IsDir returns true if the path refers to a directory.
	IsDir() bool

	// Dir returns the parent directory of the path, or the same directory if
	// there is no parent.
	Dir() DirPath
}

FilesystemPath is a Path representing a file or directory in a filesystem.

type FlagError added in v0.1.1

type FlagError struct {
	Err   error
	Flags *pflag.FlagSet
}

func (FlagError) Error added in v0.1.1

func (err FlagError) Error() string

func (FlagError) NiceError added in v0.1.1

func (err FlagError) NiceError(w io.Writer) error

type FormAnalyzer

type FormAnalyzer interface {
	Analyze(context.Context, Annotate)
}

type HostPath

type HostPath struct {
	ContextDir string        `json:"context"`
	Path       FileOrDirPath `json:"path"`
}

HostPath is a Path representing an absolute path on the host machine's filesystem.

func NewHostDir

func NewHostDir(contextDir string) HostPath

func NewHostPath

func NewHostPath(contextDir string, path FileOrDirPath) HostPath

func (HostPath) Call

func (combiner HostPath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (HostPath) Decode

func (value HostPath) Decode(dest any) error

func (HostPath) Equal

func (value HostPath) Equal(other Value) bool

func (HostPath) Eval

func (value HostPath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (HostPath) Extend

func (path HostPath) Extend(ext Path) (Path, error)

func (HostPath) FromSlash

func (hp HostPath) FromSlash() string

func (*HostPath) FromValue

func (value *HostPath) FromValue(val Value) error

func (HostPath) Name

func (path HostPath) Name() string

func (HostPath) String

func (value HostPath) String() string

func (HostPath) Unwrap

func (app HostPath) Unwrap() Combiner

type Ignore

type Ignore struct{}

func (Ignore) Bind

func (Ignore) Bind(_ context.Context, _ *Scope, cont Cont, _ Value, _ ...Annotated) ReadyCont

func (Ignore) Decode

func (value Ignore) Decode(dest any) error

func (Ignore) EachBinding

func (Ignore) EachBinding(func(Symbol, Range) error) error

func (Ignore) Equal

func (Ignore) Equal(other Value) bool

func (Ignore) Eval

func (value Ignore) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (Ignore) String

func (Ignore) String() string

type InMemoryFS

type InMemoryFS map[string]string

InMemoryFS is a stupid simple filesystem representation, not even concerning itself with pesky permissions and timestamps.

It maps cleaned file paths to their content. It does not contain empty directories, but its file paths may be nested.

func (InMemoryFS) Open

func (inmem InMemoryFS) Open(name string) (fs.File, error)

Opens returns a file for reading the given file's content or errors if the file does not exist.

The returned file always has 0644 permissions and a zero (Unix epoch) mtime.

func (InMemoryFS) SHA256

func (inmem InMemoryFS) SHA256() (string, error)

SHA256 returns a checksum of the filesystem.

type InMemorySink

type InMemorySink struct {
	Values []Value
}

func NewInMemorySink

func NewInMemorySink() *InMemorySink

func (*InMemorySink) Emit

func (src *InMemorySink) Emit(val Value) error

func (*InMemorySink) Reset

func (sink *InMemorySink) Reset()

func (*InMemorySink) Source

func (sink *InMemorySink) Source() PipeSource

func (*InMemorySink) String

func (src *InMemorySink) String() string

type InMemorySource

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

func NewInMemorySource

func NewInMemorySource(vals ...Value) *InMemorySource

func (*InMemorySource) Next

func (src *InMemorySource) Next(_ context.Context) (Value, error)

func (*InMemorySource) String

func (src *InMemorySource) String() string

type Int

type Int int

func (Int) Bind

func (binding Int) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (Int) Decode

func (value Int) Decode(dest any) error

func (Int) EachBinding

func (Int) EachBinding(func(Symbol, Range) error) error

func (Int) Equal

func (value Int) Equal(other Value) bool

func (Int) Eval

func (value Int) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Int) String

func (value Int) String() string

type JSONProtocol

type JSONProtocol struct{}

JSON protocol decodes a values from JSON stream.

func (JSONProtocol) DecodeInto

func (JSONProtocol) DecodeInto(ctx context.Context, sink PipeSink, r io.Reader) error

DecodeInto decodes a JSON stream from r and emits values to the sink.

type JSONSink

type JSONSink struct {
	Name string
	// contains filtered or unexported fields
}

func NewJSONSink

func NewJSONSink(name string, out io.Writer) *JSONSink

func (*JSONSink) Emit

func (sink *JSONSink) Emit(val Value) error

func (*JSONSink) String

func (sink *JSONSink) String() string

type JSONSource

type JSONSource struct {
	Name string
	// contains filtered or unexported fields
}

func NewJSONSource

func NewJSONSource(name string, in io.Reader) *JSONSource

func (*JSONSource) Next

func (source *JSONSource) Next(context.Context) (Value, error)

func (*JSONSource) String

func (source *JSONSource) String() string

type Keyword

type Keyword string

func (Keyword) Bind

func (binding Keyword) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (Keyword) Decode

func (value Keyword) Decode(dest any) error

func (Keyword) EachBinding

func (Keyword) EachBinding(func(Symbol, Range) error) error

func (Keyword) Equal

func (value Keyword) Equal(other Value) bool

func (Keyword) Eval

func (value Keyword) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval converts the Keyword to a Symbol.

func (Keyword) String

func (value Keyword) String() string

func (Keyword) Symbol

func (value Keyword) Symbol() Symbol

type List

type List interface {
	Value
	Bindable

	First() Value
	Rest() Value
}

func NewConsList

func NewConsList(vals ...Value) List

func NewList

func NewList(vals ...Value) List

func ToCons

func ToCons(list List) List

type Lockfile

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

func NewLockfileMemo

func NewLockfileMemo(path string) *Lockfile

func (*Lockfile) Remove

func (file *Lockfile) Remove(thunk Thunk, binding Symbol, input Value) error

func (*Lockfile) Retrieve

func (file *Lockfile) Retrieve(thunk Thunk, binding Symbol, input Value) (Value, bool, error)

func (*Lockfile) Store

func (file *Lockfile) Store(thunk Thunk, binding Symbol, input Value, output Value) error

type LockfileContent

type LockfileContent struct {
	Data   MemoData         `json:"memo"`
	Thunks map[string]Thunk `json:"thunks"`
}

type MemoData added in v0.5.0

type MemoData map[string][]Memory

type Memory

type Memory struct {
	Input  ValueJSON `json:"input"`
	Output ValueJSON `json:"output"`
}

type Memos

type Memos interface {
	Store(Thunk, Symbol, Value, Value) error
	Retrieve(Thunk, Symbol, Value) (Value, bool, error)
	Remove(Thunk, Symbol, Value) error
}

Memos is where memoized calls are cached.

func OpenFSPathMemos

func OpenFSPathMemos(fsPath FSPath) (Memos, error)

func OpenHostPathMemos

func OpenHostPathMemos(hostPath HostPath) Memos

func OpenMemos

func OpenMemos(ctx context.Context, dir Path) (Memos, error)

func OpenThunkPathMemos

func OpenThunkPathMemos(ctx context.Context, thunkPath ThunkPath) (Memos, error)

type NiceError

type NiceError interface {
	error

	NiceError(io.Writer) error
}

NiceError is an error that is able to provide some extra guidance to the user.

Strive for all errors returned by Bass to become a NiceError.

type NoopMemos

type NoopMemos struct{}

func (NoopMemos) Remove

func (NoopMemos) Remove(Thunk, Symbol, Value) error

func (NoopMemos) Retrieve

func (NoopMemos) Retrieve(Thunk, Symbol, Value) (Value, bool, error)

func (NoopMemos) Store

func (NoopMemos) Store(Thunk, Symbol, Value, Value) error

type Null

type Null struct{}

func (Null) Bind

func (binding Null) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (Null) Decode

func (value Null) Decode(dest any) error

Decode decodes into a Null or into bool (setting false).

func (Null) EachBinding

func (Null) EachBinding(func(Symbol, Range) error) error

func (Null) Equal

func (Null) Equal(other Value) bool

func (Null) Eval

func (value Null) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Null) MarshalJSON

func (Null) MarshalJSON() ([]byte, error)

MarshalJSON marshals as `null`.

func (Null) String

func (Null) String() string

type Operative

type Operative struct {
	Bindings     Bindable
	ScopeBinding Bindable
	Body         Value
	StaticScope  *Scope
}

func (*Operative) Call

func (combiner *Operative) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (*Operative) Decode

func (value *Operative) Decode(dest any) error

func (*Operative) Equal

func (value *Operative) Equal(other Value) bool

func (*Operative) Eval

func (value *Operative) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*Operative) MarshalJSON

func (value *Operative) MarshalJSON() ([]byte, error)

func (*Operative) String

func (value *Operative) String() string

type Pair

type Pair struct {
	A Value
	D Value
}

func (Pair) Bind

func (binding Pair) Bind(ctx context.Context, scope *Scope, cont Cont, value Value, _ ...Annotated) ReadyCont

func (Pair) Decode

func (value Pair) Decode(dest any) error

func (Pair) EachBinding

func (binding Pair) EachBinding(cb func(Symbol, Range) error) error

func (Pair) Equal

func (value Pair) Equal(other Value) bool

func (Pair) Eval

func (value Pair) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

Pair combines the first operand with the second operand.

If the first value is not a Combiner, an error is returned.

func (Pair) First

func (value Pair) First() Value

func (Pair) MarshalJSON

func (value Pair) MarshalJSON() ([]byte, error)

func (Pair) MarshalLogArray added in v0.5.0

func (pair Pair) MarshalLogArray(enc zapcore.ArrayEncoder) error

func (Pair) Rest

func (value Pair) Rest() Value

func (Pair) String

func (value Pair) String() string

func (*Pair) UnmarshalJSON

func (value *Pair) UnmarshalJSON(payload []byte) error

type Path

type Path interface {
	// All Paths are Values.
	Value

	// Name returns the unqualified name for the path, i.e. the base name of a
	// file or directory, or the name of a command.
	Name() string

	// Extend returns a path referring to the given path relative to the parent
	// Path.
	Extend(Path) (Path, error)
}

Path is an abstract location identifier for files, directories, or executable commands.

type PipeSink

type PipeSink interface {
	String() string
	Emit(Value) error
}

type PipeSource

type PipeSource interface {
	String() string
	Next(context.Context) (Value, error)
}

type Platform

type Platform struct {
	OS   string `json:"os"`
	Arch string `json:"arch,omitempty"`
}

Platform configures an OCI image platform.

func (Platform) CanSelect

func (platform Platform) CanSelect(given Platform) bool

CanSelect returns true if the given platform (from a runtime) matches.

func (Platform) String

func (platform Platform) String() string

type Protocol

type Protocol interface {
	// DecodeInto decodes values from the reader and emits them to the sink.
	DecodeInto(context.Context, PipeSink, io.Reader) error
}

Protocol determines how response data is parsed from a thunk's response.

type PruneOpts

type PruneOpts struct {
	// Prune everything.
	All bool

	// Keep data last used within the duration.
	KeepDuration time.Duration

	// Keep
	KeepBytes int64
}

PruneOpts contains parameters to fine-tune the pruning behavior. These parameters are best-effort; not all runtimes are expected to support every option.

type Range

type Range struct {
	Start, End reader.Position
}

func (*Range) FromMeta

func (r *Range) FromMeta(meta *Scope) error

func (Range) IsWithin

func (inner Range) IsWithin(outer Range) bool

func (Range) String

func (r Range) String() string

func (Range) ToMeta

func (r Range) ToMeta(meta *Scope)

type RawProtocol

type RawProtocol struct{}

Raw protocol buffers the entire stream and writes it as a single JSON string on flush.

func (RawProtocol) DecodeInto

func (RawProtocol) DecodeInto(ctx context.Context, sink PipeSink, r io.Reader) error

DecodeInto reads the full content from r and emits it to the sink as a one big string.

type ReadError

type ReadError struct {
	Err   reader.Error
	Range Range
}

ReadError is returned when the reader trips on a syntax token.

func (ReadError) Error

func (err ReadError) Error() string

func (ReadError) Unwrap added in v0.4.0

func (err ReadError) Unwrap() error

type Readable

type Readable interface {
	Value

	Open(context.Context) (io.ReadCloser, error)
}

Readable is any Value that can be (read).

type Reader

type Reader struct {
	Analyzer FormAnalyzer
	Context  context.Context
	// contains filtered or unexported fields
}

func NewReader

func NewReader(src io.Reader, name ...string) *Reader

func (*Reader) Next

func (reader *Reader) Next() (Value, error)

type ReadonlyMemos

type ReadonlyMemos struct {
	Content LockfileContent
}

func (ReadonlyMemos) Remove

func (file ReadonlyMemos) Remove(thunk Thunk, binding Symbol, input Value) error

func (ReadonlyMemos) Retrieve

func (file ReadonlyMemos) Retrieve(thunk Thunk, binding Symbol, input Value) (Value, bool, error)

func (ReadonlyMemos) Store

func (file ReadonlyMemos) Store(thunk Thunk, binding Symbol, input Value, output Value) error

type ReadyCont

type ReadyCont interface {
	Value

	Go() (Value, error)
}

func BindList

func BindList(ctx context.Context, scope *Scope, cont Cont, binding List, value Value) ReadyCont

func EvalPair

func EvalPair(ctx context.Context, scope *Scope, pair Pair, cont Cont) ReadyCont

func PrintDocs

func PrintDocs(ctx context.Context, cont Cont, scope *Scope, forms ...Value) ReadyCont

type ReadyContinuation

type ReadyContinuation struct {
	Cont *Continuation

	Result Value
	Err    error
}

func (*ReadyContinuation) Decode

func (value *ReadyContinuation) Decode(dest any) error

func (*ReadyContinuation) Equal

func (value *ReadyContinuation) Equal(other Value) bool

func (*ReadyContinuation) Eval

func (value *ReadyContinuation) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*ReadyContinuation) Go

func (cont *ReadyContinuation) Go() (Value, error)

func (*ReadyContinuation) MarshalJSON

func (value *ReadyContinuation) MarshalJSON() ([]byte, error)

func (*ReadyContinuation) String

func (cont *ReadyContinuation) String() string

type Runtime

func RuntimeFromContext

func RuntimeFromContext(ctx context.Context, platform *Platform) (Runtime, error)

type RuntimeConfig

type RuntimeConfig struct {
	Platform Platform `json:"platform"`
	Runtime  string   `json:"runtime"`
	Config   *Scope   `json:"config,omitempty"`
}

RuntimeConfig associates a platform object to a runtime command to run.

Additional configuration may be specified; it will be read from the runtime by finding the config associated to the platform on the thunk it receives.

type RuntimePool

type RuntimePool interface {
	Select(*Platform) (Runtime, error)
	All() []Runtime
}

func RuntimePoolFromContext

func RuntimePoolFromContext(ctx context.Context) (RuntimePool, error)

type Scope

type Scope struct {
	// an optional name for the scope, used to prettify .String on 'standard'
	// environments
	Name string

	Parents  []*Scope
	Bindings Bindings
	Order    []Symbol
	// contains filtered or unexported fields
}

Scope contains bindings from symbols to values, and parent scopes to delegate to during symbol lookup.

func Assoc added in v0.5.0

func Assoc(obj *Scope, kv ...Value) (*Scope, error)

func ImportSystemEnv

func ImportSystemEnv() *Scope

ImportSystemEnv converts the system env into a scope, clearing the system env in the process. This is a destructive operation.

func NewEmptyScope

func NewEmptyScope(parents ...*Scope) *Scope

NewEmptyScope constructs a new scope with no bindings and optional parents.

func NewScope

func NewScope(bindings Bindings, parents ...*Scope) *Scope

NewScope constructs a new scope with the given bindings and optional parents.

func NewStandardScope

func NewStandardScope() *Scope

NewStandardScope returns a new empty scope with Ground as its sole parent.

func (*Scope) Complete

func (scope *Scope) Complete(prefix string) []CompleteOpt

Complete queries the scope for bindings beginning with the given prefix.

Local bindings are listed before parent bindings, with shorter binding names listed first.

func (*Scope) Copy

func (value *Scope) Copy() *Scope

func (*Scope) Decode

func (value *Scope) Decode(dest any) error

func (*Scope) Each

func (value *Scope) Each(f func(Symbol, Value) error) error

Reduce calls f for each binding-value pair mapped by the scope.

Note that shadowed bindings will be skipped.

func (*Scope) Equal

func (value *Scope) Equal(o Value) bool

func (*Scope) Eval

func (value *Scope) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (*Scope) Get

func (scope *Scope) Get(binding Symbol) (Value, bool)

Get fetches the given binding.

If a value is set in the local bindings, it is returned.

If not, the parent scopes are queried in order.

If no value is found, false is returned.

func (*Scope) GetDecode

func (scope *Scope) GetDecode(binding Symbol, dest any) error

GetDecode fetches the given binding and Decodes its value.

func (*Scope) IsEmpty

func (value *Scope) IsEmpty() bool

func (*Scope) IsSubsetOf

func (value *Scope) IsSubsetOf(other *Scope) bool

func (*Scope) MarshalJSON

func (value *Scope) MarshalJSON() ([]byte, error)

func (*Scope) MarshalLogObject added in v0.5.0

func (scope *Scope) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*Scope) Set

func (scope *Scope) Set(binding Symbol, value Value, docs ...string)

Set assigns the value in the local bindings.

func (*Scope) String

func (value *Scope) String() string

func (*Scope) UnmarshalJSON

func (value *Scope) UnmarshalJSON(payload []byte) error

type Secret

type Secret struct {
	Name string `json:"secret"`
	// contains filtered or unexported fields
}

func NewSecret

func NewSecret(name string, inner []byte) Secret

func (Secret) Decode

func (value Secret) Decode(dest any) error

Decode only supports decoding into a Secret or Value; it will not reveal the inner secret.

func (Secret) Equal

func (secret Secret) Equal(other Value) bool

Equal returns false; secrets cannot be compared.

func (Secret) Eval

func (secret Secret) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

Eval does nothing and returns the secret.

func (*Secret) FromValue added in v0.5.0

func (value *Secret) FromValue(val Value) error

func (Secret) Reveal

func (secret Secret) Reveal() []byte

func (Secret) String

func (secret Secret) String() string

type Sink

type Sink struct {
	PipeSink PipeSink
}

func NewSink

func NewSink(ps PipeSink) *Sink

func (*Sink) Decode

func (value *Sink) Decode(dest any) error

func (*Sink) Equal

func (sink *Sink) Equal(other Value) bool

func (*Sink) Eval

func (value *Sink) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*Sink) MarshalJSON

func (value *Sink) MarshalJSON() ([]byte, error)

func (*Sink) String

func (value *Sink) String() string

type Source

type Source struct {
	PipeSource PipeSource
}

func Across added in v0.5.0

func Across(ctx context.Context, sources ...*Source) *Source

func NewSource

func NewSource(ps PipeSource) *Source

func (*Source) Decode

func (value *Source) Decode(dest any) error

func (*Source) Equal

func (value *Source) Equal(other Value) bool

func (*Source) Eval

func (value *Source) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*Source) MarshalJSON

func (value *Source) MarshalJSON() ([]byte, error)

func (*Source) String

func (value *Source) String() string

type String

type String string

func (String) Bind

func (binding String) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (String) Decode

func (value String) Decode(dest any) error

func (String) EachBinding

func (String) EachBinding(func(Symbol, Range) error) error

func (String) Equal

func (value String) Equal(other Value) bool

func (String) Eval

func (value String) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (String) String

func (value String) String() string

type StructuredError added in v0.5.0

type StructuredError struct {
	Message string
	Fields  *Scope
}

func (*StructuredError) Error added in v0.5.0

func (err *StructuredError) Error() string

func (*StructuredError) NiceError added in v0.5.0

func (structured *StructuredError) NiceError(w io.Writer) error

type Symbol

type Symbol string
var (
	DocMetaBinding    Symbol = "doc"
	FileMetaBinding   Symbol = "file"
	LineMetaBinding   Symbol = "line"
	ColumnMetaBinding Symbol = "column"
)

DocMetaBinding is the binding in meta that stores the value's doc string.

func Predicates

func Predicates(val Value) []Symbol

Predicates returns a list of all builtin predicates which return true for the given value.

func SymbolFromJSONKey

func SymbolFromJSONKey(key string) Symbol

func (Symbol) Bind

func (binding Symbol) Bind(ctx context.Context, scope *Scope, cont Cont, val Value, doc ...Annotated) ReadyCont

func (Symbol) Call

func (combiner Symbol) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (Symbol) Decode

func (value Symbol) Decode(dest any) error

func (Symbol) EachBinding

func (binding Symbol) EachBinding(cb func(Symbol, Range) error) error

func (Symbol) Equal

func (value Symbol) Equal(other Value) bool

func (Symbol) Eval

func (value Symbol) Eval(_ context.Context, scope *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Symbol) JSONKey

func (value Symbol) JSONKey() string

func (Symbol) Keyword

func (value Symbol) Keyword() Keyword

func (Symbol) String

func (value Symbol) String() string

func (Symbol) Unwrap

func (app Symbol) Unwrap() Combiner

type SymbolOperative

type SymbolOperative struct {
	Symbol Symbol
}

func (SymbolOperative) Call

func (op SymbolOperative) Call(_ context.Context, val Value, _ *Scope, cont Cont) ReadyCont

func (SymbolOperative) Decode

func (value SymbolOperative) Decode(dest any) error

func (SymbolOperative) Equal

func (value SymbolOperative) Equal(other Value) bool

func (SymbolOperative) Eval

func (value SymbolOperative) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (SymbolOperative) String

func (value SymbolOperative) String() string

type Thunk

type Thunk struct {
	// Image specifies the OCI image in which to run the thunk.
	Image *ThunkImage `json:"image,omitempty"`

	// Insecure may be set to true to enable running the thunk with elevated
	// privileges. Its meaning is determined by the runtime.
	Insecure bool `json:"insecure,omitempty"`

	// Cmd identifies the file or command to run.
	Cmd ThunkCmd `json:"cmd"`

	// Args is a list of string or path arguments to pass to the command.
	Args []Value `json:"args,omitempty"`

	// Stdin is a list of arbitrary values, which may contain paths, to pass to
	// the command.
	Stdin []Value `json:"stdin,omitempty"`

	// Env is a mapping from environment variables to their string or path
	// values.
	Env *Scope `json:"env,omitempty"`

	// Dir configures a working directory in which to run the command.
	//
	// Note that a working directory is automatically provided to thunks by
	// the runtime. A relative Dir value will be relative to this working
	// directory, not the OCI image's initial working directory. The OCI image's
	// working directory is ignored.
	//
	// A relative directory path will be relative to the initial working
	// directory. An absolute path will be relative to the OCI image root.
	//
	// A thunk directory path may also be provided. It will be mounted to the
	// container and used as the working directory of the command.
	Dir *ThunkDir `json:"dir,omitempty"`

	// Mounts configures explicit mount points for the thunk, in addition to
	// any provided in Path, Args, Stdin, Env, or Dir.
	Mounts []ThunkMount `json:"mounts,omitempty"`

	// Labels specify arbitrary fields for identifying the thunk, typically
	// used to influence caching behavior.
	//
	// For example, thunks which may return different results over time should
	// embed the current timestamp truncated to a certain amount of granularity,
	// e.g. one minute. Doing so prevents the first call from being cached
	// forever while still allowing some level of caching to take place.
	Labels *Scope `json:"labels,omitempty"`
}

func MustThunk

func MustThunk(cmd Path, stdin ...Value) Thunk

func (Thunk) Avatar

func (wl Thunk) Avatar() (*invaders.Invader, error)

Avatar returns an ASCII art avatar derived from the thunk.

func (Thunk) Call

func (combiner Thunk) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (Thunk) Cmdline

func (thunk Thunk) Cmdline() string

func (Thunk) Decode

func (thunk Thunk) Decode(dest any) error

func (Thunk) Equal

func (thunk Thunk) Equal(other Value) bool

func (Thunk) Eval

func (value Thunk) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the thunk.

func (Thunk) Extend

func (thunk Thunk) Extend(sub Path) (Path, error)

Extend returns a path referring to the given path relative to the parent Path.

func (*Thunk) FromValue

func (value *Thunk) FromValue(val Value) error

func (Thunk) Name

func (thunk Thunk) Name() string

Name returns the unqualified name for the path, i.e. the base name of a file or directory, or the name of a command.

func (Thunk) Open

func (thunk Thunk) Open(ctx context.Context) (io.ReadCloser, error)

func (*Thunk) Platform

func (thunk *Thunk) Platform() *Platform

func (Thunk) SHA256

func (wl Thunk) SHA256() (string, error)

SHA256 returns a stable SHA256 hash derived from the thunk.

func (Thunk) String

func (thunk Thunk) String() string

func (*Thunk) UnmarshalJSON

func (thunk *Thunk) UnmarshalJSON(b []byte) error

func (Thunk) Unwrap

func (combiner Thunk) Unwrap() Combiner

func (Thunk) WithArgs

func (thunk Thunk) WithArgs(args []Value) Thunk

WithArgs sets the thunk's arg values.

func (Thunk) WithCmd added in v0.4.0

func (thunk Thunk) WithCmd(cmd ThunkCmd) Thunk

WithArgs sets the thunk's command.

func (Thunk) WithDir

func (thunk Thunk) WithDir(dir ThunkDir) Thunk

WithDir sets the thunk's working directory.

func (Thunk) WithEnv

func (thunk Thunk) WithEnv(env *Scope) Thunk

WithEnv sets the thunk's env.

func (Thunk) WithImage

func (thunk Thunk) WithImage(image ThunkImage) Thunk

WithImage sets the base image of the thunk, recursing into parent thunks until it reaches the bottom, like a rebase.

func (Thunk) WithInsecure

func (thunk Thunk) WithInsecure(insecure bool) Thunk

WithInsecure sets whether the thunk should be run insecurely.

func (Thunk) WithLabel

func (thunk Thunk) WithLabel(key Symbol, val Value) Thunk

WithMount adds a mount.

func (Thunk) WithMount

func (thunk Thunk) WithMount(src ThunkMountSource, tgt FileOrDirPath) Thunk

WithMount adds a mount.

func (Thunk) WithStdin

func (thunk Thunk) WithStdin(stdin []Value) Thunk

WithStdin sets the thunk's stdin values.

type ThunkCmd

type ThunkCmd struct {
	Cmd       *CommandPath
	File      *FilePath
	ThunkFile *ThunkPath
	Host      *HostPath
	FS        *FSPath
}

func (*ThunkCmd) FromValue

func (path *ThunkCmd) FromValue(val Value) error

func (ThunkCmd) Inner

func (cmd ThunkCmd) Inner() (Value, error)

func (ThunkCmd) MarshalJSON

func (path ThunkCmd) MarshalJSON() ([]byte, error)

func (ThunkCmd) ToValue

func (cmd ThunkCmd) ToValue() Value

func (*ThunkCmd) UnmarshalJSON

func (path *ThunkCmd) UnmarshalJSON(payload []byte) error

type ThunkDir

type ThunkDir struct {
	Dir      *DirPath
	ThunkDir *ThunkPath
	HostDir  *HostPath
}

func (*ThunkDir) FromValue

func (path *ThunkDir) FromValue(val Value) error

func (ThunkDir) MarshalJSON

func (path ThunkDir) MarshalJSON() ([]byte, error)

func (ThunkDir) ToValue

func (path ThunkDir) ToValue() Value

func (*ThunkDir) UnmarshalJSON

func (path *ThunkDir) UnmarshalJSON(payload []byte) error

type ThunkImage

type ThunkImage struct {
	Ref   *ThunkImageRef
	Thunk *Thunk
}

ThunkImage specifies the base image of a thunk - either a reference to be fetched, a thunk path (e.g. of a OCI/Docker tarball), or a lower thunk to run.

func (*ThunkImage) FromValue

func (image *ThunkImage) FromValue(val Value) error

func (ThunkImage) MarshalJSON

func (image ThunkImage) MarshalJSON() ([]byte, error)

func (ThunkImage) Platform

func (img ThunkImage) Platform() *Platform

func (ThunkImage) ToValue

func (image ThunkImage) ToValue() Value

func (*ThunkImage) UnmarshalJSON

func (image *ThunkImage) UnmarshalJSON(payload []byte) error

type ThunkImageRef

type ThunkImageRef struct {
	// The platform to target; influences runtime selection.
	Platform Platform `json:"platform"`

	// A reference to an image hosted on a registry.
	Repository string `json:"repository,omitempty"`

	// An OCI image archive tarball to load.
	File *ThunkPath `json:"file,omitempty"`

	// The tag to use, either from the repository or in a multi-tag OCI archive.
	Tag string `json:"tag,omitempty"`

	// An optional digest for maximally reprodicuble builds.
	Digest string `json:"digest,omitempty"`
}

ThunkImageRef specifies an OCI image uploaded to a registry.

func (ThunkImageRef) Ref

func (ref ThunkImageRef) Ref() (string, error)

type ThunkMount

type ThunkMount struct {
	Source ThunkMountSource `json:"source"`
	Target FileOrDirPath    `json:"target"`
}

ThunkMount configures a mount for the thunk.

type ThunkMountSource

type ThunkMountSource struct {
	ThunkPath *ThunkPath
	HostPath  *HostPath
	FSPath    *FSPath
	Cache     *FileOrDirPath
	Secret    *Secret
}

func (*ThunkMountSource) FromValue

func (enum *ThunkMountSource) FromValue(val Value) error

func (ThunkMountSource) MarshalJSON

func (enum ThunkMountSource) MarshalJSON() ([]byte, error)

func (ThunkMountSource) ToValue

func (enum ThunkMountSource) ToValue() Value

func (*ThunkMountSource) UnmarshalJSON

func (enum *ThunkMountSource) UnmarshalJSON(payload []byte) error

type ThunkOperative

type ThunkOperative struct {
	Cmd ThunkCmd
}

ThunkOperative is an operative which constructs a Thunk.

func (ThunkOperative) Call

func (op ThunkOperative) Call(_ context.Context, args Value, _ *Scope, cont Cont) ReadyCont

Call constructs a thunk, passing arguments as values on stdin.

func (ThunkOperative) Decode

func (value ThunkOperative) Decode(dest any) error

func (ThunkOperative) Equal

func (value ThunkOperative) Equal(other Value) bool

func (ThunkOperative) Eval

func (value ThunkOperative) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (ThunkOperative) String

func (value ThunkOperative) String() string

type ThunkPath

type ThunkPath struct {
	Thunk Thunk         `json:"thunk"`
	Path  FileOrDirPath `json:"path"`
}

A path created by a thunk.

func (ThunkPath) Call

func (combiner ThunkPath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (ThunkPath) Decode

func (value ThunkPath) Decode(dest any) error

func (ThunkPath) Dir

func (path ThunkPath) Dir() ThunkPath

func (ThunkPath) Equal

func (value ThunkPath) Equal(other Value) bool

func (ThunkPath) Eval

func (value ThunkPath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (ThunkPath) Extend

func (path ThunkPath) Extend(ext Path) (Path, error)

func (*ThunkPath) FromValue

func (value *ThunkPath) FromValue(val Value) error

func (ThunkPath) Name

func (path ThunkPath) Name() string

func (ThunkPath) Open

func (path ThunkPath) Open(ctx context.Context) (io.ReadCloser, error)

func (ThunkPath) SHA256

func (wl ThunkPath) SHA256() (string, error)

SHA256 returns a stable SHA256 hash derived from the thunk path.

func (ThunkPath) String

func (value ThunkPath) String() string

func (*ThunkPath) UnmarshalJSON

func (value *ThunkPath) UnmarshalJSON(payload []byte) error

func (ThunkPath) Unwrap

func (app ThunkPath) Unwrap() Combiner

type Trace

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

func TraceFrom added in v0.3.0

func TraceFrom(ctx context.Context) (*Trace, bool)

func (*Trace) Caller

func (trace *Trace) Caller(offset int) *Annotate

func (*Trace) Frames

func (trace *Trace) Frames() []*Annotate

func (*Trace) IsEmpty

func (trace *Trace) IsEmpty() bool

func (*Trace) Pop

func (trace *Trace) Pop(n int)

func (*Trace) Record

func (trace *Trace) Record(frame *Annotate)

func (*Trace) Reset

func (trace *Trace) Reset()

type UnboundError

type UnboundError struct {
	Symbol Symbol
	Scope  *Scope
}

func (UnboundError) Error

func (err UnboundError) Error() string

func (UnboundError) NiceError added in v0.4.0

func (unbound UnboundError) NiceError(w io.Writer) error

type UnixTableProtocol

type UnixTableProtocol struct{}

UnixTableProtocol parses lines of tabular output with columns separated by whitespace.

Each row is not guaranteed to have the same number of columns. Empty lines correspond to empty arrays.

func (UnixTableProtocol) DecodeInto

func (proto UnixTableProtocol) DecodeInto(ctx context.Context, sink PipeSink, r io.Reader) error

DecodeInto decodes from r and emits lists of strings to the sink.

type UnknownProtocolError

type UnknownProtocolError struct {
	Protocol Symbol
}

UnknownProtocolError is returned when a thunk specifies an unknown response protocol.

func (UnknownProtocolError) Error

func (err UnknownProtocolError) Error() string

type Value

type Value interface {
	fmt.Stringer

	// Eval continues execution with a new value (or the same value, for consts).
	Eval(context.Context, *Scope, Cont) ReadyCont

	// Equal checks whether two values are equal, i.e. same type and equivalent
	// value.
	Equal(Value) bool

	// Decode coerces and assigns the Value into the given type, analogous to
	// unmarshaling.
	//
	// If the given type is a direct implementor of Value, it must only
	// successfully decode from another instance of that type.
	//
	// If the given type is a Go primitive, it must do its best to coerce into
	// that type. For example, null can Decode into bool, but not Bool.
	//
	// TODO: move this to Encodable/Decodable or something (or rename all this if
	// it's so confusing)
	Decode(any) error
}

Value represents any value used by Bass programs.

func Descope

func Descope(val Value) Value

Descope is a funky little function that decodes from the scope form of a first-class value type, like a thunk path or file path. This typically happens when encoding to and from JSON.

func EvalFSFile

func EvalFSFile(ctx context.Context, scope *Scope, fs fs.FS, filePath string) (Value, error)

func EvalFile

func EvalFile(ctx context.Context, scope *Scope, filePath string) (Value, error)

func EvalReader

func EvalReader(ctx context.Context, e *Scope, r io.Reader, name ...string) (Value, error)

func EvalString

func EvalString(ctx context.Context, e *Scope, str string, name ...string) (Value, error)

func Resolve

func Resolve(val Value, r func(Value) (Value, error)) (Value, error)

func ToSlice

func ToSlice(list List) ([]Value, error)

func Trampoline

func Trampoline(ctx context.Context, val Value) (Value, error)

func ValueOf

func ValueOf(src any) (Value, error)

func WithMeta

func WithMeta(val Value, metaVal Value) (Value, error)

type ValueJSON

type ValueJSON struct {
	Value
}

ValueJSON is just an envelope for an arbitrary Value.

func (ValueJSON) MarshalJSON

func (res ValueJSON) MarshalJSON() ([]byte, error)

func (*ValueJSON) UnmarshalJSON

func (res *ValueJSON) UnmarshalJSON(p []byte) error

type Wrapped

type Wrapped struct {
	Underlying Combiner
}

func (Wrapped) Call

func (combiner Wrapped) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

Call evaluates the value in the scope and calls the underlying combiner with the result.

func (Wrapped) Decode

func (value Wrapped) Decode(dest any) error

func (Wrapped) Equal

func (value Wrapped) Equal(other Value) bool

func (Wrapped) Eval

func (value Wrapped) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Wrapped) MarshalJSON

func (value Wrapped) MarshalJSON() ([]byte, error)

func (Wrapped) String

func (value Wrapped) String() string

func (Wrapped) Unwrap

func (app Wrapped) Unwrap() Combiner

type WriteFlusher

type WriteFlusher interface {
	io.Writer
	Flush() error
}

WriteFlusher is a flushable io.Writer, to support protocols which have to maintain an internal buffer.

type WriteonlyMemos

type WriteonlyMemos struct {
	Writer Memos
}

func (WriteonlyMemos) Remove

func (file WriteonlyMemos) Remove(thunk Thunk, binding Symbol, input Value) error

func (WriteonlyMemos) Retrieve

func (file WriteonlyMemos) Retrieve(thunk Thunk, binding Symbol, input Value) (Value, bool, error)

func (WriteonlyMemos) Store

func (file WriteonlyMemos) Store(thunk Thunk, binding Symbol, input Value, output Value) error

Jump to

Keyboard shortcuts

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