eval

package module
v0.0.0-...-d746062 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2014 License: BSD-3-Clause Imports: 13 Imported by: 1

README

eval - A library for providing an eval function in Go

Build Status

This project adds an Eval() function to go.

Right now only, Go expressions are handled.

Using

The simplest invocation is

	results, panik, compileErrs := Eval("1 + 2")
	// results = []reflect.Value{reflect.ValueOf(3)}
	// panik = error(nil)
	// compileErrs = []error(nil)

Results are reflect.Values, and in reality Eval is nothing more than a fancy wrapper around the reflect package. Runtime panics should be detected during evaluation and returned as panik, if an actual runtime panic occurs please file a bug. Any parse or type errors are returned as compileErrs; it is nil otherwise.

EvalEnv evaluates an expression inside an environment containing variables, constants, functions, types and packages.

	type T int
	x := 1
	sum := func(xs ...int) (result int) {
		for _, x := range xs {
			result += x
		}
		return result
	}
	env := eval.MakeSimpleEnv()
	// Note the &x
	env.Vars["x"] = reflect.ValueOf(&x)
	env.Funcs["sum"] = reflect.ValueOf(f)
	env.Types["T"] = reflect.TypeOf(T(0))
	pkg := MakeSimpleEnv()
	pkg.Consts["C"] = reflect.ValueOf(2)
	env.Pkgs["pkg"] = pkg
	results, panik, compileErrs := EvalEnv("T(sum(1, x, pkg.C))", env)

Extended API

The extented API allows step by step execution of the evaluator. The dance is three part

  • Parse
  • Check
  • Eval
	env := eval.MakeSimpleEnv()
	if expr, err := parser.ParseExpr(expr); err != nil {
		fmt.Printf("parse error: %s\n", err)
	} else if cexpr, errs := eval.CheckExpr(expr, env); len(errs) != 0 {
		for _, cerr := range errs {
			fmt.Printf("%v\n", cerr)
		}
	} else if vals, _, err := eval.EvalExpr(cexpr, env); err != nil {
		fmt.Printf("eval error: %s\n", err)
	} else {
	  // do something with pointer to reflect.Value array vals, e.g.:
	  fmt.Println(vals[0].Interface())
	}

The program repl.go is a full Go program showing this.

Limitations

Eval is currently limited to the functionality of the reflect package.

Most noteably, the following are not implemented as they cannot be created:

  • struct literals
  • array literals
  • function literals

Struct and Array composite named types can still be constructed. E.g.

	env.Types["A"] = reflect.TypeOf([2]int{})
	EvalEnv("A{1, 2}", env)

In theory this could also work for named Function literals, but this has not been implemented.

See Also

  • What's left to do?
  • go-fish: an interactive read, eval, print loop which uses this to handle the eval() step. In that project, see the program make_eval for how to create a complete environment given an initial import.
  • gack: another experimental REPL which implements import by continuously recompiling the executable.
  • gub debugger: a debugger that uses this to handle the eval debugger command

Documentation

Index

Constants

This section is empty.

Variables

View Source
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)}
)
View Source
var ByteType = Byte{reflect.TypeOf(byte(0))}
View Source
var RuneType = Rune{reflect.TypeOf(rune(0))}

Functions

func Eval

func Eval(expr string) (result []reflect.Value, panik error, compileErrors []error)

func EvalEnv

func EvalEnv(expr string, env Env) (result []reflect.Value, panik error, compileErrors []error)

func EvalExpr

func EvalExpr(expr Expr, env Env) ([]reflect.Value, error)

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

func FormatErrorPos(source, errmsg string) (cursored []string)

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

func Inspect(val reflect.Value) string

Inspect prints a reflect.Value the way you would enter it. Some like this should really be part of the reflect package.

func InspectShort

func InspectShort(val reflect.Value) string

Returns type{...} for composite lits

func Interpret

func Interpret(stmt string, env Env) (result []reflect.Value, panik error, compileErrors []error)

func ParseStmt

func ParseStmt(stmt string) (ast.Stmt, error)

A convenience function for parsing a Stmt by wrapping it in a func literal

Types

type ArrayType

type ArrayType struct {
	*ast.ArrayType
	Len Expr
	Elt Expr
	// contains filtered or unexported fields
}

func (*ArrayType) Const

