ast

package
v0.0.0-...-6120cfb Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRegexExpr   = errors.New("invalid regex expr")
	ErrCompileRegexFailed = errors.New("compile regex failed")
)
View Source
var (
	ErrUnknownAccessorMemberIdentType   = errors.New("unknown accessor member ident type")
	ErrUnknownAccessorAncestorIdentType = errors.New("unknown accessor ancestor ident type")
	ErrUnknownAccessorAncestorType      = errors.New("unknown accessor ancestor type")
)
View Source
var BoolFalse = &Primitive{Typ: BOOLEAN, Value: false}
View Source
var BoolTrue = &Primitive{Typ: BOOLEAN, Value: true}

Functions

func RemoveStringQuote

func RemoveStringQuote(target string) string

Types

type Accessor

type Accessor struct {
	Typ      Type
	Ancestor Evaluable
	Ident    Evaluable
	// contains filtered or unexported fields
}

func (*Accessor) ChildrenLen

func (e *Accessor) ChildrenLen() int

func (*Accessor) Clone

func (e *Accessor) Clone() Evaluable

func (*Accessor) Evaluate

func (a *Accessor) Evaluate(ctx EvaluateCtx) (*Primitive, error)

func (*Accessor) GetChildAt

func (e *Accessor) GetChildAt(idx int) Evaluable

func (*Accessor) GetMutChildAt

func (e *Accessor) GetMutChildAt(idx int) *Evaluable

func (*Accessor) String

func (e *Accessor) String() string

type AccessorValue

type AccessorValue interface {
	GetMember(ident string) *Primitive
}

type Args

type Args []Evaluable

func (Args) ChildrenLen

func (a Args) ChildrenLen() int

func (Args) Clone

func (a Args) Clone() Evaluable

func (Args) Evaluate

func (a Args) Evaluate(ctx EvaluateCtx) (*Primitive, error)

func (Args) GetChildAt

func (a Args) GetChildAt(idx int) Evaluable

func (Args) GetMutChildAt

func (a Args) GetMutChildAt(idx int) *Evaluable

func (Args) String

func (a Args) String() string

type ArgsRef

type ArgsRef []*Evaluable

type ArithmeticEvalFnGroup

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

type ArithmeticEvalMap

type ArithmeticEvalMap map[Op]ArithmeticEvalFnGroup

type BinaryOperationExpr

type BinaryOperationExpr struct {
	Op
	L Evaluable
	R Evaluable
}

func (*BinaryOperationExpr) ChildrenLen

func (e *BinaryOperationExpr) ChildrenLen() int

func (*BinaryOperationExpr) Clone

func (e *BinaryOperationExpr) Clone() Evaluable

func (*BinaryOperationExpr) Evaluate

func (e *BinaryOperationExpr) Evaluate(ctx EvaluateCtx) (*Primitive, error)

func (*BinaryOperationExpr) GetChildAt

func (e *BinaryOperationExpr) GetChildAt(idx int) Evaluable

func (*BinaryOperationExpr) GetMutChildAt

func (e *BinaryOperationExpr) GetMutChildAt(idx int) *Evaluable

func (*BinaryOperationExpr) String

func (e *BinaryOperationExpr) String() string

type CondEvalFnGroup

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

type CondEvalMap

type CondEvalMap map[Op]CondEvalFnGroup

type Context

type Context struct {
	Variables
	// contains filtered or unexported fields
}

func NewContext

func NewContext() *Context

func (Context) AddAccessor

func (ctx Context) AddAccessor(k string, a AccessorValue)

func (Context) AddFunctionWithCtx

func (ctx Context) AddFunctionWithCtx(k string, f FunctionWithCtx)

func (Context) AddParameter

func (ctx Context) AddParameter(k string, p *Primitive)

func (Context) Get

func (ctx Context) Get(key string) interface{}

func (*Context) GetVars

func (ctx *Context) GetVars() *Variables

type Error

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

func (*Error) ChildrenLen

func (e *Error) ChildrenLen() int

func (*Error) Clone

func (e *Error) Clone() Evaluable

func (*Error) Evaluate

func (e *Error) Evaluate(ctx EvaluateCtx) (*Primitive, error)

func (*Error) GetChildAt

func (e *Error) GetChildAt(idx int) Evaluable

func (*Error) GetMutChildAt

func (e *Error) GetMutChildAt(idx int) *Evaluable

func (*Error) String

func (e *Error) String() string

type EvalCond

type EvalCond[T any] func(l, r T) bool

type EvalFloat

type EvalFloat func(float64, float64) float64

type EvalInt

type EvalInt func(int, int) int

type Evaluable

type Evaluable interface {
	Evaluate(ctx EvaluateCtx) (*Primitive, error)
	// GetChildAt returns am immutable ast.Evaluable
	GetChildAt(idx int) Evaluable
	// GetMutChildAt returns a mutable ref of ast.Evaluable
	GetMutChildAt(idx int) *Evaluable
	ChildrenLen() int
	Clone() Evaluable
	String() string
}

