rulengine

package module
v0.0.0-...-25f1ce1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 7 Imported by: 0

README

Build Coverage Go Report

Rulengine

Rulegine provides support for evaluating arbitrary expressions.

Installation

When used with Go modules, use the following import path:

go get github.com/leonests/rulengine

Quickstart

Bracket Accessor

Dot Accessor

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Expr

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

func NewExpr

func NewExpr(expr string) (res *Expr, err error)

func (*Expr) Eval

func (expr *Expr) Eval(params map[string]interface{}) (interface{}, error)

type LexerToken

type LexerToken struct {
	Type  TokenType
	Value interface{}
}

type TokenType

type TokenType int //enum
const (
	ILLEGAL TokenType = iota

	// literal operators
	CHAR     // 'a', '爱', ...
	STRING   // "abc"
	NUMBER   // 123, 123.456 treated as float64
	BOOL     // true, false
	VARIABLE // a1, b_2, c
	SELECTOR // a.b.c,
	ACCESSOR // .a.b

	// prefix operators
	NOT // !
	NEG // -

	// normal operators
	ADD // +
	SUB // -
	MUL // *
	QUO // /
	REM // %

	AND // &
	OR  // |
	XOR // ^
	SHL // <<
	SHR // >>

	// ternary operators
	TERNARY_IF
	TERNARY_ELSE

	// logical operators
	LAND // &&
	LOR  // ||

	// comparer operators
	EQ  // ==
	NEQ // !=
	LT  // <
	GT  // >
	LEQ // <=
	GEQ // >=

	// clause operators
	LPAREN // (
	RPAREN // )

	LBRACKET // [
	RBRACKET // ]

	LITERAL // represent all literal operators
	CLAUSE  // represent all clause operator
	EOF
)

func (TokenType) Priority

func (op TokenType) Priority() opPriority

func (TokenType) String

func (t TokenType) String() string

Jump to

Keyboard shortcuts

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