xexpr

package
v0.0.0-...-8145a24 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package xexpr 基于 github.com/expr-lang/expr 实现 xdag.Evaluator。

它被拆成独立子包,是为了让根包 xdag 保持零第三方依赖: 不需要条件判断的使用者不会把 expr 编进二进制。

dag, err := xdag.New(tasks, xdag.WithEvaluator(xexpr.New()))

Index

Constants

View Source
const DefaultMaxNodes = 1000

DefaultMaxNodes 是表达式 AST 的默认节点上限。 expr 自身默认为 1e4,分支条件用不到这个量级,收紧一些可以挡住畸形输入。

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine 实现 xdag.Evaluator。零值不可用,请使用 New 构造。

func New

func New(opts ...expr.Option) *Engine

New 构造表达式引擎。传入的 opts 会追加在默认选项之后,因此可以覆盖默认行为。

默认选项:

  • expr.Env(xdag.Env{}):以 Env 结构体做编译期类型检查
  • expr.AsBool():编译期强制表达式结果为 bool
  • expr.MaxNodes(DefaultMaxNodes):限制 AST 规模

func (*Engine) Compile

func (e *Engine) Compile(expression string) (xdag.Program, error)

Compile 实现 xdag.Evaluator。

Jump to

Keyboard shortcuts

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