Documentation ¶
Index ¶
- Variables
- func Eval(expr string) (result []reflect.Value, panik error, compileErrors []error)
- func EvalEnv(expr string, env Env) (result []reflect.Value, panik error, compileErrors []error)
- func EvalExpr(expr Expr, env Env) ([]reflect.Value, error)
- func FormatErrorPos(source, errmsg string) (cursored []string)
- func Inspect(val reflect.Value) string
- func InspectShort(val reflect.Value) string
- func Interpret(stmt string, env Env) (result []reflect.Value, panik error, compileErrors []error)
- func ParseStmt(stmt string) (ast.Stmt, error)
- type ArrayType
- type AssignStmt
- type BadExpr
- type BasicLit
- type BigComplex
- func (z *BigComplex) Add(x, y *BigComplex) *BigComplex
- func (z *BigComplex) Complex128() (_ complex128, exact bool)
- func (z *BigComplex) Equals(other *BigComplex) bool
- func (z *BigComplex) Float64() (f float64, truncation, exact bool)
- func (z *BigComplex) Int(bits int) (_ int64, truncation, overflow bool)
- func (z *BigComplex) Integer() (_ *BigComplex, truncation bool)
- func (z *BigComplex) IsInteger() bool
- func (z *BigComplex) IsReal() bool
- func (z *BigComplex) IsZero() bool
- func (z *BigComplex) Lsh(x *BigComplex, count uint) *BigComplex
- func (z *BigComplex) Mul(x, y *BigComplex) *BigComplex
- func (z *BigComplex) Quo(x, y *BigComplex) *BigComplex
- func (z *BigComplex) Real() (_ *BigComplex, truncation bool)
- func (z *BigComplex) Rsh(x *BigComplex, count uint) *BigComplex
- func (z *BigComplex) String() string
- func (z *BigComplex) StringShow0i(show0i bool) string
- func (z *BigComplex) Sub(x, y *BigComplex) *BigComplex
- func (z *BigComplex) Uint(bits int) (_ uint64, truncation, overflow bool)
- type BinaryExpr
- type BlockStmt
- type BranchStmt
- type Byte
- type CallExpr
- type CaseClause
- type ChanType
- type CompositeLit
- type ConstBoolType
- type ConstComplexType
- type ConstFloatType
- type ConstIntType
- type ConstNilType
- type ConstNumber
- func NewConstComplex128(c complex128) *ConstNumber
- func NewConstFloat(r string) (*ConstNumber, bool)
- func NewConstFloat64(f float64) *ConstNumber
- func NewConstImag(i string) (*ConstNumber, bool)
- func NewConstInt64(i int64) *ConstNumber
- func NewConstInteger(i string) (*ConstNumber, bool)
- func NewConstRune(n rune) *ConstNumber
- func NewConstUint64(u uint64) *ConstNumber
- func (z *ConstNumber) Add(x, y *ConstNumber) *ConstNumber
- func (z *ConstNumber) And(x, y *ConstNumber) *ConstNumber
- func (z *ConstNumber) AndNot(x, y *ConstNumber) *ConstNumber
- func (z *ConstNumber) Lsh(x *ConstNumber, count uint) *ConstNumber
- func (z *ConstNumber) Mul(x, y *ConstNumber) *ConstNumber
- func (z *ConstNumber) Or(x, y *ConstNumber) *ConstNumber
- func (z *ConstNumber) Quo(x, y *ConstNumber) *ConstNumber
- func (z *ConstNumber) Rem(x, y *ConstNumber) *ConstNumber
- func (z *ConstNumber) Rsh(x *ConstNumber, count uint) *ConstNumber
- func (z *ConstNumber) String() string
- func (z *ConstNumber) StringShow0i(show0i bool) string
- func (z *ConstNumber) Sub(x, y *ConstNumber) *ConstNumber
- func (z *ConstNumber) Xor(x, y *ConstNumber) *ConstNumber
- type ConstRuneType
- type ConstShiftedIntType
- type ConstStringType
- type ConstType
- type Ellipsis
- type EmptyStmt
- type Env
- type ErrAppendFirstArgNotSlice
- type ErrAppendFirstArgNotVariadic
- type ErrArrayKeyOutOfBounds
- type ErrAssignCountMismatch
- type ErrBadArrayKey
- type ErrBadArrayValue
- type ErrBadBasicLit
- type ErrBadConstConversion
- type ErrBadConversion
- type ErrBadMapIndex
- type ErrBadMapKey
- type ErrBadMapValue
- type ErrBadReturnValue
- type ErrBadStructValue
- type ErrBuiltinInvalidEllipsis
- type ErrBuiltinMismatchedArgs
- type ErrBuiltinNonTypeArg
- type ErrBuiltinWrongArgType
- type ErrBuiltinWrongNumberOfArgs
- type ErrCallNonFuncType
- type ErrCannotAssignToType
- type ErrCannotAssignToUnaddressable
- type ErrCopyArgsHaveDifferentEltTypes
- type ErrCopyArgsMustBeSlices
- type ErrDeleteFirstArgNotMap
- type ErrDivideByZero
- type ErrDuplicateArg
- type ErrDuplicateArrayKey
- type ErrDuplicateMapKey
- type ErrDuplicateStructField
- type ErrImpossibleTypeAssert
- type ErrImpossibleTypeCase
- type ErrIndexOutOfBounds
- type ErrInvalidAddressOf
- type ErrInvalidBinaryOperation
- type ErrInvalidCase
- type ErrInvalidEllipsisInCall
- type ErrInvalidIndex
- type ErrInvalidIndexOperation
- type ErrInvalidIndirect
- type ErrInvalidRecvFrom
- type ErrInvalidSliceIndex
- type ErrInvalidSliceOperation
- type ErrInvalidStructField
- type ErrInvalidTypeAssert
- type ErrInvalidUnaryOperation
- type ErrMakeBadType
- type ErrMakeLenGtrThanCap
- type ErrMakeNonIntegerArg
- type ErrMissingCompositeLitType
- type ErrMissingMapKey
- type ErrMissingValue
- type ErrMixedStructValues
- type ErrMultiInSingleContext
- type ErrNoNewNamesInDeclaration
- type ErrNonBoolCondition
- type ErrNonIntegerIndex
- type ErrNonInterfaceTypeSwitch
- type ErrNonNameInDeclaration
- type ErrOverflowedConstant
- type ErrStupidShift
- type ErrTruncatedConstant
- type ErrTypeUsedAsExpression
- type ErrUnaddressableSliceOperand
- type ErrUncomparableMapKey
- type ErrUndefined
- type ErrUndefinedFieldOrMethod
- type ErrUnknownStructField
- type ErrUntypedNil
- type ErrWrongArgType
- type ErrWrongNumberOfArgs
- type ErrWrongNumberOfReturnValues
- type ErrWrongNumberOfStructValues
- type Expr
- type ExprStmt
- type Field
- type FieldList
- type ForStmt
- type FuncLit
- type FuncType
- type Ident
- type IfStmt
- type IndexExpr
- type InterfaceType
- type KeyValueExpr
- type LabeledStmt
- type MapType
- type PanicDivideByZero
- type PanicIndexOutOfBounds
- type PanicInterfaceConversion
- type PanicInvalidDereference
- type PanicSliceOutOfBounds
- type PanicUncomparableType
- type PanicUnhashableType
- type PanicUser
- type ParenExpr
- type ReturnStmt
- type Rune
- type SelectorExpr
- type SimpleEnv
- func (env *SimpleEnv) AddConst(ident string, c reflect.Value)
- func (env *SimpleEnv) AddFunc(ident string, f reflect.Value)
- func (env *SimpleEnv) AddPkg(pkg string, p Env)
- func (env *SimpleEnv) AddType(ident string, t reflect.Type)
- func (env *SimpleEnv) AddVar(ident string, v reflect.Value)
- func (env *SimpleEnv) Const(ident string) reflect.Value
- func (env *SimpleEnv) Func(ident string) reflect.Value
- func (env *SimpleEnv) Pkg(pkg string) Env
- func (env *SimpleEnv) PopScope() Env
- func (env *SimpleEnv) PushScope() Env
- func (env *SimpleEnv) Type(ident string) reflect.Type
- func (env *SimpleEnv) Var(ident string) reflect.Value
- type SliceExpr
- type StarExpr
- type State
- type Stmt
- type StructType
- type SwitchStmt
- type TypeAssertExpr
- type TypeSwitchStmt
- type UnaryExpr
- type UntypedNil
Constants ¶
This section is empty.
Variables ¶
var ( ConstInt = ConstIntType{reflect.TypeOf(0)} ConstShiftedInt = ConstShiftedIntType{reflect.TypeOf(0)} ConstRune = ConstRuneType{RuneType} ConstFloat = ConstFloatType{reflect.TypeOf(0.0)} ConstComplex = ConstComplexType{reflect.TypeOf(0i)} ConstString = ConstStringType{reflect.TypeOf("")} ConstNil = ConstNilType{nil} ConstBool = ConstBoolType{reflect.TypeOf(false)} )
var ByteType = Byte{reflect.TypeOf(byte(0))}
var RuneType = Rune{reflect.TypeOf(rune(0))}
Functions ¶
func EvalExpr ¶
EvalExpr is the main function to call to evaluate an ast-parsed expression, expr. Parameter env, contains an evaluation environment from which to get reflect.Values from. Note however that env can be subverted somewhat by supplying callback hooks routines which access variables and by supplying user-defined conversion routines.
func FormatErrorPos ¶
FormatErrorPos formats source to show the position that a (parse) error occurs. When this works, it returns a slice of one or two strings: the source line with the error and if it can find a column position under that, a line indicating the position where the error occurred.
For example, if we have:
source := `split(os.Args ", )")` errmsg := "1:15: expected ')'"
then PrintErrPos(source, errmsg) returns:
{ `split(os.Args ", )")`, `-------------^` }
If something is wrong parsing the error message or matching it with the source, an empty slice is returned.
func Inspect ¶
Inspect prints a reflect.Value the way you would enter it. Some like this should really be part of the reflect package.
func InspectShort ¶
Returns type{...} for composite lits
Types ¶
type ArrayType ¶
type AssignStmt ¶
type AssignStmt struct { *ast.AssignStmt Lhs []Expr Rhs []Expr // contains filtered or unexported fields }
type BigComplex ¶
BigComplex behaves like a *big.Re, but has an imaginary component and separate implementation for + - * /
func (*BigComplex) Add ¶
func (z *BigComplex) Add(x, y *BigComplex) *BigComplex
func (*BigComplex) Complex128 ¶
func (z *BigComplex) Complex128() (_ complex128, exact bool)
z.Complex128() returns a complex128 representation of z. Return value exact will be true if the conversion was completed without loss of precision.
func (*BigComplex) Equals ¶
func (z *BigComplex) Equals(other *BigComplex) bool
func (*BigComplex) Float64 ¶
func (z *BigComplex) Float64() (f float64, truncation, exact bool)
z.Float64() returns a representation of z truncated to a float64 If a truncation from a complex occurs. The imaginary part is dropped and the conversion continues as usual. return value truncation will be true exact will be true if the conversion was completed without loss of precision.
func (*BigComplex) Int ¶
func (z *BigComplex) Int(bits int) (_ int64, truncation, overflow bool)
z.Int() returns a representation of z, truncated to be an int of length bits. Valid values for bits are 8, 16, 32, 64. Result is otherwise undefined If a truncation occurs, the decimal part is dropped and the conversion continues as usual. truncation will be true If an overflow occurs, the result is equivelant to a cast of the form int32(x). overflow will be true.
func (*BigComplex) Integer ¶
func (z *BigComplex) Integer() (_ *BigComplex, truncation bool)
z.Integer() returns a representation of z, a *BigComplex, truncated to be a integer value. The second return value is true if a truncation occured in the real component.
func (*BigComplex) IsInteger ¶
func (z *BigComplex) IsInteger() bool
func (*BigComplex) IsReal ¶
func (z *BigComplex) IsReal() bool
func (*BigComplex) IsZero ¶
func (z *BigComplex) IsZero() bool
func (*BigComplex) Lsh ¶
func (z *BigComplex) Lsh(x *BigComplex, count uint) *BigComplex
func (*BigComplex) Mul ¶
func (z *BigComplex) Mul(x, y *BigComplex) *BigComplex
func (*BigComplex) Quo ¶
func (z *BigComplex) Quo(x, y *BigComplex) *BigComplex
func (*BigComplex) Real ¶
func (z *BigComplex) Real() (_ *BigComplex, truncation bool)
z.Real() returns a representation of z, truncated to a real value. The second return valuie is true if a truncation occured.
func (*BigComplex) Rsh ¶
func (z *BigComplex) Rsh(x *BigComplex, count uint) *BigComplex
func (*BigComplex) String ¶
func (z *BigComplex) String() string
func (*BigComplex) StringShow0i ¶
func (z *BigComplex) StringShow0i(show0i bool) string
func (*BigComplex) Sub ¶
func (z *BigComplex) Sub(x, y *BigComplex) *BigComplex
func (*BigComplex) Uint ¶
func (z *BigComplex) Uint(bits int) (_ uint64, truncation, overflow bool)
z.Uint() returns a representation of z truncated to be a uint of length bits. Valid values for bits are 0, 8, 16, 32, 64. The returned result is otherwise undefined. If a truncation occurs, the decimal part is dropped and the conversion continues as usual. Return values truncation and overflow will be true if an overflow occurs. The result is equivelant to a cast of the form uint32(x).
type BinaryExpr ¶
type BinaryExpr struct { *ast.BinaryExpr X Expr Y Expr // contains filtered or unexported fields }
func (BinaryExpr) Op ¶
func (b BinaryExpr) Op() token.Token
func (*BinaryExpr) String ¶
func (binary *BinaryExpr) String() string
type BranchStmt ¶
type BranchStmt struct { *ast.BranchStmt Label *Ident }
type CallExpr ¶
type CaseClause ¶
type CaseClause struct { *ast.CaseClause List []Expr Body []Stmt }
type CompositeLit ¶
type CompositeLit struct { *ast.CompositeLit Elts []Expr // contains filtered or unexported fields }
func (*CompositeLit) Const ¶
func (*CompositeLit) Const() reflect.Value
func (*CompositeLit) IsConst ¶
func (*CompositeLit) IsConst() bool
func (*CompositeLit) String ¶
func (lit *CompositeLit) String() string
type ConstBoolType ¶
func (ConstBoolType) DefaultPromotion ¶
func (c ConstBoolType) DefaultPromotion() reflect.Type
func (ConstBoolType) IsIntegral ¶
func (ConstBoolType) IsIntegral() bool
func (ConstBoolType) IsNumeric ¶
func (ConstBoolType) IsNumeric() bool
func (ConstBoolType) IsReal ¶
func (ConstBoolType) IsReal() bool
func (ConstBoolType) String ¶
func (ConstBoolType) String() string
type ConstComplexType ¶
func (ConstComplexType) DefaultPromotion ¶
func (c ConstComplexType) DefaultPromotion() reflect.Type
func (ConstComplexType) IsIntegral ¶
func (ConstComplexType) IsIntegral() bool
func (ConstComplexType) IsNumeric ¶
func (ConstComplexType) IsNumeric() bool
func (ConstComplexType) IsReal ¶
func (ConstComplexType) IsReal() bool
func (ConstComplexType) String ¶
func (ConstComplexType) String() string
type ConstFloatType ¶
func (ConstFloatType) DefaultPromotion ¶
func (c ConstFloatType) DefaultPromotion() reflect.Type
func (ConstFloatType) IsIntegral ¶
func (ConstFloatType) IsIntegral() bool
func (ConstFloatType) IsNumeric ¶
func (ConstFloatType) IsNumeric() bool
func (ConstFloatType) IsReal ¶
func (ConstFloatType) IsReal() bool
func (ConstFloatType) String ¶
func (ConstFloatType) String() string
type ConstIntType ¶
func (ConstIntType) DefaultPromotion ¶
func (c ConstIntType) DefaultPromotion() reflect.Type
func (ConstIntType) IsIntegral ¶
func (ConstIntType) IsIntegral() bool
func (ConstIntType) IsNumeric ¶
func (ConstIntType) IsNumeric() bool
func (ConstIntType) IsReal ¶
func (ConstIntType) IsReal() bool
func (ConstIntType) String ¶
func (ConstIntType) String() string
type ConstNilType ¶
func (ConstNilType) DefaultPromotion ¶
func (c ConstNilType) DefaultPromotion() reflect.Type
func (ConstNilType) IsIntegral ¶
func (ConstNilType) IsIntegral() bool
func (ConstNilType) IsNumeric ¶
func (ConstNilType) IsNumeric() bool
func (ConstNilType) IsReal ¶
func (ConstNilType) IsReal() bool
func (ConstNilType) String ¶
func (ConstNilType) String() string
type ConstNumber ¶
type ConstNumber struct { Value BigComplex Type ConstType }
func NewConstComplex128 ¶
func NewConstComplex128(c complex128) *ConstNumber
func NewConstFloat ¶
func NewConstFloat(r string) (*ConstNumber, bool)
Use with token.FLOAT ast.BasicLit
func NewConstFloat64 ¶
func NewConstFloat64(f float64) *ConstNumber
func NewConstImag ¶
func NewConstImag(i string) (*ConstNumber, bool)
Use with token.IMAG ast.BasicLit
func NewConstInt64 ¶
func NewConstInt64(i int64) *ConstNumber
func NewConstInteger ¶
func NewConstInteger(i string) (*ConstNumber, bool)
Use with token.INT ast.BasicLit
func NewConstUint64 ¶
func NewConstUint64(u uint64) *ConstNumber
func (*ConstNumber) Add ¶
func (z *ConstNumber) Add(x, y *ConstNumber) *ConstNumber
Add two ConstNumbers, promoting the type automatically.
func (*ConstNumber) And ¶
func (z *ConstNumber) And(x, y *ConstNumber) *ConstNumber
z.And compute logical "and" of two ConstNumbers, promoting the type automatically. The result is undefined if both x and y are not integral types.
func (*ConstNumber) AndNot ¶
func (z *ConstNumber) AndNot(x, y *ConstNumber) *ConstNumber
z.AndNot computes "and not" of two ConstNumbers, promoting the type automatically. The result is undefined if both x and y are not integral types.
func (*ConstNumber) Lsh ¶
func (z *ConstNumber) Lsh(x *ConstNumber, count uint) *ConstNumber
z.Shl() shifts x left by count. Type is set to ConstShiftedInt
func (*ConstNumber) Mul ¶
func (z *ConstNumber) Mul(x, y *ConstNumber) *ConstNumber
z.Mul multiplies two ConstNumbers, promoting the type automatically.
func (*ConstNumber) Or ¶
func (z *ConstNumber) Or(x, y *ConstNumber) *ConstNumber
z.Or computes the logical "o"r of two ConstNumbers, promoting the type automatically. The result is undefined if both x and y are not integral types.
func (*ConstNumber) Quo ¶
func (z *ConstNumber) Quo(x, y *ConstNumber) *ConstNumber
z.Quo divides two ConstNumbers, promoting the type automatically. If both operands are of ConstInt, then integer division is performed.
func (*ConstNumber) Rem ¶
func (z *ConstNumber) Rem(x, y *ConstNumber) *ConstNumber
z.Rem computes remainder of two ConstNumbers, promoting the type automatically. The result is undefined if both x and y are not integral types.
func (*ConstNumber) Rsh ¶
func (z *ConstNumber) Rsh(x *ConstNumber, count uint) *ConstNumber
z.Shl() shifts x right by count. Type is set to ConstShiftedInt
func (*ConstNumber) String ¶
func (z *ConstNumber) String() string
func (*ConstNumber) StringShow0i ¶
func (z *ConstNumber) StringShow0i(show0i bool) string
func (*ConstNumber) Sub ¶
func (z *ConstNumber) Sub(x, y *ConstNumber) *ConstNumber
z.Sub() subtracts two ConstNumbers, promoting the type automatically.
func (*ConstNumber) Xor ¶
func (z *ConstNumber) Xor(x, y *ConstNumber) *ConstNumber
z.Xor computes the exclusive "or" of two ConstNumbers, promoting the type automatically. The result is undefined if both x and y are not integral types.
type ConstRuneType ¶
func (ConstRuneType) DefaultPromotion ¶
func (c ConstRuneType) DefaultPromotion() reflect.Type
func (ConstRuneType) IsIntegral ¶
func (ConstRuneType) IsIntegral() bool
func (ConstRuneType) IsNumeric ¶
func (ConstRuneType) IsNumeric() bool
func (ConstRuneType) IsReal ¶
func (ConstRuneType) IsReal() bool
func (ConstRuneType) String ¶
func (ConstRuneType) String() string
type ConstShiftedIntType ¶
func (ConstShiftedIntType) DefaultPromotion ¶
func (c ConstShiftedIntType) DefaultPromotion() reflect.Type
func (ConstShiftedIntType) IsIntegral ¶
func (ConstShiftedIntType) IsIntegral() bool
func (ConstShiftedIntType) IsNumeric ¶
func (ConstShiftedIntType) IsNumeric() bool
func (ConstShiftedIntType) IsReal ¶
func (ConstShiftedIntType) IsReal() bool
func (ConstShiftedIntType) String ¶
func (ConstShiftedIntType) String() string
type ConstStringType ¶
func (ConstStringType) DefaultPromotion ¶
func (c ConstStringType) DefaultPromotion() reflect.Type
func (ConstStringType) IsIntegral ¶
func (ConstStringType) IsIntegral() bool
func (ConstStringType) IsNumeric ¶
func (ConstStringType) IsNumeric() bool
func (ConstStringType) IsReal ¶
func (ConstStringType) IsReal() bool
func (ConstStringType) String ¶
func (ConstStringType) String() string
type ConstType ¶
type ConstType interface { reflect.Type IsIntegral() bool IsReal() bool IsNumeric() bool // The go type the ConstType is promoted to by default DefaultPromotion() reflect.Type }
Type ConstType can annotate information needed for evaluating const expressions. It should not be used with the reflect package.
type Env ¶
type Env interface { // Return a pointer value to the variable ident if defined in the top scope, or reflect.Value{} otherwise Var(ident string) reflect.Value // Return the const value ident if defined in the top scope, or reflect.Value{} otherwise Const(ident string) reflect.Value // Return the func value ident if defined in the top scope, or reflect.Value{} otherwise Func(ident string) reflect.Value // Return the type ident if defined in the top scope, or reflect.Value{} otherwise Type(ident string) reflect.Type // Return the environment containing vars, consts, funcs and types of pkg, or nil if not defined. // Unlike other lookup methods, packages exist only in the root scope. Pkg(pkg string) Env // Create a new block scope. Only the behaviour of the returned Env should change PushScope() Env // Pop the top block scope. Only the behaviour of the returned Env should change PopScope() Env // Add var ident to the top scope. The value is always a pointer value, and this same value should be // returned by Var(ident). It is up to the implementation how to handle duplicate identifiers. AddVar(ident string, v reflect.Value) // Add const ident to the top scope. It is up to the implementation how to handle duplicate identifiers. AddConst(ident string, c reflect.Value) // Add func ident to the top scope. It is up to the implementation how to handle duplicate identifiers. AddFunc(ident string, f reflect.Value) // Add type ident to the top scope. It is up to the implementation how to handle duplicate identifiers. AddType(ident string, t reflect.Type) // Add pkg to the root scope. It is up to the implementation how to handle duplicate identifiers. AddPkg(pkg string, p Env) }
A Environment used for evaluation
type ErrAppendFirstArgNotSlice ¶
type ErrAppendFirstArgNotSlice struct {
Expr
}
func (ErrAppendFirstArgNotSlice) Error ¶
func (err ErrAppendFirstArgNotSlice) Error() string
type ErrAppendFirstArgNotVariadic ¶
type ErrAppendFirstArgNotVariadic struct {
Expr
}
func (ErrAppendFirstArgNotVariadic) Error ¶
func (err ErrAppendFirstArgNotVariadic) Error() string
type ErrArrayKeyOutOfBounds ¶
type ErrArrayKeyOutOfBounds struct { Expr // contains filtered or unexported fields }
func (ErrArrayKeyOutOfBounds) Error ¶
func (err ErrArrayKeyOutOfBounds) Error() string
type ErrAssignCountMismatch ¶
type ErrAssignCountMismatch struct { *AssignStmt // contains filtered or unexported fields }
func (ErrAssignCountMismatch) Error ¶
func (err ErrAssignCountMismatch) Error() string
type ErrBadArrayKey ¶
type ErrBadArrayKey struct {
Expr
}
func (ErrBadArrayKey) Error ¶
func (ErrBadArrayKey) Error() string
type ErrBadArrayValue ¶
type ErrBadArrayValue struct { Expr // contains filtered or unexported fields }
func (ErrBadArrayValue) Error ¶
func (err ErrBadArrayValue) Error() string
type ErrBadBasicLit ¶
type ErrBadBasicLit struct {
*BasicLit
}
func (ErrBadBasicLit) Error ¶
func (err ErrBadBasicLit) Error() string
type ErrBadConstConversion ¶
type ErrBadConstConversion struct { Expr // contains filtered or unexported fields }
func (ErrBadConstConversion) Error ¶
func (err ErrBadConstConversion) Error() string
type ErrBadConversion ¶
type ErrBadConversion struct { Expr // contains filtered or unexported fields }
func (ErrBadConversion) Error ¶
func (err ErrBadConversion) Error() string
type ErrBadMapIndex ¶
type ErrBadMapIndex struct { Expr // contains filtered or unexported fields }
func (ErrBadMapIndex) Error ¶
func (err ErrBadMapIndex) Error() string
type ErrBadMapKey ¶
type ErrBadMapKey struct { Expr // contains filtered or unexported fields }
func (ErrBadMapKey) Error ¶
func (err ErrBadMapKey) Error() string
type ErrBadMapValue ¶
type ErrBadMapValue struct { Expr // contains filtered or unexported fields }
func (ErrBadMapValue) Error ¶
func (err ErrBadMapValue) Error() string
type ErrBadReturnValue ¶
type ErrBadReturnValue struct { Expr // contains filtered or unexported fields }
func (ErrBadReturnValue) Error ¶
func (err ErrBadReturnValue) Error() string
type ErrBadStructValue ¶
type ErrBadStructValue struct { Expr // contains filtered or unexported fields }
func (ErrBadStructValue) Error ¶
func (err ErrBadStructValue) Error() string
type ErrBuiltinInvalidEllipsis ¶
type ErrBuiltinInvalidEllipsis struct {
*CallExpr
}
func (ErrBuiltinInvalidEllipsis) Error ¶
func (err ErrBuiltinInvalidEllipsis) Error() string
type ErrBuiltinMismatchedArgs ¶
type ErrBuiltinMismatchedArgs struct { *CallExpr // contains filtered or unexported fields }
func (ErrBuiltinMismatchedArgs) Error ¶
func (err ErrBuiltinMismatchedArgs) Error() string
type ErrBuiltinNonTypeArg ¶
type ErrBuiltinNonTypeArg struct {
Expr
}
func (ErrBuiltinNonTypeArg) Error ¶
func (err ErrBuiltinNonTypeArg) Error() string
type ErrBuiltinWrongArgType ¶
type ErrBuiltinWrongArgType struct { Expr // contains filtered or unexported fields }
func (ErrBuiltinWrongArgType) Error ¶
func (err ErrBuiltinWrongArgType) Error() string
type ErrBuiltinWrongNumberOfArgs ¶
type ErrBuiltinWrongNumberOfArgs struct {
*CallExpr
}
func (ErrBuiltinWrongNumberOfArgs) Error ¶
func (err ErrBuiltinWrongNumberOfArgs) Error() string
type ErrCallNonFuncType ¶
type ErrCallNonFuncType struct {
Expr
}
func (ErrCallNonFuncType) Error ¶
func (err ErrCallNonFuncType) Error() string
type ErrCannotAssignToType ¶
type ErrCannotAssignToType struct { Expr //lhs // contains filtered or unexported fields }
func (ErrCannotAssignToType) Error ¶
func (err ErrCannotAssignToType) Error() string
type ErrCannotAssignToUnaddressable ¶
type ErrCannotAssignToUnaddressable struct {
Expr
}
func (ErrCannotAssignToUnaddressable) Error ¶
func (err ErrCannotAssignToUnaddressable) Error() string
type ErrCopyArgsHaveDifferentEltTypes ¶
type ErrCopyArgsHaveDifferentEltTypes struct { *CallExpr // contains filtered or unexported fields }
func (ErrCopyArgsHaveDifferentEltTypes) Error ¶
func (err ErrCopyArgsHaveDifferentEltTypes) Error() string
type ErrCopyArgsMustBeSlices ¶
type ErrCopyArgsMustBeSlices struct { *CallExpr // contains filtered or unexported fields }
func (ErrCopyArgsMustBeSlices) Error ¶
func (err ErrCopyArgsMustBeSlices) Error() string
type ErrDeleteFirstArgNotMap ¶
type ErrDeleteFirstArgNotMap struct {
Expr
}
func (ErrDeleteFirstArgNotMap) Error ¶
func (err ErrDeleteFirstArgNotMap) Error() string
type ErrDivideByZero ¶
type ErrDivideByZero struct {
*BinaryExpr
}
func (ErrDivideByZero) Error ¶
func (err ErrDivideByZero) Error() string
type ErrDuplicateArg ¶
type ErrDuplicateArg struct {
*Ident
}
func (ErrDuplicateArg) Error ¶
func (err ErrDuplicateArg) Error() string
type ErrDuplicateArrayKey ¶
type ErrDuplicateArrayKey struct { Expr // contains filtered or unexported fields }
func (ErrDuplicateArrayKey) Error ¶
func (err ErrDuplicateArrayKey) Error() string
type ErrDuplicateMapKey ¶
type ErrDuplicateMapKey struct {
Expr
}
func (ErrDuplicateMapKey) Error ¶
func (err ErrDuplicateMapKey) Error() string
type ErrDuplicateStructField ¶
type ErrDuplicateStructField struct { *Ident // contains filtered or unexported fields }
func (ErrDuplicateStructField) Error ¶
func (err ErrDuplicateStructField) Error() string
type ErrImpossibleTypeAssert ¶
type ErrImpossibleTypeAssert struct {
*TypeAssertExpr
}
func (ErrImpossibleTypeAssert) Error ¶
func (err ErrImpossibleTypeAssert) Error() string
type ErrImpossibleTypeCase ¶
type ErrImpossibleTypeCase struct { Expr // contains filtered or unexported fields }
func (ErrImpossibleTypeCase) Error ¶
func (err ErrImpossibleTypeCase) Error() string
type ErrIndexOutOfBounds ¶
type ErrIndexOutOfBounds struct { Expr // contains filtered or unexported fields }
func (ErrIndexOutOfBounds) Error ¶
func (err ErrIndexOutOfBounds) Error() string
type ErrInvalidAddressOf ¶
type ErrInvalidAddressOf struct {
Expr
}
func (ErrInvalidAddressOf) Error ¶
func (err ErrInvalidAddressOf) Error() string
type ErrInvalidBinaryOperation ¶
type ErrInvalidBinaryOperation struct {
*BinaryExpr
}
func (ErrInvalidBinaryOperation) Error ¶
func (err ErrInvalidBinaryOperation) Error() string
type ErrInvalidCase ¶
type ErrInvalidCase struct { Expr // contains filtered or unexported fields }
func (ErrInvalidCase) Error ¶
func (err ErrInvalidCase) Error() string
type ErrInvalidEllipsisInCall ¶
type ErrInvalidEllipsisInCall struct {
*CallExpr
}
func (ErrInvalidEllipsisInCall) Error ¶
func (err ErrInvalidEllipsisInCall) Error() string
type ErrInvalidIndex ¶
type ErrInvalidIndex struct { Expr // contains filtered or unexported fields }
type ErrInvalidIndexOperation ¶
type ErrInvalidIndexOperation struct {
*IndexExpr
}
func (ErrInvalidIndexOperation) Error ¶
func (err ErrInvalidIndexOperation) Error() string
type ErrInvalidIndirect ¶
type ErrInvalidIndirect struct {
Expr
}
func (ErrInvalidIndirect) Error ¶
func (err ErrInvalidIndirect) Error() string
type ErrInvalidRecvFrom ¶
type ErrInvalidRecvFrom struct {
Expr
}
func (ErrInvalidRecvFrom) Error ¶
func (err ErrInvalidRecvFrom) Error() string
type ErrInvalidSliceIndex ¶
type ErrInvalidSliceIndex struct {
*SliceExpr
}
func (ErrInvalidSliceIndex) Error ¶
func (err ErrInvalidSliceIndex) Error() string
type ErrInvalidSliceOperation ¶
type ErrInvalidSliceOperation struct {
*SliceExpr
}
func (ErrInvalidSliceOperation) Error ¶
func (err ErrInvalidSliceOperation) Error() string
type ErrInvalidStructField ¶
type ErrInvalidStructField struct {
Expr
}
func (ErrInvalidStructField) Error ¶
func (err ErrInvalidStructField) Error() string
type ErrInvalidTypeAssert ¶
type ErrInvalidTypeAssert struct {
*TypeAssertExpr
}
func (ErrInvalidTypeAssert) Error ¶
func (err ErrInvalidTypeAssert) Error() string
type ErrInvalidUnaryOperation ¶
type ErrInvalidUnaryOperation struct {
*UnaryExpr
}
func (ErrInvalidUnaryOperation) Error ¶
func (err ErrInvalidUnaryOperation) Error() string
type ErrMakeBadType ¶
type ErrMakeBadType struct { Expr // contains filtered or unexported fields }
func (ErrMakeBadType) Error ¶
func (err ErrMakeBadType) Error() string
type ErrMakeLenGtrThanCap ¶
type ErrMakeLenGtrThanCap struct { *CallExpr // contains filtered or unexported fields }
func (ErrMakeLenGtrThanCap) Error ¶
func (err ErrMakeLenGtrThanCap) Error() string
type ErrMakeNonIntegerArg ¶
type ErrMakeNonIntegerArg struct { Expr // contains filtered or unexported fields }
func (ErrMakeNonIntegerArg) Error ¶
func (err ErrMakeNonIntegerArg) Error() string
type ErrMissingCompositeLitType ¶
type ErrMissingCompositeLitType struct {
*CompositeLit
}
func (ErrMissingCompositeLitType) Error ¶
func (err ErrMissingCompositeLitType) Error() string
type ErrMissingMapKey ¶
type ErrMissingMapKey struct {
Expr
}
func (ErrMissingMapKey) Error ¶
func (err ErrMissingMapKey) Error() string
type ErrMissingValue ¶
type ErrMissingValue struct {
Expr
}
func (ErrMissingValue) Error ¶
func (err ErrMissingValue) Error() string
type ErrMixedStructValues ¶
type ErrMixedStructValues struct {
Expr
}
func (ErrMixedStructValues) Error ¶
func (err ErrMixedStructValues) Error() string
type ErrMultiInSingleContext ¶
type ErrMultiInSingleContext struct {
Expr
}
func (ErrMultiInSingleContext) Error ¶
func (err ErrMultiInSingleContext) Error() string
type ErrNoNewNamesInDeclaration ¶
type ErrNoNewNamesInDeclaration struct {
*AssignStmt
}
func (ErrNoNewNamesInDeclaration) Error ¶
func (err ErrNoNewNamesInDeclaration) Error() string
type ErrNonBoolCondition ¶
type ErrNonBoolCondition struct { Expr // contains filtered or unexported fields }
func (ErrNonBoolCondition) Error ¶
func (err ErrNonBoolCondition) Error() string
type ErrNonIntegerIndex ¶
type ErrNonIntegerIndex struct {
Expr
}
func (ErrNonIntegerIndex) Error ¶
func (err ErrNonIntegerIndex) Error() string
type ErrNonInterfaceTypeSwitch ¶
type ErrNonInterfaceTypeSwitch struct {
Expr
}
func (ErrNonInterfaceTypeSwitch) Error ¶
func (err ErrNonInterfaceTypeSwitch) Error() string
type ErrNonNameInDeclaration ¶
type ErrNonNameInDeclaration struct {
Expr
}
func (ErrNonNameInDeclaration) Error ¶
func (err ErrNonNameInDeclaration) Error() string
type ErrOverflowedConstant ¶
type ErrOverflowedConstant struct { Expr // contains filtered or unexported fields }
func (ErrOverflowedConstant) Error ¶
func (err ErrOverflowedConstant) Error() string
type ErrStupidShift ¶
type ErrStupidShift struct { Expr // contains filtered or unexported fields }
func (ErrStupidShift) Error ¶
func (err ErrStupidShift) Error() string
type ErrTruncatedConstant ¶
type ErrTruncatedConstant struct { Expr // contains filtered or unexported fields }
func (ErrTruncatedConstant) Error ¶
func (err ErrTruncatedConstant) Error() string
type ErrTypeUsedAsExpression ¶
type ErrTypeUsedAsExpression struct {
Expr
}
func (ErrTypeUsedAsExpression) Error ¶
func (err ErrTypeUsedAsExpression) Error() string
type ErrUnaddressableSliceOperand ¶
type ErrUnaddressableSliceOperand struct {
*SliceExpr
}
func (ErrUnaddressableSliceOperand) Error ¶
func (err ErrUnaddressableSliceOperand) Error() string
type ErrUncomparableMapKey ¶
type ErrUncomparableMapKey struct { Expr // contains filtered or unexported fields }
func (ErrUncomparableMapKey) Error ¶
func (err ErrUncomparableMapKey) Error() string
type ErrUndefined ¶
type ErrUndefined struct {
Expr
}
func (ErrUndefined) Error ¶
func (err ErrUndefined) Error() string
type ErrUndefinedFieldOrMethod ¶
type ErrUndefinedFieldOrMethod struct {
Expr
}
func (ErrUndefinedFieldOrMethod) Error ¶
func (err ErrUndefinedFieldOrMethod) Error() string
type ErrUnknownStructField ¶
type ErrUnknownStructField struct { Expr // contains filtered or unexported fields }
func (ErrUnknownStructField) Error ¶
func (err ErrUnknownStructField) Error() string
type ErrUntypedNil ¶
type ErrUntypedNil struct {
Expr
}
func (ErrUntypedNil) Error ¶
func (ErrUntypedNil) Error() string
type ErrWrongArgType ¶
type ErrWrongArgType struct { Expr // contains filtered or unexported fields }
func (ErrWrongArgType) Error ¶
func (err ErrWrongArgType) Error() string
type ErrWrongNumberOfArgs ¶
type ErrWrongNumberOfArgs struct { *CallExpr // contains filtered or unexported fields }
func (ErrWrongNumberOfArgs) Error ¶
func (err ErrWrongNumberOfArgs) Error() string
type ErrWrongNumberOfReturnValues ¶
type ErrWrongNumberOfReturnValues struct { *ReturnStmt // contains filtered or unexported fields }
func (ErrWrongNumberOfReturnValues) Error ¶
func (err ErrWrongNumberOfReturnValues) Error() string
type ErrWrongNumberOfStructValues ¶
type ErrWrongNumberOfStructValues struct {
*CompositeLit
}
func (ErrWrongNumberOfStructValues) Error ¶
func (err ErrWrongNumberOfStructValues) Error() string
type Expr ¶
type Expr interface { ast.Expr // The type of this expression if known. Certain expr types have special interpretations // Constant expr: a ConstType will be returned if constant is untyped // Ellipsis expr: a single reflect.Type represents the type of all unpacked values KnownType() []reflect.Type // Returns true if this expression evaluates to a constant. In this // case, Value() will return the evalutated constant. Nodes below // this expression can be ignored. IsConst() bool // Returns the const value, if known. Const() reflect.Value // String() matches the print format of expressions in go errors String() string // contains filtered or unexported methods }
Annotated ast.Expr nodes
func CheckExpr ¶
Type check an ast.Expr to produce an Expr. Errors are accumulated and returned as a single slice. When evaluating constant expressions, non fatal truncation/overflow errors may be raised but type checking will continue. A common pattern to detect errors is
if expr, errs := CheckExpr(...); errs != nil && !expr.IsConst() { fatal }
if expr.IsConst() is true, then the resulting Expr has been successfully checked, regardless of if errors are present.
type FuncLit ¶
type FuncType ¶
type IndexExpr ¶
type InterfaceType ¶
type InterfaceType struct { *ast.InterfaceType // contains filtered or unexported fields }
func (*InterfaceType) Const ¶
func (*InterfaceType) Const() reflect.Value
func (*InterfaceType) IsConst ¶
func (*InterfaceType) IsConst() bool
func (*InterfaceType) String ¶
func (interfaceType *InterfaceType) String() string
type KeyValueExpr ¶
type KeyValueExpr struct { *ast.KeyValueExpr Key Expr Value Expr }
func (*KeyValueExpr) Const ¶
func (*KeyValueExpr) Const() reflect.Value
func (*KeyValueExpr) IsConst ¶
func (*KeyValueExpr) IsConst() bool
func (*KeyValueExpr) KnownType ¶
func (*KeyValueExpr) KnownType() []reflect.Type
func (*KeyValueExpr) String ¶
func (keyValueExpr *KeyValueExpr) String() string
type LabeledStmt ¶
type LabeledStmt struct { *ast.LabeledStmt Label *Ident Stmt Stmt }
type PanicDivideByZero ¶
type PanicDivideByZero struct{}
func (PanicDivideByZero) Error ¶
func (err PanicDivideByZero) Error() string
type PanicIndexOutOfBounds ¶
type PanicIndexOutOfBounds struct{}
func (PanicIndexOutOfBounds) Error ¶
func (err PanicIndexOutOfBounds) Error() string
type PanicInterfaceConversion ¶
type PanicInterfaceConversion struct {
// contains filtered or unexported fields
}
func (PanicInterfaceConversion) Error ¶
func (err PanicInterfaceConversion) Error() string
type PanicInvalidDereference ¶
type PanicInvalidDereference struct{}
func (PanicInvalidDereference) Error ¶
func (err PanicInvalidDereference) Error() string
type PanicSliceOutOfBounds ¶
type PanicSliceOutOfBounds struct{}
func (PanicSliceOutOfBounds) Error ¶
func (err PanicSliceOutOfBounds) Error() string
type PanicUncomparableType ¶
type PanicUncomparableType struct {
// contains filtered or unexported fields
}
func (PanicUncomparableType) Error ¶
func (err PanicUncomparableType) Error() string
type PanicUnhashableType ¶
type PanicUnhashableType struct {
// contains filtered or unexported fields
}
func (PanicUnhashableType) Error ¶
func (err PanicUnhashableType) Error() string
type ReturnStmt ¶
type ReturnStmt struct { *ast.ReturnStmt Results []Expr }
type SelectorExpr ¶
type SelectorExpr struct { *ast.SelectorExpr X Expr Sel *Ident // contains filtered or unexported fields }
func (*SelectorExpr) String ¶
func (selectorExpr *SelectorExpr) String() string
type SimpleEnv ¶
type SimpleEnv struct { // path relative to GOROOT or GOPATH. e.g. github.com/0xfaded/eval Path string Parent *SimpleEnv Vars map[string]reflect.Value Funcs map[string]reflect.Value Consts map[string]reflect.Value Types map[string]reflect.Type Pkgs map[string]Env }
func MakeSimpleEnv ¶
func MakeSimpleEnv() *SimpleEnv
type SliceExpr ¶
type StructType ¶
type StructType struct { *ast.StructType // contains filtered or unexported fields }
func (*StructType) Const ¶
func (*StructType) Const() reflect.Value
func (*StructType) IsConst ¶
func (*StructType) IsConst() bool
func (*StructType) String ¶
func (structType *StructType) String() string
type SwitchStmt ¶
type SwitchStmt struct { *ast.SwitchStmt Init Stmt Tag Expr Body *BlockStmt // contains filtered or unexported fields }
type TypeAssertExpr ¶
type TypeAssertExpr struct { *ast.TypeAssertExpr X Expr Type Expr // contains filtered or unexported fields }
func (*TypeAssertExpr) Const ¶
func (*TypeAssertExpr) Const() reflect.Value
func (*TypeAssertExpr) IsConst ¶
func (*TypeAssertExpr) IsConst() bool
func (*TypeAssertExpr) String ¶
func (assert *TypeAssertExpr) String() string
type TypeSwitchStmt ¶
type TypeSwitchStmt struct { *ast.TypeSwitchStmt Init Stmt Assign Stmt Body *BlockStmt // contains filtered or unexported fields }
func (*TypeSwitchStmt) Name ¶
func (typeswitch *TypeSwitchStmt) Name() string
func (*TypeSwitchStmt) Tag ¶
func (typeswitch *TypeSwitchStmt) Tag() Expr
type UntypedNil ¶
type UntypedNil struct{}
func (UntypedNil) String ¶
func (UntypedNil) String() string
Source Files ¶
- ast.go
- bigcomplex.go
- builtins.go
- bytetype.go
- checkbasiclit.go
- checkbinaryexpr.go
- checkbuiltin.go
- checkcallexpr.go
- checkcompositelit.go
- checkexpr.go
- checkfunclit.go
- checkident.go
- checkindexexpr.go
- checkparenexpr.go
- checkselectorexpr.go
- checksliceexpr.go
- checkstarexpr.go
- checkstmt.go
- checktypeassertexpr.go
- checkunaryexpr.go
- constnumber.go
- consttype.go
- didyoutypecheck.go
- doc.go
- env.go
- errors.go
- eval.go
- evalbasiclit.go
- evalbinaryexpr.go
- evalbuiltin.go
- evalcallexpr.go
- evalcompositelit.go
- evalexpr.go
- evalfunclit.go
- evalident.go
- evalindexexpr.go
- evalselectorexpr.go
- evalsliceexpr.go
- evalstarexpr.go
- evaltypeassertexpr.go
- evalunaryexpr.go
- fakecheck.go
- inspect.go
- interpstmt.go
- panics.go
- runetype.go
- untypednil.go
- util.go
- walk.go
Directories ¶
Path | Synopsis |
---|---|
Example repl is a simple REPL (read-eval-print loop) for GO using http://github.com/0xfaded/eval to the heavy lifting to implement the eval() part.
|
Example repl is a simple REPL (read-eval-print loop) for GO using http://github.com/0xfaded/eval to the heavy lifting to implement the eval() part. |