restruct: github.com/go-restruct/restruct/expr Index | Files

package expr

import "github.com/go-restruct/restruct/expr"

Index

Package Files

ast.go env.go eval.go lex.go package.go parse.go tokenkind_string.go type.go value.go

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")
)

func Eval Uses

func Eval(resolver Resolver, expr string) (interface{}, error)

Eval returns the result of evaluating the provided expression.

func EvalProgram Uses

func EvalProgram(resolver Resolver, program *Program) (v interface{}, err error)

EvalProgram returns the result of executing the program with the given resolver.

func TypeEqual Uses

func TypeEqual(a, b Type) bool

TypeEqual returns true if the two types are equal.

type ArrayType Uses

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

ArrayType is the type of array-like values.

func NewArrayType Uses

func NewArrayType(count int, elem Type) *ArrayType

NewArrayType returns a new array type.

func (ArrayType) Elem Uses

func (t ArrayType) Elem() Type

Elem is the type of element in the array.

func (ArrayType) Kind Uses

func (ArrayType) Kind() Kind

Kind implements Type.

func (ArrayType) Len Uses

func (t ArrayType) Len() int

Len is the length of the array.

func (ArrayType) String Uses

func (t ArrayType) String() string

String implements Type.

type ConversionError Uses

type ConversionError struct {
    From Type
    To   Type
}

ConversionError is returned when an invalid type conversion is attempted.

func (ConversionError) Error Uses

func (e ConversionError) Error() string

type Field Uses

type Field struct {
    Name string
    Type Type
}

Field represents a struct field.

type FuncType Uses

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

FuncType is the type of function values.

func NewFuncType Uses

func NewFuncType(in []Type, out []Type, variadic bool) *FuncType

NewFuncType returns a new function type.

func (FuncType) In Uses

func (t FuncType) In(i int) Type

In gets the nth input parameter.

func (FuncType) IsVariadic Uses

func (t FuncType) IsVariadic() bool

IsVariadic returns true for variadic functions.

func (FuncType) Kind Uses

func (FuncType) Kind() Kind

Kind implements Type.

func (FuncType) NumIn Uses

func (t FuncType) NumIn() int

NumIn returns the number of input parameters.

func (FuncType) NumOut Uses

func (t FuncType) NumOut() int

NumOut returns the number of output parameters.

func (FuncType) Out Uses

func (t FuncType) Out(i int) Type

Out gets the nth output parameter.

func (FuncType) String Uses

func (t FuncType) String() string

String implements Type.

type InvalidOpError Uses

type InvalidOpError struct {
    Op  string
    V   Value
}

InvalidOpError is returned when an attempt is made to perform an operation on a type that is not supported.

func (InvalidOpError) Error Uses

func (e InvalidOpError) Error() string

type Kind Uses

type Kind int

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 Uses

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

MapResolver resolves map keys.

func NewMapResolver Uses

func NewMapResolver(m map[string]Value) *MapResolver

NewMapResolver creates a new struct resolver.

func (*MapResolver) Resolve Uses

func (r *MapResolver) Resolve(ident string) Value

Resolve implements Resolver.

type MapType Uses

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

MapType is the type of maps.

func (MapType) Key Uses

func (t MapType) Key() Type

Key is the type of the map's keys.

func (MapType) Kind Uses

func (MapType) Kind() Kind

Kind implements Type.

func (MapType) String Uses

func (t MapType) String() string

String implements Type.

func (MapType) Value Uses

func (t MapType) Value() Type

Value is the type of the map's values.

type MapTypeResolver Uses

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

MapTypeResolver resolves map keys.

func NewMapTypeResolver Uses

func NewMapTypeResolver(m map[string]Type) *MapTypeResolver

NewMapTypeResolver creates a new struct resolver.

func (*MapTypeResolver) TypeResolve Uses

func (r *MapTypeResolver) TypeResolve(ident string) Type

TypeResolve implements TypeResolver.

type MetaResolver Uses

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

MetaResolver runs multiple resolvers serially.

func NewMetaResolver Uses

func NewMetaResolver() *MetaResolver

NewMetaResolver creates a new meta resolver.

func (*MetaResolver) AddResolver Uses

func (r *MetaResolver) AddResolver(n Resolver)

AddResolver adds a new resolver below other resolvers.

func (*MetaResolver) Resolve Uses

func (r *MetaResolver) Resolve(ident string) Value

Resolve implements Resolver.

type MetaTypeResolver Uses

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

MetaTypeResolver runs multiple type resolvers serially.

func NewMetaTypeResolver Uses

func NewMetaTypeResolver() *MetaTypeResolver

NewMetaTypeResolver creates a new meta type resolver.

func (*MetaTypeResolver) AddResolver Uses

func (r *MetaTypeResolver) AddResolver(n TypeResolver)

AddResolver adds a new resolver below other resolvers.

func (*MetaTypeResolver) TypeResolve Uses

func (r *MetaTypeResolver) TypeResolve(ident string) Type

TypeResolve implements TypeResolver.

type NoSuchFieldError Uses

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

NoSuchFieldError is returned when an unknown field is accessed.

func (NoSuchFieldError) Error Uses

func (err NoSuchFieldError) Error() string

type Package Uses

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

Package represents a package value.

func NewPackage Uses

func NewPackage(symbols map[string]Value) Package

