exp

package
v0.0.0-...-5e93b50 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInputTooLong = fmt.Errorf("input too long")
View Source
var ErrNoSuchValue = fmt.Errorf("no such value")

Functions

func Evaluate

func Evaluate(startPos Pos, tree parser.IExpressionContext, data Scope) (any, error)

Evaluate 对语法树求值

func IsBool

func IsBool(input any) (bool, bool)

func IsComplex

func IsComplex(value any) (complex128, bool)

func IsFloat

func IsFloat(value any) (float64, bool)

func IsInt

func IsInt(value any) (int64, bool)

func IsNil

func IsNil(a any) bool

func IsNull

func IsNull(a any) bool

func IsString

func IsString(input any) (string, bool)

func NameOfFunction

func NameOfFunction(f interface{}) string

NameOfFunction 获取函数的全限定名

func NewErrorListener

func NewErrorListener(start Pos) *errorListener

NewErrorListener 新建词法/语法分析错误监听器

func NewVisitor

func NewVisitor(pos Pos, s Scope) *visitor

NewVisitor 创建一个 Visitor 实例 通过 Visitor 遍历语法树来对其求值

func NotNil

func NotNil(a any) bool

func NotNull

func NotNull(a any) bool

func ParseCode

func ParseCode(input string, opts ...parseCodeOpt) (tree parser.IExpressionContext, err error)

ParseCode 解析代码为语法树

func ReflectConvert

func ReflectConvert[T any](from any) (to T)

func ToBytes

func ToBytes(a any) (s []byte)

func ToNumber

func ToNumber[T Integer | Float](a any) (n T)

func ToRunes

func ToRunes(a any) (s []rune)

func ToString

func ToString(a any) string

func TreesToString

func TreesToString(tree parser.IExpressionContext) string

TreesToString 打印语法树的工具函数

func WithStartPos

func WithStartPos(pos Pos) parseCodeOpt

WithStartPos 设置代码的起始位置 默认是起始于第 1 行第 1 列

Types

type Complex

type Complex interface {
	~complex64 | ~complex128
}

type Float

type Float interface {
	~float32 | ~float64
}

type Integer

type Integer interface {
	Signed | Unsigned
}

type Ordered

type Ordered interface {
	Integer | Float | ~string
}

type Pos

type Pos struct {
	Line   int // 行
	Column int // 列
}

Pos 行列位置

func NewPos

func NewPos(line, column int) Pos

func (Pos) Add

func (p Pos) Add(line, column int) Pos

func (Pos) String

func (p Pos) String() string

type Scope

type Scope interface {
	// Get 从该作用域内获取 name 对应的值
	// 返回 ErrNoSuchValue 表示该作用域中无 name 对应的值
	Get(name string) (result any, err error)
}

Scope 表示一个作用域

func Combine

func Combine(s, p Scope) Scope

Combine 组合两个作用域 当子作用域中找不到时 从父作用域找

func EmptyScope

func EmptyScope() Scope

EmptyScope 构造一个没有任何值的作用域

func NewScope

func NewScope(data any) Scope

NewScope 从结构体/map/数组/切片新建作用域

func WithDefaultScope

func WithDefaultScope(s Scope) Scope

WithDefaultScope 组合默认作用域

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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