reflectlang

package
v0.0.0-...-69abbbe Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParser       = errors.New("parser error")
	ErrUnboundVar   = errors.New("unbound variable")
	ErrTypeMismatch = errors.New("type mismatch")
	ErrUnknownOp    = errors.New("unknown op")
	ErrRuntime      = errors.New("runtime error")
)

Functions

func Eval

func Eval(expression string, env Environment) (_ []reflect.Value, err error)

func IsIdentifier

func IsIdentifier(v string) bool

func IsLowerFunc

func IsLowerFunc(v interface{}) bool

func LowerFunc

func LowerFunc(env Environment, fn func([]reflect.Value) ([]reflect.Value, error)) reflect.Value

func LowerStruct

func LowerStruct(env Environment, sub Environment) reflect.Value

func Repr

func Repr(x reflect.Value) string

Types

type ArrayAccess

type ArrayAccess struct {
	Array Evaluable
	Index Evaluable
	// contains filtered or unexported fields
}

func (*ArrayAccess) Run

func (a *ArrayAccess) Run(env Environment) ([]reflect.Value, error)

type Call

type Call struct {
	Func Evaluable
	Args []Evaluable
	// contains filtered or unexported fields
}

func (*Call) Run

func (c *Call) Run(env Environment) ([]reflect.Value, error)

type Environment

type Environment map[string]reflect.Value

func IsLowerStruct

func IsLowerStruct(v interface{}) Environment

func NewStandardEnvironment

func NewStandardEnvironment() Environment

type Evaluable

type Evaluable interface {
	Run(env Environment) ([]reflect.Value, error)
}

func Parse

func Parse(expression string) (Evaluable, error)

type FieldAccess

type FieldAccess struct {
	Val   Evaluable
	Field *Ident
	// contains filtered or unexported fields
}

func (*FieldAccess) Run

func (a *FieldAccess) Run(env Environment) ([]reflect.Value, error)

type Ident

type Ident struct {
	Name string
	// contains filtered or unexported fields
}

func (*Ident) Run

func (i *Ident) Run(env Environment) ([]reflect.Value, error)

type ModType

type ModType = string
const (
	ModNeg   ModType = "-"
	ModNot   ModType = "!"
	ModRef   ModType = "&"
	ModDeref ModType = "*"
)

type Modifier

type Modifier struct {
	Type ModType
	Val  Evaluable
	// contains filtered or unexported fields
}

func (*Modifier) Run

func (m *Modifier) Run(env Environment) ([]reflect.Value, error)

type OpType

type OpType = string
const (
	OpOrModNil            = ""
	OpMul          OpType = "*"
	OpDiv          OpType = "/"
	OpAdd          OpType = "+"
	OpSub          OpType = "-"
	OpLess         OpType = "<"
	OpLessEqual    OpType = "<="
	OpEqual        OpType = "=="
	OpNotEqual     OpType = "!="
	OpGreater      OpType = ">"
	OpGreaterEqual OpType = ">="
	OpAnd          OpType = "&&"
	OpOr           OpType = "||"
)

type Operation

type Operation struct {
	Type  OpType
	Left  Evaluable
	Right Evaluable
	// contains filtered or unexported fields
}

func (*Operation) Run

func (o *Operation) Run(env Environment) ([]reflect.Value, error)

type Parser

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

func NewParser

func NewParser(source string) *Parser

func (Parser) Err

func (p Parser) Err(errType error, messagef string, args ...interface{}) error

func (*Parser) Parse

func (p *Parser) Parse() (Evaluable, error)

type SliceAccess

type SliceAccess struct {
	Array Evaluable
	Low   Evaluable
	High  Evaluable
	// contains filtered or unexported fields
}

func (*SliceAccess) Run

func (a *SliceAccess) Run(env Environment) ([]reflect.Value, error)

type Subexpression

type Subexpression struct {
	Expr Evaluable
	// contains filtered or unexported fields
}

func (*Subexpression) Run

func (s *Subexpression) Run(env Environment) ([]reflect.Value, error)

type Value

type Value struct {
	Val reflect.Value
}

func (*Value) Run

func (v *Value) Run(env Environment) ([]reflect.Value, error)

Jump to

Keyboard shortcuts

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