NewPackage creates a new package.

func (Package) Symbol Uses

func (p Package) Symbol(ident string) Value

Symbol returns a symbol, or nil if the symbol doesn't exist.

func (Package) Type Uses

func (p Package) Type() Type

Type returns the type for this package.

type PackageType Uses

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

PackageType is the type of a package.

func NewPackageType Uses

func NewPackageType(symbols map[string]Type) *PackageType

NewPackageType returns a new package with the given symbols.

func (PackageType) Kind Uses

func (PackageType) Kind() Kind

Kind implements Type.

func (PackageType) String Uses

func (PackageType) String() string

String implements Type.

func (PackageType) Symbol Uses

func (t PackageType) Symbol(ident string) Type

Symbol returns a symbol by the given name, or nil if none could be found.

type PrimitiveType Uses

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

PrimitiveType is the type of primitives.

func (PrimitiveType) Kind Uses

func (t PrimitiveType) Kind() Kind

Kind implements Type.

func (PrimitiveType) String Uses

func (t PrimitiveType) String() string

String implements Type.

type Program Uses

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

Program represents a parsed expression.

func Parse Uses

func Parse(r io.RuneScanner) *Program

Parse parses an expression into a program.

func ParseString Uses

func ParseString(s string) *Program

ParseString parses an expression from a string.

type PtrType Uses

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

PtrType is the type of pointers.

func NewPtrType Uses

func NewPtrType(elem Type) *PtrType

NewPtrType returns a new pointer type.

func (PtrType) Elem Uses

func (t PtrType) Elem() Type

Elem returns the element being pointed to by the pointer.

func (PtrType) Kind Uses

func (PtrType) Kind() Kind

Kind implements Type.

func (PtrType) String Uses

func (t PtrType) String() string

String implements Type.

type ReferenceError Uses

type ReferenceError struct{}

ReferenceError is returned when it is not possible to take the address of a value.

func (ReferenceError) Error Uses

func (e ReferenceError) Error() string

type Resolver Uses

type Resolver interface {
    Resolve(ident string) Value
}

Resolver resolves runtime values.

type SliceType Uses

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

SliceType is the type of array-like values.

func NewSliceType Uses

func NewSliceType(elem Type) *SliceType

NewSliceType returns a new array type.

func (SliceType) Elem Uses

func (t SliceType) Elem() Type

Elem is the type of element in the slice.

func (SliceType) Kind Uses

func (SliceType) Kind() Kind

Kind implements Type.

func (SliceType) String Uses

func (t SliceType) String() string

String implements Type.

type StructResolver Uses

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

StructResolver resolves struct fields.

func NewStructResolver Uses

func NewStructResolver(s reflect.Value) *StructResolver

NewStructResolver creates a new struct resolver.

func (*StructResolver) Resolve Uses

func (r *StructResolver) Resolve(ident string) Value

Resolve implements Resolver.

type StructType Uses

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

StructType is the type of struct values.

func NewStructType Uses

func NewStructType(fields []Field) *StructType

NewStructType returns a new struct type.

func (StructType) Field Uses

func (t StructType) Field(i int) Field

Field returns the nth field in the struct.

func (StructType) FieldByName Uses

func (t StructType) FieldByName(name string) (Field, bool)

FieldByName returns the field with the given name.

func (StructType) Kind Uses

func (StructType) Kind() Kind

Kind implements Type.

func (StructType) NumFields Uses

func (t StructType) NumFields() int

NumFields returns the number of fields in the struct.

func (StructType) String Uses

func (t StructType) String() string

String implements Type.

type StructTypeResolver Uses

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

StructTypeResolver resolves types of struct fields.

func NewStructTypeResolver Uses

func NewStructTypeResolver(s interface{}) *StructTypeResolver

NewStructTypeResolver creates a new struct type resolver.

func (*StructTypeResolver) TypeResolve Uses

func (r *StructTypeResolver) TypeResolve(ident string) Type

TypeResolve implements TypeResolver.

type Type Uses

type Type interface {
    Kind() Kind
    String() string
}

Type is the representation of an expr type.

func NewLiteralType Uses

func NewLiteralType(k Kind) Type

NewLiteralType returns a new primitive type.

func NewMapType Uses

func NewMapType(key Type, val Type) Type

NewMapType returns a new map type.

func NewPrimitiveType Uses

func NewPrimitiveType(k Kind) Type

NewPrimitiveType returns a new primitive type.

func TypeOf Uses

func TypeOf(i interface{}) Type

TypeOf returns the type of a runtime value.

type TypeResolver Uses

type TypeResolver interface {
    TypeResolve(ident string) Type
}

TypeResolver resolves types.

type TypeResolverAdapter Uses

type TypeResolverAdapter struct {
    Resolver
}

TypeResolverAdapter adapts a runtime resolver to a type resolver by taking types of values retrieve from Resolve.

func NewTypeResolverAdapter Uses

func NewTypeResolverAdapter(r Resolver) *TypeResolverAdapter

NewTypeResolverAdapter creates a new TypeResolverAdapter from a resolver.

func (*TypeResolverAdapter) TypeResolve Uses

func (r *TypeResolverAdapter) TypeResolve(ident string) Type

TypeResolve implements TypeResolver.

type Value Uses

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.

func ValueOf Uses

func ValueOf(i interface{}) Value

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.