types

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: 14 Imported by: 0

Documentation

Overview

Package types contains basic types for the Elvish runtime.

Index

Constants

View Source
const NoPretty = util.MinInt

NoPretty can be passed to Repr to suppress pretty-printing.

Variables

View Source
var (
	ErrBadIndex        = errors.New("bad index")
	ErrIndexOutOfRange = errors.New("index out of range")
	ErrAssocWithSlice  = errors.New("assoc with slice not yet supported")
)

Error definitions.

View Source
var EmptyList = List{vector.Empty}

EmptyList is an empty list.

View Source
var EmptyMap = Map{hashmap.Empty}

EmptyMap is an empty Map.

View Source
var (
	ErrIndexMustBeString = errors.New("index must be string")
)
View Source
var ErrOnlyStrOrRat = errors.New("only str or rat may be converted to rat")
View Source
var ErrReplacementMustBeString = errors.New("replacement must be string")

Functions

func EqMapLike

func EqMapLike(lhs MapLike, a interface{}) bool

func HashMapLike

func HashMapLike(m MapLike) uint32

func ParseAndFixListIndex

func ParseAndFixListIndex(s string, n int) (bool, int, int)

ParseAndFixListIndex parses a list index and returns whether the index is a slice and "real" (-1 becomes n-1) indicies. It throws errors when the index is invalid or out of range.

func ToBool

func ToBool(v Value) bool

ToBool converts a Value to bool. When the Value type implements Bool(), it is used. Otherwise it is considered true.

func ToString

func ToString(v Value) string

ToString converts a Value to string. When the Value type implements String(), it is used. Otherwise Repr(NoPretty) is used.

Types

type Assocer

type Assocer interface {
	// Assoc returns a slightly modified version of the receiver with key k
	// associated with value v.
	Assoc(k, v Value) Value
}

Assocer wraps the Assoc method.

type Bool

type Bool bool

Bool represents truthness.

func (Bool) Bool

func (b Bool) Bool() bool

func (Bool) Equal

func (b Bool) Equal(rhs interface{}) bool

func (Bool) Hash

func (b Bool) Hash() uint32

func (Bool) Kind

func (Bool) Kind() string

func (Bool) Repr

func (b Bool) Repr(int) string

type Booler

type Booler interface {
	// Bool computes the truth value of the receiver.
	Bool() bool
}

Booler wraps the Bool method.

type Dissocer

type Dissocer interface {
	// Dissoc returns a slightly modified version of the receiver with key k
	// dissociated with any value.
	Dissoc(k Value) Value
}

Dissocer is anything tha can return a slightly modified version of itself with the specified key removed, as a new value.

type Equaler

type Equaler interface {
	// Equal compares the receiver to another value. Two equal values must have
	// the same hash code.
	Equal(other interface{}) bool
}

Equaler wraps the Equal method.

type File

type File struct {
	Inner *os.File
}

File wraps a pointer to os.File.

func NewFile

func NewFile(inner *os.File) File

NewFile creates a new File value.

func (File) Equal

func (f File) Equal(rhs interface{}) bool

func (File) Hash

func (f File) Hash() uint32

func (File) Kind

func (File) Kind() string

func (File) Repr

func (f File) Repr(int) string

type HasKeyer

type HasKeyer interface {
	HasKey(k Value) bool
}

type Hasher

type Hasher interface {
	// Hash computes the hash code of the receiver.
	Hash() uint32
}

Hasher wraps the Hash method.

type IndexOneer

type IndexOneer interface {
	// Index retrieves one value from the receiver at the specified index.
	IndexOne(idx Value) Value
}

IndexOneer wraps the IndexOne method.

type IndexOneerIndexer

type IndexOneerIndexer struct {
	IndexOneer
}

IndexOneerIndexer adapts an IndexOneer to an Indexer by calling all the indicies on the IndexOner and collect the results.

func (IndexOneerIndexer) Index

func (ioi IndexOneerIndexer) Index(vs []Value) []Value

type Indexer

type Indexer interface {
	// Index retrieves the values within the receiver at the specified indicies.
	Index(idx []Value) []Value
}

