Documentation
¶
Index ¶
- Variables
- func Eval(resolver Resolver, expr string) (interface{}, error)
- func EvalProgram(resolver Resolver, program *Program) (v interface{}, err error)
- func TypeEqual(a, b Type) bool
- type ArrayType
- type ConversionError
- type Field
- type FuncType
- type InvalidOpError
- type Kind
- type MapResolver
- type MapType
- type MapTypeResolver
- type MetaResolver
- type MetaTypeResolver
- type NoSuchFieldError
- type Package
- type PackageType
- type PrimitiveType
- type Program
- type PtrType
- type ReferenceError
- type Resolver
- type SliceType
- type StructResolver
- type StructType
- type StructTypeResolver
- type Type
- type TypeResolver
- type TypeResolverAdapter
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidKind occurs when you call an inappropriate method for a given kind. ErrInvalidKind = errors.New("invalid kind") // ErrNotRepresentable occurs when a type is encountered that is not supported by the language. ErrNotRepresentable = errors.New("type cannot be represented") // ErrUntypedNil occurs when an untyped nil is used inappropriately. ErrUntypedNil = errors.New("untyped nil value") )
Functions ¶
func EvalProgram ¶
EvalProgram returns the result of executing the program with the given resolver.
Types ¶
type ArrayType ¶
type ArrayType struct {
// contains filtered or unexported fields
}
ArrayType is the type of array-like values.
func NewArrayType ¶
NewArrayType returns a new array type.
type ConversionError ¶
ConversionError is returned when an invalid type conversion is attempted.
func (ConversionError) Error ¶
func (e ConversionError) Error() string
type FuncType ¶
type FuncType struct {
// contains filtered or unexported fields
}
FuncType is the type of function values.
func NewFuncType ¶
NewFuncType returns a new function type.
func (FuncType) IsVariadic ¶
IsVariadic returns true for variadic functions.
type InvalidOpError ¶
InvalidOpError is returned when an attempt is made to perform an operation on a type that is not supported.
func (InvalidOpError) Error ¶
func (e InvalidOpError) Error() string
type MapResolver ¶
type MapResolver struct {
// contains filtered or unexported fields
}
MapResolver resolves map keys.
func NewMapResolver ¶
func NewMapResolver(m map[string]Value) *MapResolver
NewMapResolver creates a new struct resolver.
func (*MapResolver) Resolve ¶
func (r *MapResolver) Resolve(ident string) Value
Resolve implements Resolver.
type MapType ¶
type MapType struct {
// contains filtered or unexported fields
}
MapType is the type of maps.
type MapTypeResolver ¶
type MapTypeResolver struct {
// contains filtered or unexported fields
}
MapTypeResolver resolves map keys.
func NewMapTypeResolver ¶
func NewMapTypeResolver(m map[string]Type) *MapTypeResolver
NewMapTypeResolver creates a new struct resolver.
func (*MapTypeResolver) TypeResolve ¶
func (r *MapTypeResolver) TypeResolve(ident string) Type
TypeResolve implements TypeResolver.
type MetaResolver ¶
type MetaResolver struct {
// contains filtered or unexported fields
}
MetaResolver runs multiple resolvers serially.
func NewMetaResolver ¶
func NewMetaResolver() *MetaResolver
NewMetaResolver creates a new meta resolver.
func (*MetaResolver) AddResolver ¶
func (r *MetaResolver) AddResolver(n Resolver)
AddResolver adds a new resolver below other resolvers.
func (*MetaResolver) Resolve ¶
func (r *MetaResolver) Resolve(ident string) Value
Resolve implements Resolver.
type MetaTypeResolver ¶
type MetaTypeResolver struct {
// contains filtered or unexported fields
}
MetaTypeResolver runs multiple type resolvers serially.
func NewMetaTypeResolver ¶
func NewMetaTypeResolver() *MetaTypeResolver
NewMetaTypeResolver creates a new meta type resolver.
func (*MetaTypeResolver) AddResolver ¶
func (r *MetaTypeResolver) AddResolver(n TypeResolver)
AddResolver adds a new resolver below other resolvers.
func (*MetaTypeResolver) TypeResolve ¶
func (r *MetaTypeResolver) TypeResolve(ident string) Type
TypeResolve implements TypeResolver.
type NoSuchFieldError ¶
type NoSuchFieldError struct {
// contains filtered or unexported fields
}
NoSuchFieldError is returned when an unknown field is accessed.
func (NoSuchFieldError) Error ¶
func (err NoSuchFieldError) Error() string
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package represents a package value.
func NewPackage ¶
NewPackage creates a new package.
type PackageType ¶
type PackageType struct {
// contains filtered or unexported fields
}
PackageType is the type of a package.
func NewPackageType ¶
func NewPackageType(symbols map[string]Type) *PackageType
NewPackageType returns a new package with the given symbols.
func (PackageType) Symbol ¶
func (t PackageType) Symbol(ident string) Type
Symbol returns a symbol by the given name, or nil if none could be found.
type PrimitiveType ¶
type PrimitiveType struct {
// contains filtered or unexported fields
}
PrimitiveType is the type of primitives.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program represents a parsed expression.
func ParseString ¶
ParseString parses an expression from a string.
type PtrType ¶
type PtrType struct {
// contains filtered or unexported fields
}
PtrType is the type of pointers.
type ReferenceError ¶
type ReferenceError struct{}
ReferenceError is returned when it is not possible to take the address of a value.
func (ReferenceError) Error ¶
func (e ReferenceError) Error() string
type SliceType ¶
type SliceType struct {
// contains filtered or unexported fields
}
SliceType is the type of array-like values.
type StructResolver ¶
type StructResolver struct {
// contains filtered or unexported fields
}
StructResolver resolves struct fields.
func NewStructResolver ¶
func NewStructResolver(s reflect.Value) *StructResolver
NewStructResolver creates a new struct resolver.
func (*StructResolver) Resolve ¶
func (r *StructResolver) Resolve(ident string) Value
Resolve implements Resolver.
type StructType ¶
type StructType struct {
// contains filtered or unexported fields
}
StructType is the type of struct values.
func NewStructType ¶
func NewStructType(fields []Field) *StructType
NewStructType returns a new struct type.
func (StructType) Field ¶
func (t StructType) Field(i int) Field
Field returns the nth field in the struct.
func (StructType) FieldByName ¶
func (t StructType) FieldByName(name string) (Field, bool)
FieldByName returns the field with the given name.
func (StructType) NumFields ¶
func (t StructType) NumFields() int
NumFields returns the number of fields in the struct.
type StructTypeResolver ¶
type StructTypeResolver struct {
// contains filtered or unexported fields
}
StructTypeResolver resolves types of struct fields.
func NewStructTypeResolver ¶
func NewStructTypeResolver(s interface{}) *StructTypeResolver
NewStructTypeResolver creates a new struct type resolver.
func (*StructTypeResolver) TypeResolve ¶
func (r *StructTypeResolver) TypeResolve(ident string) Type
TypeResolve implements TypeResolver.
type Type ¶
Type is the representation of an expr type.
func NewPrimitiveType ¶
NewPrimitiveType returns a new primitive type.
type TypeResolver ¶
TypeResolver resolves types.
type TypeResolverAdapter ¶
type TypeResolverAdapter struct {
Resolver
}
TypeResolverAdapter adapts a runtime resolver to a type resolver by taking types of values retrieve from Resolve.
func NewTypeResolverAdapter ¶
func NewTypeResolverAdapter(r Resolver) *TypeResolverAdapter
NewTypeResolverAdapter creates a new TypeResolverAdapter from a resolver.
func (*TypeResolverAdapter) TypeResolve ¶
func (r *TypeResolverAdapter) TypeResolve(ident string) Type
TypeResolve implements TypeResolver.
type Value ¶
type Value interface { Type() Type Value() reflect.Value RawValue() interface{} Negate() Value Not() Value BitNot() Value Deref() Value Ref() Value Dot(ident string) Value LogicalOr(rhs Value) Value LogicalAnd(rhs Value) Value Equal(rhs Value) Value NotEqual(rhs Value) Value Lesser(rhs Value) Value LesserEqual(rhs Value) Value Greater(rhs Value) Value GreaterEqual(rhs Value) Value Add(rhs Value) Value Sub(rhs Value) Value Or(rhs Value) Value Xor(rhs Value) Value Mul(rhs Value) Value Div(rhs Value) Value Rem(rhs Value) Value Lsh(rhs Value) Value Rsh(rhs Value) Value And(rhs Value) Value AndNot(rhs Value) Value Index(rhs Value) Value Call(in []Value) Value }
Value represents a value at runtime.