expr

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenEOF = -(iota + 1)
	TokenIdent
	TokenInt
	TokenFloat
	TokenString
	TokenOperator
)

Variables

This section is empty.

Functions

func ConvertToBool

func ConvertToBool(v reflect.Value) bool

func ConvertToFloat

func ConvertToFloat(v reflect.Value) float64

func ConvertToInt

func ConvertToInt(v reflect.Value) int64

func ConvertToUint

func ConvertToUint(v reflect.Value) uint64

func EvalBool

func EvalBool(expr Expr, env Env) (value bool, err error)

func EvalInt

func EvalInt(expr Expr, env Env) (value int64, err error)

Types

type Env

type Env map[Var]interface{}

type Expr

type Expr interface {
	// Eval returns the value of this Expr in the environment env.
	Eval(env Env) reflect.Value
	// Check reports errors in this Expr and adds its Vars to the set.
	Check(vars map[Var]interface{}) error
}

An Expr is an arithmetic expression.

type ExpressionParser

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

---- parser ----

func NewExpressionParser

func NewExpressionParser() *ExpressionParser

func (*ExpressionParser) GetExpr

func (parser *ExpressionParser) GetExpr() Expr

func (*ExpressionParser) GetVariable

func (parser *ExpressionParser) GetVariable() []string

func (*ExpressionParser) Parse

func (parser *ExpressionParser) Parse(input string) (err error)

Parse parses the input string as an arithmetic expression.

expr = num                         a literal number, e.g., 3.14159
     | id                          a variable name, e.g., x
     | id '(' expr ',' ... ')'     a function call
     | '-' expr                    a unary operator ( + - ! )
     | expr '+' expr               a binary operator ( + - * / && & || | == )

type Var

type Var string

A Var identifies a variable, e.g., x.

func (Var) Check

func (v Var) Check(vars map[Var]interface{}) error

func (Var) Eval

func (v Var) Eval(env Env) reflect.Value

Jump to

Keyboard shortcuts

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