eval

package
v0.0.0-...-c4618b4 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoFormula ErrNoFormula
	ErrNoFormula = errors.New("no formula like this")
)

Functions

func Format

func Format(e Expr) string

Format formats an expression as a string. It does not attempt to remove unnecessary parens.

func GenMapFromEnv

func GenMapFromEnv(env Env) map[Var]bool

GenMapFromEnv GenMapFromEnv

Types

type Boolean

type Boolean struct {
	Val bool `json:"result"`
}

Boolean bool

func (*Boolean) Boolean

func (b *Boolean) Boolean() bool

Boolean to bool

func (*Boolean) Float64

func (b *Boolean) Float64() float64

Float64 to float64

func (*Boolean) GetType

func (b *Boolean) GetType() T

GetType get float64 type

func (*Boolean) String

func (b *Boolean) String() string

String to string

type Env

type Env map[Var]Substance

Env environment variable

func GenEnv

func GenEnv(param map[string]interface{}) Env

GenEnv GenEnv

type Expr

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

An Expr is an arithmetic expression.

func Parse

func Parse(input string) (_ Expr, 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 Float64

type Float64 struct {
	Val float64 `json:"result"`
}

Float64 float64

func (*Float64) Boolean

func (f *Float64) Boolean() bool

Boolean to bool

func (*Float64) Float64

func (f *Float64) Float64() float64

Float64 to float64

func (*Float64) GetType

func (f *Float64) GetType() T

GetType get float64 type

func (*Float64) String

func (f *Float64) String() string

String to string

type Formula

type Formula func(args []Expr, env Env) Substance

Formula Formula define

type FormulaReq

type FormulaReq struct {
	Expression string                 `json:"expression"`
	Parameter  map[string]interface{} `json:"parameter"`
}

FormulaReq FormulaReq

type Result

type Result interface{}

Result response

func Handler

func Handler(c context.Context, req *FormulaReq) (Result, error)

Handler Handler

type String

type String struct {
	Val string `json:"result"`
}

String string

func (*String) Boolean

func (s *String) Boolean() bool

Boolean to bool

func (*String) Float64

func (s *String) Float64() float64

Float64 to float64

func (*String) GetType

func (s *String) GetType() T

GetType get string type

func (*String) String

func (s *String) String() string

String to string

type Substance

type Substance interface {
	GetType() T
	String() string
	Float64() float64
	Boolean() bool
}

Substance substance

type T

type T string

T type

type Var

type Var string

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

func (Var) Check

func (v Var) Check(vars map[Var]bool) error

Check check vars

func (Var) Eval

func (v Var) Eval(env Env) Substance

Eval var eval

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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