Indexer wraps the Index method.

func GetIndexer

func GetIndexer(v Value) (Indexer, bool)

GetIndexer adapts a Value to an Indexer if there is an adapter.

type IterateKeyer

type IterateKeyer interface {
	// IterateKey calls the passed function with each value within the receiver.
	// The iteration is aborted if the function returns false.
	IterateKey(func(k Value) bool)
}

IterateKeyer wraps the IterateKey method.

type IteratePairer

type IteratePairer interface {
	// IteratePair calls the passed function with each key and value within the
	// receiver. The iteration is aborted if the function returns false.
	IteratePair(func(k, v Value) bool)
}

IteratePairer wraps the IteratePair method.

type Iterator

type Iterator interface {
	// Iterate calls the passed function with each value within the receiver.
	// The iteration is aborted if the function returns false.
	Iterate(func(v Value) bool)
}

Iterator wraps the Iterate method.

type IteratorValue

type IteratorValue interface {
	Iterator
	Value
}

IteratorValue is an iterable Value.

type Kinder

type Kinder interface {
	Kind() string
}

Kinder wraps the Kind method.

type Lener

type Lener interface {
	// Len computes the length of the receiver.
	Len() int
}

Lener wraps the Len method.

type List

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

List is a list of Value's.

func MakeList

func MakeList(vs ...Value) List

MakeList creates a new List from values.

func NewList

func NewList(vec vector.Vector) List

NewList creates a new List from an existing Vector.

func (List) Assoc

func (l List) Assoc(idx, v Value) Value

func (List) Equal

func (l List) Equal(rhs interface{}) bool

func (List) Hash

func (l List) Hash() uint32

func (List) IndexOne

func (l List) IndexOne(idx Value) Value

func (List) Iterate

func (l List) Iterate(f func(Value) bool)

func (List) Kind

func (List) Kind() string

func (List) Len

func (l List) Len() int

func (List) MarshalJSON

func (l List) MarshalJSON() ([]byte, error)

func (List) Repr

func (l List) Repr(indent int) string

type ListLike

type ListLike interface {
	Lener
	Iterator
	IndexOneer
}

type ListReprBuilder

type ListReprBuilder struct {
	Indent int
	// contains filtered or unexported fields
}

ListReprBuilder helps to build Repr of list-like Values.

func (*ListReprBuilder) String

func (b *ListReprBuilder) String() string

func (*ListReprBuilder) WriteElem

func (b *ListReprBuilder) WriteElem(v string)

type Map

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

Map is a map from string to Value.

func MakeMap

func MakeMap(m map[Value]Value) Map

MakeMap converts a native Go map to Map.

func NewMap

func NewMap(inner hashmap.HashMap) Map

NewMap creates a new Map from an inner HashMap.

func (Map) Assoc

func (m Map) Assoc(k, v Value) Value

func (Map) Dissoc

func (m Map) Dissoc(k Value) Value

func (Map) Equal

func (m Map) Equal(a interface{}) bool

func (Map) HasKey

func (m Map) HasKey(k Value) bool

func (Map) Hash

func (m Map) Hash() uint32

func (Map) IndexOne

func (m Map) IndexOne(idx Value) Value

func (Map) IterateKey

func (m Map) IterateKey(f func(Value) bool)

func (Map) IteratePair

func (m Map) IteratePair(f func(Value, Value) bool)

func (Map) Kind

func (Map) Kind() string

func (Map) Len

func (m Map) Len() int

func (Map) MarshalJSON

func (m Map) MarshalJSON() ([]byte, error)

func (Map) Repr

func (m Map) Repr(indent int) string

type MapReprBuilder

type MapReprBuilder struct {
	ListReprBuilder
}

MapReprBuilder helps building the Repr of a Map. It is also useful for implementing other Map-like values. The zero value of a MapReprBuilder is ready to use.

func (*MapReprBuilder) String

func (b *MapReprBuilder) String() string

func (*MapReprBuilder) WritePair

func (b *MapReprBuilder) WritePair(k string, indent int, v string)