func (*ArrayType) Const() reflect.Value

func (*ArrayType) IsConst

func (*ArrayType) IsConst() bool

func (ArrayType) KnownType

func (t ArrayType) KnownType() []reflect.Type

func (*ArrayType) String

func (arrayType *ArrayType) String() string

type AssignStmt

type AssignStmt struct {
	*ast.AssignStmt
	Lhs []Expr
	Rhs []Expr
	// contains filtered or unexported fields
}

type BadExpr

type BadExpr struct {
	*ast.BadExpr
}

func (*BadExpr) Const

func (*BadExpr) Const() reflect.Value

func (*BadExpr) IsConst

func (*BadExpr) IsConst() bool

func (*BadExpr) KnownType

func (*BadExpr) KnownType() []reflect.Type

func (*BadExpr) String

func (badExpr *BadExpr) String() string

type BasicLit

type BasicLit struct {
	*ast.BasicLit
	// contains filtered or unexported fields
}

func (BasicLit) Const

func (c BasicLit) Const() reflect.Value

func (BasicLit) IsConst

func (c BasicLit) IsConst() bool

func (BasicLit) KnownType

func (t BasicLit) KnownType() []reflect.Type

func (*BasicLit) String

func (basicLit *BasicLit) String() string

type BigComplex

type BigComplex struct {
	Re big.Rat
	Im big.Rat
}

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

func (c BinaryExpr) Const() reflect.Value

func (BinaryExpr) IsConst

func (c BinaryExpr) IsConst() bool

func (BinaryExpr) KnownType

func (t BinaryExpr) KnownType() []reflect.Type

func (BinaryExpr) Op

func (b BinaryExpr) Op() token.Token

func (*BinaryExpr) String

func (binary *BinaryExpr) String() string

type BlockStmt

type BlockStmt struct {
	*ast.BlockStmt
	List []Stmt
}

type BranchStmt

type BranchStmt struct {
	*ast.BranchStmt
	Label *Ident
}

type Byte

type Byte struct {
	reflect.Type
}

func (Byte) Name

func (Byte) Name() string

func (Byte) String

func (Byte) String() string

type CallExpr

type CallExpr struct {
	*ast.CallExpr
	Fun  Expr
	Args []Expr
	// contains filtered or unexported fields
}

func (CallExpr) Const

func (c CallExpr) Const() reflect.Value

func (CallExpr) IsConst

func (c CallExpr) IsConst() bool

func (CallExpr) KnownType

func (t CallExpr) KnownType() []reflect.Type

func (*CallExpr) String

func (call *CallExpr) String() string

type CaseClause

type CaseClause struct {
	*ast.CaseClause
	List []Expr
	Body []Stmt
}

type ChanType

type ChanType struct {
	*ast.ChanType
	Value Expr
	// contains filtered or unexported fields
}

func (*ChanType) Const

func (*ChanType) Const() reflect.Value

func (*ChanType) IsConst

func (*ChanType) IsConst() bool

func (ChanType) KnownType

func (t ChanType) KnownType() []reflect.Type

func (*ChanType) String

func (chanType *ChanType) String() string

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

func (t CompositeLit) KnownType() []reflect.Type

func (*CompositeLit) String

func (lit *CompositeLit) String() string

type ConstBoolType

type ConstBoolType struct{ reflect.Type }

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

type ConstComplexType struct{ reflect.Type }

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

type ConstFloatType struct{ reflect.Type }

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

type ConstIntType struct{ reflect.Type }

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

type ConstNilType struct{ reflect.Type }

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 NewConstRune

func NewConstRune(n rune) *ConstNumber

Use with token.CHAR 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

type ConstRuneType struct{ reflect.Type }

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

type ConstShiftedIntType struct{ reflect.Type }

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

type ConstStringType struct{ reflect.Type }

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 Ellipsis

type Ellipsis struct {
	*ast.Ellipsis
	// contains filtered or unexported fields
}

func (*Ellipsis) Const

func (*Ellipsis) Const() reflect.Value

func (*Ellipsis) IsConst

func (*Ellipsis) IsConst() bool

func (Ellipsis) KnownType

func (t Ellipsis) KnownType() []reflect.Type

func (*Ellipsis) String

func (ellipsis *Ellipsis) String() string

type EmptyStmt

