import "github.com/go-restruct/restruct/expr"
ast.go env.go eval.go lex.go package.go parse.go tokenkind_string.go type.go value.go
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") )
Eval returns the result of evaluating the provided expression.
EvalProgram returns the result of executing the program with the given resolver.
TypeEqual returns true if the two types are equal.
type ArrayType struct {
// contains filtered or unexported fields
}
ArrayType is the type of array-like values.
NewArrayType returns a new array type.
Elem is the type of element in the array.
Kind implements Type.
Len is the length of the array.
String implements Type.
ConversionError is returned when an invalid type conversion is attempted.
func (e ConversionError) Error() string
Field represents a struct field.
type FuncType struct {
// contains filtered or unexported fields
}
FuncType is the type of function values.
NewFuncType returns a new function type.
In gets the nth input parameter.
IsVariadic returns true for variadic functions.
Kind implements Type.
NumIn returns the number of input parameters.
NumOut returns the number of output parameters.
Out gets the nth output parameter.
String implements Type.
InvalidOpError is returned when an attempt is made to perform an operation on a type that is not supported.
func (e InvalidOpError) Error() string
Kind is the most basic type descriptor.
const ( Invalid Kind = iota // Primitives Bool Int Int8 Int16 Int32 Int64 Uint Uint8 Uint16 Uint32 Uint64 Uintptr Float32 Float64 String // Untyped constants UntypedBool UntypedInt UntypedFloat UntypedNil // Composite types Array Slice Struct Map Ptr Func Pkg )
Enumeration of valid kinds of types.
type MapResolver struct {
// contains filtered or unexported fields
}
MapResolver resolves map keys.
func NewMapResolver(m map[string]Value) *MapResolver
NewMapResolver creates a new struct resolver.
func (r *MapResolver) Resolve(ident string) Value
Resolve implements Resolver.
type MapType struct {
// contains filtered or unexported fields
}
MapType is the type of maps.
Key is the type of the map's keys.
Kind implements Type.
String implements Type.
Value is the type of the map's values.
type MapTypeResolver struct {
// contains filtered or unexported fields
}
MapTypeResolver resolves map keys.
func NewMapTypeResolver(m map[string]Type) *MapTypeResolver
NewMapTypeResolver creates a new struct resolver.
func (r *MapTypeResolver) TypeResolve(ident string) Type
TypeResolve implements TypeResolver.
type MetaResolver struct {
// contains filtered or unexported fields
}
MetaResolver runs multiple resolvers serially.
func NewMetaResolver() *MetaResolver
NewMetaResolver creates a new meta resolver.
func (r *MetaResolver) AddResolver(n Resolver)
AddResolver adds a new resolver below other resolvers.
func (r *MetaResolver) Resolve(ident string) Value
Resolve implements Resolver.
type MetaTypeResolver struct {
// contains filtered or unexported fields
}
MetaTypeResolver runs multiple type resolvers serially.
func NewMetaTypeResolver() *MetaTypeResolver
NewMetaTypeResolver creates a new meta type resolver.
func (r *MetaTypeResolver) AddResolver(n TypeResolver)
AddResolver adds a new resolver below other resolvers.
func (r *MetaTypeResolver) TypeResolve(ident string) Type
TypeResolve implements TypeResolver.
type NoSuchFieldError struct {
// contains filtered or unexported fields
}
NoSuchFieldError is returned when an unknown field is accessed.
func (err NoSuchFieldError) Error() string
type Package struct {
// contains filtered or unexported fields
}
Package represents a package value.
NewPackage creates a new package.
Symbol returns a symbol, or nil if the symbol doesn't exist.
Type returns the type for this package.
type PackageType struct {
// contains filtered or unexported fields
}
PackageType is the type of a package.
func NewPackageType(symbols map[string]Type) *PackageType
NewPackageType returns a new package with the given symbols.
func (PackageType) Kind() Kind
Kind implements Type.
func (PackageType) String() string
String implements Type.
func (t PackageType) Symbol(ident string) Type
Symbol returns a symbol by the given name, or nil if none could be found.
type PrimitiveType struct {
// contains filtered or unexported fields
}
PrimitiveType is the type of primitives.
func (t PrimitiveType) Kind() Kind
Kind implements Type.
func (t PrimitiveType) String() string
String implements Type.
type Program struct {
// contains filtered or unexported fields
}
Program represents a parsed expression.
func Parse(r io.RuneScanner) *Program
Parse parses an expression into a program.
ParseString parses an expression from a string.
type PtrType struct {
// contains filtered or unexported fields
}
PtrType is the type of pointers.
NewPtrType returns a new pointer type.
Elem returns the element being pointed to by the pointer.
Kind implements Type.
String implements Type.
type ReferenceError struct{}
ReferenceError is returned when it is not possible to take the address of a value.
func (e ReferenceError) Error() string
Resolver resolves runtime values.
type SliceType struct {
// contains filtered or unexported fields
}
SliceType is the type of array-like values.
NewSliceType returns a new array type.
Elem is the type of element in the slice.
Kind implements Type.
String implements Type.
type StructResolver struct {
// contains filtered or unexported fields
}
StructResolver resolves struct fields.
func NewStructResolver(s reflect.Value) *StructResolver
NewStructResolver creates a new struct resolver.
func (r *StructResolver) Resolve(ident string) Value
Resolve implements Resolver.
type StructType struct {
// contains filtered or unexported fields
}
StructType is the type of struct values.
func NewStructType(fields []Field) *StructType
NewStructType returns a new struct type.
func (t StructType) Field(i int) Field
Field returns the nth field in the struct.
func (t StructType) FieldByName(name string) (Field, bool)
FieldByName returns the field with the given name.
func (StructType) Kind() Kind
Kind implements Type.
func (t StructType) NumFields() int
NumFields returns the number of fields in the struct.
func (t StructType) String() string
String implements Type.
type StructTypeResolver struct {
// contains filtered or unexported fields
}
StructTypeResolver resolves types of struct fields.
func NewStructTypeResolver(s interface{}) *StructTypeResolver
NewStructTypeResolver creates a new struct type resolver.
func (r *StructTypeResolver) TypeResolve(ident string) Type
TypeResolve implements TypeResolver.
Type is the representation of an expr type.
NewLiteralType returns a new primitive type.
NewMapType returns a new map type.
NewPrimitiveType returns a new primitive type.
TypeOf returns the type of a runtime value.
TypeResolver resolves types.
TypeResolverAdapter adapts a runtime resolver to a type resolver by taking types of values retrieve from Resolve.
func NewTypeResolverAdapter(r Resolver) *TypeResolverAdapter
NewTypeResolverAdapter creates a new TypeResolverAdapter from a resolver.
func (r *TypeResolverAdapter) TypeResolve(ident string) Type
TypeResolve implements TypeResolver.
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.
ValueOf returns a Value for the given runtime value.
Package expr imports 9 packages (graph) and is imported by 1 packages. Updated 2019-11-11. Refresh now. Tools for package owners.