type Pipe

type Pipe struct {
	ReadEnd, WriteEnd *os.File
}

Pipe wraps a pair of pointers to os.File that are the two ends of the same pipe.

func NewPipe

func NewPipe(r, w *os.File) Pipe

NewPipe creates a new Pipe value.

func (Pipe) Equal

func (p Pipe) Equal(rhs interface{}) bool

func (Pipe) Hash

func (p Pipe) Hash() uint32

func (Pipe) Kind

func (Pipe) Kind() string

func (Pipe) Repr

func (p Pipe) Repr(int) string

type Rat

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

Rat is a rational number.

func ToRat

func ToRat(v Value) (Rat, error)

ToRat converts a Value to rat. A str can be converted to a rat if it can be parsed. A rat is returned as-is. Other types of values cannot be converted.

func (Rat) Equal

func (r Rat) Equal(a interface{}) bool

func (Rat) Hash

func (r Rat) Hash() uint32

func (Rat) Kind

func (Rat) Kind() string

func (Rat) Repr

func (r Rat) Repr(int) string

func (Rat) String

func (r Rat) String() string

type Reprer

type Reprer interface {
	// Repr returns a string that represents a Value. The string either be a
	// literal of that Value that is preferably deep-equal to it (like `[a b c]`
	// for a list), or a string enclosed in "<>" containing the kind and
	// identity of the Value(like `<fn 0xdeadcafe>`).
	//
	// If indent is at least 0, it should be pretty-printed with the current
	// indentation level of indent; the indent of the first line has already
	// been written and shall not be written in Repr. The returned string
	// should never contain a trailing newline.
	Repr(indent int) string
}

Reprer wraps the Repr method.

type String

type String string

String is just a string.

func (String) Assoc

func (s String) Assoc(idx, v Value) Value

func (String) Equal

func (s String) Equal(rhs interface{}) bool

func (String) Hash

func (s String) Hash() uint32

func (String) IndexOne

func (s String) IndexOne(idx Value) Value

func (String) Iterate

func (s String) Iterate(f func(v Value) bool)

func (String) Kind

func (String) Kind() string

func (String) Len

func (s String) Len() int

func (String) Repr

func (s String) Repr(int) string

func (String) String

func (s String) String() string

type Stringer

type Stringer interface {
	// Stringer converts the receiver to a string.
	String() string
}

Stringer wraps the String method.

type Struct

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

Struct is like a Map with fixed keys.

func NewStruct

func NewStruct(descriptor *StructDescriptor, fields []Value) *Struct

NewStruct creates a new *Struct value.

func (*Struct) Assoc

func (s *Struct) Assoc(k, v Value) Value

func (*Struct) Equal

func (s *Struct) Equal(rhs interface{}) bool

Equal returns true if the rhs is MapLike and all pairs are equal.

func (*Struct) HasKey

func (s *Struct) HasKey(k Value) bool

func (*Struct) Hash

func (s *Struct) Hash() uint32

func (*Struct) IndexOne

func (s *Struct) IndexOne(idx Value) Value

func (*Struct) IterateKey

func (s *Struct) IterateKey(f func(Value) bool)

func (*Struct) IteratePair

func (s *Struct) IteratePair(f func(Value, Value) bool)

func (*Struct) Kind

func (*Struct) Kind() string

func (*Struct) Len

func (s *Struct) Len() int

func (*Struct) MarshalJSON

func (s *Struct) MarshalJSON() ([]byte, error)

MarshalJSON encodes the Struct to a JSON Object.

func (*Struct) Repr

func (s *Struct) Repr(indent int) string

type StructDescriptor

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

StructDescriptor contains information about the fields in a Struct.

func NewStructDescriptor

func NewStructDescriptor(fields ...string) *StructDescriptor

NewStructDescriptor creates a new struct descriptor from a list of field names.

type Value

type Value interface {
	Kinder
	Equaler
	Hasher
	Reprer
}

Value is an Elvish value.

func CollectFromIterator

func CollectFromIterator(it Iterator) []Value

Jump to

Keyboard shortcuts

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