pub struct ParsedExpression { /* private fields */ }Expand description
A parsed expression ready for evaluation.
Implementations§
Source§impl ParsedExpression
impl ParsedExpression
Sourcepub fn expression(&self) -> &str
pub fn expression(&self) -> &str
The trimmed expression string.
Sourcepub fn accessed_symbols(&self) -> &HashSet<String>
pub fn accessed_symbols(&self) -> &HashSet<String>
Symbol names accessed by this expression (e.g. Param.Name).
Sourcepub fn called_functions(&self) -> &HashSet<String>
pub fn called_functions(&self) -> &HashSet<String>
Function names called by this expression (e.g. len, upper).
Sourcepub fn local_bindings(&self) -> &HashSet<String>
pub fn local_bindings(&self) -> &HashSet<String>
Loop variable names bound by list comprehensions in this expression.
Source§impl ParsedExpression
Parse a Python expression, handling contextual keywords (Python keywords
used as attribute names after ‘.’).
impl ParsedExpression
Parse a Python expression, handling contextual keywords (Python keywords used as attribute names after ‘.’).
Matches the Python implementation’s approach:
- Try to parse
- On syntax error, find keyword after ‘.’ at error position
- Replace with same-length identifier (preserves error positions)
- Retry
- After success, record renames so evaluator can map back
Sourcepub fn new(expr: &str) -> Result<ParsedExpression, ExpressionError>
pub fn new(expr: &str) -> Result<ParsedExpression, ExpressionError>
Parse an expression using the “latest” profile
(ExprProfile::latest): the current revision with every known
extension enabled.
This constructor is intentionally unstable across crate versions. The set of accepted syntax, functions, and types grows as new extensions and revisions land. Use it for ad-hoc parsing, prototyping, or when the source of the expression is known to target the newest capabilities.
For stability across crate versions, build a profile with an
explicit revision and extension set and use
with_profile.
Sourcepub fn with_profile(
expr: &str,
profile: &ExprProfile,
) -> Result<ParsedExpression, ExpressionError>
pub fn with_profile( expr: &str, profile: &ExprProfile, ) -> Result<ParsedExpression, ExpressionError>
Parse an expression under a caller-supplied profile.
The profile governs which syntax features the parser accepts (determined by its revision and enabled extensions) and — once expression-level extensions exist — which functions and types are in scope. An expression that parses successfully under one profile may fail to parse under another; conversely, a template that pinned a specific revision at decode time will continue to parse identically across crate upgrades if it is re-parsed against the same profile.
§Examples
use openjd_expr::{ExprProfile, ParsedExpression};
// Stable: this call will parse the same expression the same way
// regardless of future crate versions.
let profile = ExprProfile::current();
let parsed = ParsedExpression::with_profile("1 + 2", &profile)
.expect("parses");Sourcepub fn evaluate(
&self,
values: &SymbolTable,
) -> Result<ExprValue, ExpressionError>
pub fn evaluate( &self, values: &SymbolTable, ) -> Result<ExprValue, ExpressionError>
Evaluate this parsed expression against a single symbol table.
Convenience shortcut that returns just the value. See
evaluate_with_metrics to also
observe resource usage.
Sourcepub fn evaluate_with_metrics(
&self,
symtabs: &[&SymbolTable],
) -> Result<EvalResult, ExpressionError>
pub fn evaluate_with_metrics( &self, symtabs: &[&SymbolTable], ) -> Result<EvalResult, ExpressionError>
Evaluate this parsed expression and return the value alongside resource-usage metrics.
Convenience shortcut equivalent to
parsed.with_*(default).evaluate_with_metrics(&symtabs) — call this
when you don’t need any with_* configuration.
Sourcepub fn with_library<'a>(
&'a self,
library: &'a FunctionLibrary,
) -> EvalBuilder<'a>
pub fn with_library<'a>( &'a self, library: &'a FunctionLibrary, ) -> EvalBuilder<'a>
Start a configured evaluation using the EvalBuilder.
Sourcepub fn with_memory_limit(&self, limit: usize) -> EvalBuilder<'_>
pub fn with_memory_limit(&self, limit: usize) -> EvalBuilder<'_>
Start a configured evaluation with a memory limit.
Sourcepub fn with_operation_limit(&self, limit: usize) -> EvalBuilder<'_>
pub fn with_operation_limit(&self, limit: usize) -> EvalBuilder<'_>
Start a configured evaluation with an operation limit.
Sourcepub fn with_path_format(&self, format: PathFormat) -> EvalBuilder<'_>
pub fn with_path_format(&self, format: PathFormat) -> EvalBuilder<'_>
Start a configured evaluation with an explicit path format.
Sourcepub fn with_target_type<'a>(
&'a self,
target_type: &'a ExprType,
) -> EvalBuilder<'a>
pub fn with_target_type<'a>( &'a self, target_type: &'a ExprType, ) -> EvalBuilder<'a>
Start a configured evaluation with a target type for coercion.
Sourcepub fn as_name_lookup(&self) -> Option<&str>
pub fn as_name_lookup(&self) -> Option<&str>
If this expression is a simple dotted name (e.g. Param.Name),
return it as a string. Returns None for anything more complex
(arithmetic, function calls, subscripts, etc.).
Trait Implementations§
Source§impl Clone for ParsedExpression
impl Clone for ParsedExpression
Source§fn clone(&self) -> ParsedExpression
fn clone(&self) -> ParsedExpression
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for ParsedExpression
impl RefUnwindSafe for ParsedExpression
impl Send for ParsedExpression
impl Sync for ParsedExpression
impl Unpin for ParsedExpression
impl UnsafeUnpin for ParsedExpression
impl UnwindSafe for ParsedExpression
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more