type EmptyStmt struct {
	*ast.EmptyStmt
}

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

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

func (c ErrBadBasicLit) Const() reflect.Value

func (ErrBadBasicLit) Error

func (err ErrBadBasicLit) Error() string

func (ErrBadBasicLit) IsConst

func (c ErrBadBasicLit) IsConst() bool

func (ErrBadBasicLit) KnownType

func (t ErrBadBasicLit) KnownType() []reflect.Type

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

func (c ErrBuiltinInvalidEllipsis) Const() reflect.Value

func (ErrBuiltinInvalidEllipsis) Error

func (err ErrBuiltinInvalidEllipsis) Error() string

func (ErrBuiltinInvalidEllipsis) IsConst

func (c ErrBuiltinInvalidEllipsis) IsConst() bool

func (ErrBuiltinInvalidEllipsis) KnownType

func (t ErrBuiltinInvalidEllipsis) KnownType() []reflect.Type

type ErrBuiltinMismatchedArgs

type ErrBuiltinMismatchedArgs struct {
	*CallExpr
	// contains filtered or unexported fields
}

func (ErrBuiltinMismatchedArgs) Const

func (c ErrBuiltinMismatchedArgs) Const() reflect.Value

func (ErrBuiltinMismatchedArgs) Error

func (err ErrBuiltinMismatchedArgs) Error() string

func (ErrBuiltinMismatchedArgs) IsConst

func (c ErrBuiltinMismatchedArgs) IsConst() bool

func (ErrBuiltinMismatchedArgs) KnownType

func (t ErrBuiltinMismatchedArgs) KnownType() []reflect.Type

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

func (c ErrBuiltinWrongNumberOfArgs) Const() reflect.Value

func (ErrBuiltinWrongNumberOfArgs) Error

func (err ErrBuiltinWrongNumberOfArgs) Error() string

func (ErrBuiltinWrongNumberOfArgs) IsConst

func (c ErrBuiltinWrongNumberOfArgs) IsConst() bool

func (ErrBuiltinWrongNumberOfArgs) KnownType

func (t ErrBuiltinWrongNumberOfArgs) KnownType() []reflect.Type

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

type ErrCopyArgsHaveDifferentEltTypes

type ErrCopyArgsHaveDifferentEltTypes struct {
	*CallExpr
	// contains filtered or unexported fields
}

func (ErrCopyArgsHaveDifferentEltTypes) Const

func (c ErrCopyArgsHaveDifferentEltTypes) Const() reflect.Value

func (ErrCopyArgsHaveDifferentEltTypes) Error

func (ErrCopyArgsHaveDifferentEltTypes) IsConst

func (c ErrCopyArgsHaveDifferentEltTypes) IsConst() bool

func (ErrCopyArgsHaveDifferentEltTypes) KnownType

func (t ErrCopyArgsHaveDifferentEltTypes) KnownType() []reflect.Type

type ErrCopyArgsMustBeSlices

type ErrCopyArgsMustBeSlices struct {
	*CallExpr
	// contains filtered or unexported fields
}

func (ErrCopyArgsMustBeSlices) Const

func (c ErrCopyArgsMustBeSlices) Const() reflect.Value

func (ErrCopyArgsMustBeSlices) Error

func (err ErrCopyArgsMustBeSlices) Error() string

func (ErrCopyArgsMustBeSlices) IsConst

func (c ErrCopyArgsMustBeSlices) IsConst() bool

func (ErrCopyArgsMustBeSlices) KnownType

func (t ErrCopyArgsMustBeSlices) KnownType() []reflect.Type

type ErrDeleteFirstArgNotMap

type ErrDeleteFirstArgNotMap struct {
	Expr
}

func (ErrDeleteFirstArgNotMap) Error

func (err ErrDeleteFirstArgNotMap) Error() string

type ErrDivideByZero

type ErrDivideByZero struct {
	*BinaryExpr
}

func (ErrDivideByZero) Const

func (c ErrDivideByZero) Const() reflect.Value

func (ErrDivideByZero) Error

func (err ErrDivideByZero) Error() string

func (ErrDivideByZero) IsConst

func (c ErrDivideByZero) IsConst() bool

func (ErrDivideByZero) KnownType

func (t ErrDivideByZero) KnownType() []reflect.Type

