Documentation
¶
Overview ¶
Package types contains basic types for the Elvish runtime.
Index ¶
- Constants
- Variables
- func EqMapLike(lhs MapLike, a interface{}) bool
- func HashMapLike(m MapLike) uint32
- func ParseAndFixListIndex(s string, n int) (bool, int, int)
- func ToBool(v Value) bool
- func ToString(v Value) string
- type Assocer
- type Bool
- type Booler
- type Dissocer
- type Equaler
- type File
- type HasKeyer
- type Hasher
- type IndexOneer
- type IndexOneerIndexer
- type Indexer
- type IterateKeyer
- type IteratePairer
- type Iterator
- type IteratorValue
- type Kinder
- type Lener
- type List
- func (l List) Assoc(idx, v Value) Value
- func (l List) Equal(rhs interface{}) bool
- func (l List) Hash() uint32
- func (l List) IndexOne(idx Value) Value
- func (l List) Iterate(f func(Value) bool)
- func (List) Kind() string
- func (l List) Len() int
- func (l List) MarshalJSON() ([]byte, error)
- func (l List) Repr(indent int) string
- type ListLike
- type ListReprBuilder
- type Map
- func (m Map) Assoc(k, v Value) Value
- func (m Map) Dissoc(k Value) Value
- func (m Map) Equal(a interface{}) bool
- func (m Map) HasKey(k Value) bool
- func (m Map) Hash() uint32
- func (m Map) IndexOne(idx Value) Value
- func (m Map) IterateKey(f func(Value) bool)
- func (m Map) IteratePair(f func(Value, Value) bool)
- func (Map) Kind() string
- func (m Map) Len() int
- func (m Map) MarshalJSON() ([]byte, error)
- func (m Map) Repr(indent int) string
- type MapLike
- type MapReprBuilder
- type Pipe
- type Rat
- type Reprer
- type String
- func (s String) Assoc(idx, v Value) Value
- func (s String) Equal(rhs interface{}) bool
- func (s String) Hash() uint32
- func (s String) IndexOne(idx Value) Value
- func (s String) Iterate(f func(v Value) bool)
- func (String) Kind() string
- func (s String) Len() int
- func (s String) Repr(int) string
- func (s String) String() string
- type Stringer
- type Struct
- func (s *Struct) Assoc(k, v Value) Value
- func (s *Struct) Equal(rhs interface{}) bool
- func (s *Struct) HasKey(k Value) bool
- func (s *Struct) Hash() uint32
- func (s *Struct) IndexOne(idx Value) Value
- func (s *Struct) IterateKey(f func(Value) bool)
- func (s *Struct) IteratePair(f func(Value, Value) bool)
- func (*Struct) Kind() string
- func (s *Struct) Len() int
- func (s *Struct) MarshalJSON() ([]byte, error)
- func (s *Struct) Repr(indent int) string
- type StructDescriptor
- type Value
Constants ¶
const NoPretty = util.MinInt
NoPretty can be passed to Repr to suppress pretty-printing.
Variables ¶
var ( ErrBadIndex = errors.New("bad index") ErrIndexOutOfRange = errors.New("index out of range") ErrAssocWithSlice = errors.New("assoc with slice not yet supported") )
Error definitions.
var EmptyList = List{vector.Empty}
EmptyList is an empty list.
var EmptyMap = Map{hashmap.Empty}
EmptyMap is an empty Map.
var (
ErrIndexMustBeString = errors.New("index must be string")
)
var ErrOnlyStrOrRat = errors.New("only str or rat may be converted to rat")
var ErrReplacementMustBeString = errors.New("replacement must be string")
Functions ¶
func HashMapLike ¶
func ParseAndFixListIndex ¶
ParseAndFixListIndex parses a list index and returns whether the index is a slice and "real" (-1 becomes n-1) indicies. It throws errors when the index is invalid or out of range.
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 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 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 ¶
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 ¶
IteratorValue is an iterable Value.
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 (List) MarshalJSON ¶
type ListLike ¶
type ListLike interface {
Lener
Iterator
IndexOneer
}
type ListReprBuilder ¶
type ListReprBuilder struct {
Indent int
// contains filtered or unexported fields
}
ListReprBuilder helps to build Repr of list-like Values.
func (*ListReprBuilder) String ¶
func (b *ListReprBuilder) String() string
func (*ListReprBuilder) WriteElem ¶
func (b *ListReprBuilder) WriteElem(v string)
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is a map from string to Value.
func (Map) IterateKey ¶
func (Map) MarshalJSON ¶
type MapLike ¶
type MapLike interface {
Lener
IndexOneer
Assocer
HasKeyer
IterateKeyer
IteratePairer
}
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
type Rat ¶
type Rat struct {
// contains filtered or unexported fields
}
Rat is a rational number.
type Reprer ¶
type Reprer interface {
// Repr returns a string that represents a Value. The string either be a
// literal of that Value that is preferably deep-equal to it (like `[a b c]`
// for a list), or a string enclosed in "<>" containing the kind and
// identity of the Value(like `<fn 0xdeadcafe>`).
//
// If indent is at least 0, it should be pretty-printed with the current
// indentation level of indent; the indent of the first line has already
// been written and shall not be written in Repr. The returned string
// should never contain a trailing newline.
Repr(indent int) string
}
Reprer wraps the Repr method.
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) IterateKey ¶
func (*Struct) MarshalJSON ¶
MarshalJSON encodes the Struct to a JSON Object.
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.