Documentation
¶
Overview ¶
Package values declares the flux data types and implements them.
Index ¶
- Variables
- func AssignableTo(V, T semantic.Type) bool
- func BuildExternAssignments(node semantic.Node, scope Scope) semantic.Node
- func CheckKind(got, exp semantic.Nature)
- func FormattedScope(scope Scope) fmt.Formatter
- func NewFunction(name string, typ semantic.PolyType, ...) *function
- func NewObject() *object
- func NewObjectWithBacking(size int) *object
- func NewObjectWithValues(vals map[string]Value) *object
- func UnexpectedKind(got, exp semantic.Nature) error
- type Array
- type BinaryFuncSignature
- type BinaryFunction
- type Duration
- type Function
- type Object
- type Package
- type Scope
- type Time
- type Typer
- type Value
- func New(v interface{}) Value
- func NewBool(v bool) Value
- func NewBytes(v []byte) Value
- func NewDuration(v Duration) Value
- func NewFloat(v float64) Value
- func NewFromString(t semantic.Type, s string) (Value, error)
- func NewInt(v int64) Value
- func NewNull(t semantic.Type) Value
- func NewRegexp(v *regexp.Regexp) Value
- func NewString(v string) Value
- func NewTime(v Time) Value
- func NewUInt(v uint64) Value
- type ValueStringer
Constants ¶
This section is empty.
Variables ¶
var ( // InvalidValue is a non nil value who's type is semantic.Invalid InvalidValue = value{/* contains filtered or unexported fields */} // Null is an untyped nil value. Null = value{/* contains filtered or unexported fields */} )
Functions ¶
func AssignableTo ¶ added in v0.33.0
AssignableTo returns true if type V is assignable to type T.
func BuildExternAssignments ¶ added in v0.40.0
BuildExternAssignments constructs nested semantic.ExternAssignment nodes mirroring the nested structure of the scope.
func FormattedScope ¶ added in v0.40.0
FormattedScope produces a fmt.Formatter for pretty printing a scope.
func NewFunction ¶
func NewFunction(name string, typ semantic.PolyType, call func(ctx context.Context, args Object) (Value, error), sideEffect bool) *function
NewFunction returns a new function value
func NewObjectWithBacking ¶ added in v0.14.0
func NewObjectWithBacking(size int) *object
func NewObjectWithValues ¶
func UnexpectedKind ¶
Types ¶
type Array ¶
type Array interface { Value Get(i int) Value Set(i int, v Value) Append(v Value) Len() int Range(func(i int, v Value)) Sort(func(i, j Value) bool) }
Array represents an sequence of elements All elements must be the same type
type BinaryFuncSignature ¶
type BinaryFuncSignature struct { Operator ast.OperatorKind Left, Right semantic.Nature }
type BinaryFunction ¶
func LookupBinaryFunction ¶
func LookupBinaryFunction(sig BinaryFuncSignature) (BinaryFunction, error)
LookupBinaryFunction returns an appropriate binary function that evaluates two values and returns another value. If the two types are not compatible with the given operation, this returns an error.
type Function ¶
type Function interface { Value HasSideEffect() bool Call(ctx context.Context, args Object) (Value, error) }
Function represents a callable type
type Scope ¶ added in v0.40.0
type Scope interface { // Lookup a name in the scope. Lookup(name string) (Value, bool) // LocalLookup a name in current scope only. LocalLookup(name string) (Value, bool) // Set binds a variable in the current scope. Set(name string, v Value) // SetOption binds a variable in the package option scope. // Setting an option must occur on the specific package value. // If the package cannot be found no option is set, in which case the boolean return is false. // An error is reported if the specified package is not a package value. SetOption(pkg, name string, v Value) (bool, error) // Nest creates a new scope by nesting the current scope. // If the passed in object is not nil, its values will be added to the new nested scope. Nest(Object) Scope // Pop returns the parent of the current scope. Pop() Scope // Size is the number of visible names in scope. Size() int // Range iterates over all variable bindings in scope applying f. Range(f func(k string, v Value)) // LocalRange iterates over all variable bindings only in the current scope. LocalRange(f func(k string, v Value)) // SetReturn binds the return value of the scope. SetReturn(Value) // Return reports the bound return value of the scope. Return() Value // Copy creates a deep copy of the scope, values are not copied. // Copy preserves the nesting structure. Copy() Scope }
func NewNestedScope ¶ added in v0.40.0
NewNestedScope creates a new scope with bindings from obj and a parent.
type Time ¶
type Time int64
func ConvertTime ¶
type Value ¶
type Value interface { Typer IsNull() bool Str() string Bytes() []byte Int() int64 UInt() uint64 Float() float64 Bool() bool Time() Time Duration() Duration Regexp() *regexp.Regexp Array() Array Object() Object Function() Function Equal(Value) bool }
func New ¶
func New(v interface{}) Value
New constructs a new Value by inferring the type from the interface. If the interface does not translate to a valid Value type, then InvalidValue is returned.
func NewDuration ¶
type ValueStringer ¶ added in v0.23.0
type ValueStringer interface {
String() string
}