type ErrDuplicateArg

type ErrDuplicateArg struct {
	*Ident
}

func (ErrDuplicateArg) Const

func (c ErrDuplicateArg) Const() reflect.Value

func (ErrDuplicateArg) Error

func (err ErrDuplicateArg) Error() string

func (ErrDuplicateArg) IsConst

func (c ErrDuplicateArg) IsConst() bool

func (ErrDuplicateArg) KnownType

func (t ErrDuplicateArg) KnownType() []reflect.Type

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

func (c ErrDuplicateStructField) Const() reflect.Value

func (ErrDuplicateStructField) Error

func (err ErrDuplicateStructField) Error() string

func (ErrDuplicateStructField) IsConst

func (c ErrDuplicateStructField) IsConst() bool

func (ErrDuplicateStructField) KnownType

func (t ErrDuplicateStructField) KnownType() []reflect.Type

type ErrImpossibleTypeAssert

type ErrImpossibleTypeAssert struct {
	*TypeAssertExpr
}

func (ErrImpossibleTypeAssert) Error

func (err ErrImpossibleTypeAssert) Error() string

func (ErrImpossibleTypeAssert) KnownType

func (t ErrImpossibleTypeAssert) KnownType() []reflect.Type

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

func (c ErrInvalidBinaryOperation) Const() reflect.Value

func (ErrInvalidBinaryOperation) Error

func (err ErrInvalidBinaryOperation) Error() string

func (ErrInvalidBinaryOperation) IsConst

func (c ErrInvalidBinaryOperation) IsConst() bool

func (ErrInvalidBinaryOperation) KnownType

func (t ErrInvalidBinaryOperation) KnownType() []reflect.Type

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

func (c ErrInvalidEllipsisInCall) Const() reflect.Value

func (ErrInvalidEllipsisInCall) Error

func (err ErrInvalidEllipsisInCall) Error() string

func (ErrInvalidEllipsisInCall) IsConst

func (c ErrInvalidEllipsisInCall) IsConst() bool

func (ErrInvalidEllipsisInCall) KnownType

func (t ErrInvalidEllipsisInCall) KnownType() []reflect.Type

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

func (ErrInvalidIndexOperation) KnownType

func (t ErrInvalidIndexOperation) KnownType() []reflect.Type

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

func (ErrInvalidSliceIndex) KnownType

func (t ErrInvalidSliceIndex) KnownType() []reflect.Type

type ErrInvalidSliceOperation

type ErrInvalidSliceOperation struct {
	*SliceExpr
}

func (ErrInvalidSliceOperation) Error

func (err ErrInvalidSliceOperation) Error() string

func (ErrInvalidSliceOperation) KnownType

func (t ErrInvalidSliceOperation) KnownType() []reflect.Type

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

func (ErrInvalidTypeAssert) KnownType

func (t ErrInvalidTypeAssert) KnownType() []reflect.Type

type ErrInvalidUnaryOperation

type ErrInvalidUnaryOperation struct {
	*UnaryExpr
}

func (ErrInvalidUnaryOperation) Const

func (c ErrInvalidUnaryOperation) Const() reflect.Value

func (ErrInvalidUnaryOperation) Error

func (err ErrInvalidUnaryOperation) Error() string

func (ErrInvalidUnaryOperation) IsConst

func (c ErrInvalidUnaryOperation) IsConst() bool

func (ErrInvalidUnaryOperation) KnownType

func (t ErrInvalidUnaryOperation) KnownType() []reflect.Type

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

func (c ErrMakeLenGtrThanCap) Const() reflect.Value

func (ErrMakeLenGtrThanCap) Error

func (err ErrMakeLenGtrThanCap) Error() string

func (ErrMakeLenGtrThanCap) IsConst

func (c ErrMakeLenGtrThanCap) IsConst() bool

func (ErrMakeLenGtrThanCap) KnownType

func (t ErrMakeLenGtrThanCap) KnownType() []reflect.Type

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

func (ErrMissingCompositeLitType) KnownType

func (t ErrMissingCompositeLitType) KnownType() []reflect.Type

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 (ErrUnaddressableSliceOperand) KnownType

func (t ErrUnaddressableSliceOperand) KnownType() []reflect.Type

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

func (c ErrWrongNumberOfArgs) Const() reflect.Value

