plaita.core.expression¶
结构化表达式引擎:FunctionCategory、FunctionDescriptor、ExpressionRegistry、ExpressionEvaluator,以及 60+ 内置函数的默认注册表工厂。
expression
¶
plaita.core.expression — Structured expression engine.
Provides: - FunctionCategory enum for classifying expression functions. - FunctionDescriptor frozen dataclass with side-effect metadata. - ExpressionRegistry for querying functions by category / side-effect. - ExpressionEvaluator that delegates to plaita.io evaluate/parse_function. - get_default_expression_registry() factory with all 90+ built-in functions.
FunctionCategory
¶
Bases: str, Enum
Classification categories for expression functions.
FunctionDescriptor
dataclass
¶
FunctionDescriptor(name: str, func: Callable, category: FunctionCategory, has_side_effects: bool = False, fresh_producer: bool = False, description: str = '')
Metadata wrapper around a registered expression function.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
name |
str
|
Function name (used in expressions as |
func |
Callable
|
The underlying callable. |
category |
FunctionCategory
|
Classification category. |
has_side_effects |
bool
|
|
fresh_producer |
bool
|
|
description |
str
|
Optional human-readable description. |
ExpressionRegistry
¶
Registry for expression functions with category and side-effect metadata.
源代码位于: plaita/core/expression.py
register
¶
register(name: str, func: Callable, category: FunctionCategory, *, has_side_effects: bool = False, fresh_producer: bool = False, description: str = '', override: bool = False) -> None
Register an expression function.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
Function name (used in expressions as |
必需 |
func
|
Callable
|
The callable to execute. |
必需 |
category
|
FunctionCategory
|
Classification category. |
必需 |
has_side_effects
|
bool
|
|
False
|
fresh_producer
|
bool
|
|
False
|
description
|
str
|
Human-readable description. |
''
|
override
|
bool
|
If |
False
|
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If name is empty, or already registered with
|
源代码位于: plaita/core/expression.py
get
¶
get(name: str) -> Optional[FunctionDescriptor]
unregister
¶
get_callable
¶
Look up just the callable by name (for backward compatibility).
names
¶
by_category
¶
by_category(category: FunctionCategory) -> List[FunctionDescriptor]
side_effect_functions
¶
side_effect_functions() -> List[FunctionDescriptor]
all_functions
¶
all_functions() -> dict[str, FunctionDescriptor]
ExpressionEvaluator
¶
ExpressionEvaluator(registry: Optional[ExpressionRegistry] = None)
Evaluates expressions against an execution context.
This class wraps the existing plaita.io.evaluate / parse_function
logic and exposes the structured ExpressionRegistry. The actual
parsing and evaluation is delegated to the battle-tested functions in
plaita.io to guarantee identical results.
源代码位于: plaita/core/expression.py
evaluate
¶
Evaluate a value, resolving any expressions.
Delegates to plaita.io.evaluate but passes this evaluator's
ExpressionRegistry so that $F.func(...) calls resolve against
the scoped registry. When the registry is the default one this is
behavior-preserving; when a custom registry is supplied, function
lookups go through it instead of the module-level global.
源代码位于: plaita/core/expression.py
get_default_expression_registry
¶
get_default_expression_registry() -> ExpressionRegistry
Return the module-level default registry with all built-in functions.
The registry is created lazily on first access and cached.