expr

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Expr

type Expr struct {
	Type  Type
	Term  Term
	Op    Operator
	Left  *Expr
	Right *Expr
	Const int64
}

Expr represents an expression node.

func Int

func Int(v int64) (p *Expr)

Int creates an expression from an integer.

func Ref

func Ref(t Term) (p *Expr)

Ref creates an expression from a Term.

func (*Expr) Add

func (self *Expr) Add(v *Expr) *Expr

func (*Expr) And

func (self *Expr) And(v *Expr) *Expr

func (*Expr) Div

func (self *Expr) Div(v *Expr) *Expr

func (*Expr) Evaluate

func (self *Expr) Evaluate() (int64, error)

Evaluate evaluates the expression into an integer. It also implements the Term interface.

func (*Expr) Free

func (self *Expr) Free()

Free returns the Expr into pool. Any operation performed after Free is undefined behavior.

func (*Expr) Mod

func (self *Expr) Mod(v *Expr) *Expr

func (*Expr) Mul

func (self *Expr) Mul(v *Expr) *Expr

func (*Expr) Neg

func (self *Expr) Neg() *Expr

func (*Expr) Not

func (self *Expr) Not() *Expr

func (*Expr) Or

func (self *Expr) Or(v *Expr) *Expr

func (*Expr) Pow

func (self *Expr) Pow(v *Expr) *Expr

func (*Expr) Shl

func (self *Expr) Shl(v *Expr) *Expr

func (*Expr) Shr

func (self *Expr) Shr(v *Expr) *Expr

func (*Expr) Sub

func (self *Expr) Sub(v *Expr) *Expr

func (*Expr) Xor

func (self *Expr) Xor(v *Expr) *Expr

type Operator

type Operator uint8

Operator represents an operation to perform when Type is EXPR.

const (
	// ADD performs "Add Expr.Left and Expr.Right".
	ADD Operator = iota

	// SUB performs "Subtract Expr.Left by Expr.Right".
	SUB

	// MUL performs "Multiply Expr.Left by Expr.Right".
	MUL

	// DIV performs "Divide Expr.Left by Expr.Right".
	DIV

	// MOD performs "Modulo Expr.Left by Expr.Right".
	MOD

	// AND performs "Bitwise AND Expr.Left and Expr.Right".
	AND

	// OR performs "Bitwise OR Expr.Left and Expr.Right".
	OR

	// XOR performs "Bitwise XOR Expr.Left and Expr.Right".
	XOR

	// SHL performs "Bitwise Shift Expr.Left to the Left by Expr.Right Bits".
	SHL

	// SHR performs "Bitwise Shift Expr.Left to the Right by Expr.Right Bits".
	SHR

	// POW performs "Raise Expr.Left to the power of Expr.Right"
	POW

	// NOT performs "Bitwise Invert Expr.Left".
	NOT

	// NEG performs "Negate Expr.Left".
	NEG
)

func (Operator) String

func (self Operator) String() string

String returns the string representation of a Type.

type Parser

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

Parser parses an expression string to it's AST representation.

func (*Parser) Parse

func (self *Parser) Parse(repo Repository) (*Expr, error)

Parse parses the expression, and returns it's AST tree.

func (*Parser) SetSource

func (self *Parser) SetSource(src string) *Parser

SetSource resets the expression parser and sets the expression source.

type Repository

type Repository interface {
	Get(name string) (Term, error)
}

Repository represents a repository of Term's.

type RuntimeError

type RuntimeError struct {
	Reason string
}

RuntimeError is an error which would occur at run time.

func (*RuntimeError) Error

func (self *RuntimeError) Error() string

type SyntaxError

type SyntaxError struct {
	Pos    int
	Reason string
}

SyntaxError represents a syntax error in the expression.

func (*SyntaxError) Error

func (self *SyntaxError) Error() string

type Term

type Term interface {
	Free()
	Evaluate() (int64, error)
}

Term represents a value that can Evaluate() into an integer.

type Type

type Type int

Type is tyep expression type.

const (
	// CONST indicates that the expression is a constant.
	CONST Type = iota

	// TERM indicates that the expression is a Term reference.
	TERM

	// EXPR indicates that the expression is a unary or binary expression.
	EXPR
)

func (Type) String

func (self Type) String() string

String returns the string representation of a Type.

Jump to

Keyboard shortcuts

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