func (ErrWrongNumberOfArgs) Error

func (err ErrWrongNumberOfArgs) Error() string

func (ErrWrongNumberOfArgs) IsConst

func (c ErrWrongNumberOfArgs) IsConst() bool

func (ErrWrongNumberOfArgs) KnownType

func (t ErrWrongNumberOfArgs) KnownType() []reflect.Type

type ErrWrongNumberOfReturnValues

type ErrWrongNumberOfReturnValues struct {
	*ReturnStmt
	// contains filtered or unexported fields
}

func (ErrWrongNumberOfReturnValues) Error

type ErrWrongNumberOfStructValues

type ErrWrongNumberOfStructValues struct {
	*CompositeLit
}

func (ErrWrongNumberOfStructValues) Error

func (ErrWrongNumberOfStructValues) KnownType

func (t ErrWrongNumberOfStructValues) KnownType() []reflect.Type

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

func CheckExpr(expr ast.Expr, env Env) (Expr, []error)

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 ExprStmt

type ExprStmt struct {
	*ast.ExprStmt
	X Expr
}

type Field

type Field struct {
	*ast.Field
	Names []*Ident
	Type  Expr
	// contains filtered or unexported fields
}

func (Field) KnownType

func (t Field) KnownType() []reflect.Type

type FieldList

type FieldList struct {
	*ast.FieldList
	List []*Field
}

type ForStmt

type ForStmt struct {
	*ast.ForStmt
	Init Stmt
	Cond Expr
	Post Stmt
	Body *BlockStmt
	// contains filtered or unexported fields
}

type FuncLit

type FuncLit struct {
	*ast.FuncLit
	Type *FuncType
	Body *BlockStmt
	// contains filtered or unexported fields
}

func (*FuncLit) Const

func (*FuncLit) Const() reflect.Value

func (*FuncLit) IsConst

func (*FuncLit) IsConst() bool

func (FuncLit) KnownType

func (t FuncLit) KnownType() []reflect.Type

func (*FuncLit) String

func (funcLit *FuncLit) String() string

type FuncType

type FuncType struct {
	*ast.FuncType
	Params  *FieldList
	Results *FieldList
	// contains filtered or unexported fields
}

func (*FuncType) Const

func (*FuncType) Const() reflect.Value

func (*FuncType) IsConst

func (*FuncType) IsConst() bool

func (FuncType) KnownType

func (t FuncType) KnownType() []reflect.Type

func (*FuncType) String

func (funcType *FuncType) String() string

type Ident

type Ident struct {
	*ast.Ident
	// contains filtered or unexported fields
}

func (Ident) Const

func (c Ident) Const() reflect.Value

func (Ident) IsConst

func (c Ident) IsConst() bool

func (Ident) KnownType

func (t Ident) KnownType() []reflect.Type

func (*Ident) String

func (ident *Ident) String() string

type IfStmt

type IfStmt struct {
	*ast.IfStmt
	Init Stmt
	Cond Expr
	Body *BlockStmt
	Else Stmt
}

type IndexExpr

type IndexExpr struct {
	*ast.IndexExpr
	X     Expr
	Index Expr
	// contains filtered or unexported fields
}

func (*IndexExpr) Const

func (*IndexExpr) Const() reflect.Value

func (*IndexExpr) IsConst

func (*IndexExpr) IsConst() bool

func (IndexExpr) KnownType

func (t IndexExpr) KnownType() []reflect.Type

func (*IndexExpr) String

func (index *IndexExpr) String() string

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

func (t InterfaceType) KnownType() []reflect.Type

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 MapType

type MapType struct {
	*ast.MapType
	Key   Expr
	Value Expr
	// contains filtered or unexported fields
}

func (*MapType) Const

func (*MapType) Const() reflect.Value

func (*MapType) IsConst

func (*MapType) IsConst() bool

func (MapType) KnownType

func (t MapType) KnownType() []reflect.Type

func (*MapType) String

func (mapType *MapType) String() string

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 PanicUser

type PanicUser reflect.Value

func (PanicUser) Error

func (p PanicUser) Error() string

type ParenExpr

type ParenExpr struct {
	*ast.ParenExpr
	X Expr
	// contains filtered or unexported fields
}

func (ParenExpr) Const

func (c ParenExpr) Const() reflect.Value