func CloneSlice

func CloneSlice(a []Evaluable) []Evaluable

type EvaluateCtx

type EvaluateCtx interface {
	Get(key string) interface{}
	GetVars() *Variables
}

type FirstClass

type FirstClass map[string]interface{}

type FunctionWithCtx

type FunctionWithCtx interface {
	Eval(ctx EvaluateCtx, args ...Evaluable) (*Primitive, error)
}

type Op

type Op uint
const (
	PRE_INC_OP Op = iota + 1
	PRE_DEC_OP
	POST_INC_OP
	POST_DEC_OP

	AND
	MUL
	ADD
	SUB
	POW
	DIV
	MOD

	LEFT_OP
	RIGHT_OP

	IN_OP
	LT
	GT
	LE
	GE

	NULL_OP
	EQ_OP
	NE_OP
	RE_OP
	NR_OP
	EX_OR
	IN_OR

	AND_OP
	OR_OP

	UAND
	UMUL
	UPLUS
	UMINUS
	UBITNOT
	UNOT
)

func (Op) String

func (o Op) String() string

type Parameter

type Parameter interface {
	GetPrimitive() *Primitive
}

type Primitive

type Primitive struct {
	Typ     Type
	Value   interface{}
	Mutable bool
}

func (*Primitive) ChildrenLen

func (e *Primitive) ChildrenLen() int

func (*Primitive) Clone

func (p *Primitive) Clone() Evaluable

func (*Primitive) Equal

func (p *Primitive) Equal(another *Primitive, ctx EvaluateCtx) bool

func (*Primitive) Evaluate

func (p *Primitive) Evaluate(ctx EvaluateCtx) (*Primitive, error)

func (*Primitive) GetChildAt

func (e *Primitive) GetChildAt(idx int) Evaluable

func (*Primitive) GetMutChildAt

func (p *Primitive) GetMutChildAt(idx int) *Evaluable

func (*Primitive) IsNil

func (p *Primitive) IsNil() bool

func (*Primitive) String

func (p *Primitive) String() string

type ScalarFunction

type ScalarFunction struct {
	Ident Evaluable
	Args  []Evaluable
}

func (*ScalarFunction) ChildrenLen

func (e *ScalarFunction) ChildrenLen() int

func (ScalarFunction) Clone

func (a ScalarFunction) Clone() Evaluable

func (ScalarFunction) Evaluate

func (s ScalarFunction) Evaluate(ctx EvaluateCtx) (*Primitive, error)

func (*ScalarFunction) GetChildAt

func (e *ScalarFunction) GetChildAt(idx int) Evaluable

func (ScalarFunction) GetMutChildAt

func (e ScalarFunction) GetMutChildAt(idx int) *Evaluable

func (ScalarFunction) String

func (e ScalarFunction) String() string

type TernaryOperationExpr

type TernaryOperationExpr struct {
	Cond  Evaluable
	True  Evaluable
	False Evaluable
}

func (*TernaryOperationExpr) ChildrenLen

func (e *TernaryOperationExpr) ChildrenLen() int

func (*TernaryOperationExpr) Clone

func (e *TernaryOperationExpr) Clone() Evaluable

func (*TernaryOperationExpr) Evaluate

func (e *TernaryOperationExpr) Evaluate(ctx EvaluateCtx) (*Primitive, error)

func (*TernaryOperationExpr) GetChildAt

func (e *TernaryOperationExpr) GetChildAt(idx int) Evaluable

func (*TernaryOperationExpr) GetMutChildAt

func (e *TernaryOperationExpr) GetMutChildAt(idx int) *Evaluable

func (*TernaryOperationExpr) String

func (e *TernaryOperationExpr) String() string

type Type

type Type uint
const (
	BOOLEAN Type = iota + 1
	INT
	FLOAT
	STRING
	TUPLE
	ERROR
	MEMBER_ACCESSOR
	IDENTIFIER
	NULL
)

func (Type) String

func (t Type) String() string

type UnaryOperationExpr

type UnaryOperationExpr struct {
	Child Evaluable
	Op
}

func (*UnaryOperationExpr) ChildrenLen

func (e *UnaryOperationExpr) ChildrenLen() int

func (*UnaryOperationExpr) Clone

func (e *UnaryOperationExpr) Clone() Evaluable

func (*UnaryOperationExpr) Evaluate

func (e *UnaryOperationExpr) Evaluate(ctx EvaluateCtx) (child *Primitive, err error)

func (*UnaryOperationExpr) GetChildAt

func (e *UnaryOperationExpr) GetChildAt(idx int) Evaluable

func (*UnaryOperationExpr) GetMutChildAt

func (e *UnaryOperationExpr) GetMutChildAt(idx int) *Evaluable

func (UnaryOperationExpr) String

func (e UnaryOperationExpr) String() string

type Variables

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

Jump to

Keyboard shortcuts

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