expr

package
v0.0.0-...-732dac8 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrVarNotDefined = errors.New("variable not defined")
	ErrIdentNotFound = errors.New("unknown identifier")
	ErrFieldNotFound = errors.New("field not found")
)

Functions

func Bool

func Bool(val any) bool

func Compare

func Compare(op Token, lhs, rhs any) (res bool, err error)

func Eval

func Eval(ctx *Context, expr Expr) (any, error)

func GetFieldFn

func GetFieldFn(strkt reflect.Value) func(string) (any, bool)

Types

type BinExpr

type BinExpr struct {
	Op  Token
	Lhs Expr
	Rhs Expr
}

func (*BinExpr) String

func (expr *BinExpr) String() string

type Call

type Call struct {
	Name string
	Args []Expr
}

func (*Call) String

func (expr *Call) String() string

type Const

type Const struct {
	Value any
}

func NewConst

func NewConst(val any) *Const

func (*Const) String

func (expr *Const) String() string

type Context

type Context struct {
	GetField func(name string) (any, bool)
	GetVar   func(name string) (any, bool)
	GetIdent func(name string) (any, bool)
}

type Expr

type Expr interface {
	fmt.Stringer
}

func Parse

func Parse(str string) (expr Expr, err error)

type Field

type Field struct {
	Name string
}

func (*Field) String

func (expr *Field) String() string

type Ident

type Ident struct {
	Name string
}

func (*Ident) String

func (expr *Ident) String() string

type Scanner

type Scanner struct {
	scanner.Scanner
}

func (*Scanner) Init

func (s *Scanner) Init(rd io.Reader)

func (*Scanner) Scan

func (s *Scanner) Scan() (tok Token, err error)

type Token

type Token int
const (
	INVALID Token = iota

	IDENT

	INT
	FLOAT
	FIELD

	ADD // +
	SUB // -
	MUL // *
	QUO // /

	REM // %
	DOL // $

	LSS // <
	GTR // >

	EQL // ==
	NEQ // !=
	LEQ // <=
	GEQ // >=

	LAND // &&
	LOR  // ||

	AND // &
	OR  // |

	NOT // !

	LPAREN // (
	//LBRACK // [
	//LBRACE // {
	COMMA // ,

	RPAREN // )

	EOF
)

func (Token) String

func (i Token) String() string

type UnaryExpr

type UnaryExpr struct {
	Op Token
	X  Expr
}

func (*UnaryExpr) String

func (expr *UnaryExpr) String() string

type Var

type Var struct {
	Name string
}

func (*Var) String

func (expr *Var) String() string

Jump to

Keyboard shortcuts

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