func (ParenExpr) IsConst

func (c ParenExpr) IsConst() bool

func (ParenExpr) KnownType

func (t ParenExpr) KnownType() []reflect.Type

func (*ParenExpr) String

func (parenExpr *ParenExpr) String() string

type ReturnStmt

type ReturnStmt struct {
	*ast.ReturnStmt
	Results []Expr
}

type Rune

type Rune struct {
	reflect.Type
}

func (Rune) Name

func (Rune) Name() string

func (Rune) String

func (Rune) String() string

type SelectorExpr

type SelectorExpr struct {
	*ast.SelectorExpr
	X   Expr
	Sel *Ident
	// contains filtered or unexported fields
}

func (SelectorExpr) Const

func (c SelectorExpr) Const() reflect.Value

func (SelectorExpr) IsConst

func (c SelectorExpr) IsConst() bool

func (SelectorExpr) KnownType

func (t SelectorExpr) KnownType() []reflect.Type

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

func (*SimpleEnv) AddConst

func (env *SimpleEnv) AddConst(ident string, c reflect.Value)

func (*SimpleEnv) AddFunc

func (env *SimpleEnv) AddFunc(ident string, f reflect.Value)

func (*SimpleEnv) AddPkg

func (env *SimpleEnv) AddPkg(pkg string, p Env)

func (*SimpleEnv) AddType

func (env *SimpleEnv) AddType(ident string, t reflect.Type)

func (*SimpleEnv) AddVar

func (env *SimpleEnv) AddVar(ident string, v reflect.Value)

func (*SimpleEnv) Const

func (env *SimpleEnv) Const(ident string) reflect.Value

func (*SimpleEnv) Func

func (env *SimpleEnv) Func(ident string) reflect.Value

func (*SimpleEnv) Pkg

func (env *SimpleEnv) Pkg(pkg string) Env

func (*SimpleEnv) PopScope

func (env *SimpleEnv) PopScope() Env

func (*SimpleEnv) PushScope

func (env *SimpleEnv) PushScope() Env

func (*SimpleEnv) Type

func (env *SimpleEnv) Type(ident string) reflect.Type

func (*SimpleEnv) Var

func (env *SimpleEnv) Var(ident string) reflect.Value

type SliceExpr

type SliceExpr struct {
	*ast.SliceExpr
	X    Expr
	Low  Expr
	High Expr
	// contains filtered or unexported fields
}

func (*SliceExpr) Const

func (*SliceExpr) Const() reflect.Value

func (*SliceExpr) IsConst

func (*SliceExpr) IsConst() bool

func (SliceExpr) KnownType

func (t SliceExpr) KnownType() []reflect.Type

func (*SliceExpr) String

func (slice *SliceExpr) String() string

type StarExpr

type StarExpr struct {
	*ast.StarExpr
	X Expr
	// contains filtered or unexported fields
}

func (*StarExpr) Const

func (*StarExpr) Const() reflect.Value

func (*StarExpr) IsConst

func (*StarExpr) IsConst() bool

func (StarExpr) KnownType

func (t StarExpr) KnownType() []reflect.Type

func (*StarExpr) String

func (star *StarExpr) String() string

type State

type State struct {
	Last Stmt
	Env  Env
}

func InterpStmt

func InterpStmt(stmt Stmt, env Env) (last *State, err error)

type Stmt

type Stmt interface {
	ast.Stmt
}

Annotated ast.Stmt nodes

func CheckStmt

func CheckStmt(stmt ast.Stmt, env Env) (Stmt, []error)

Place holder for something more substantial

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

func (t StructType) KnownType() []reflect.Type

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

func (t TypeAssertExpr) KnownType() []reflect.Type

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 UnaryExpr

type UnaryExpr struct {
	*ast.UnaryExpr
	X Expr
	// contains filtered or unexported fields
}

func (UnaryExpr) Const

func (c UnaryExpr) Const() reflect.Value

func (UnaryExpr) IsConst

func (c UnaryExpr) IsConst() bool

func (UnaryExpr) KnownType

func (t UnaryExpr) KnownType() []reflect.Type

func (*UnaryExpr) String

func (unary *UnaryExpr) String() string

type UntypedNil

type UntypedNil struct{}

func (UntypedNil) String

func (UntypedNil) String() string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL