Skip to main content

ParsedExpression

Struct ParsedExpression 

Source
pub struct ParsedExpression { /* private fields */ }
Expand description

A parsed expression ready for evaluation.

Implementations§

Source§

impl ParsedExpression

Source

pub fn expression(&self) -> &str

The trimmed expression string.

Source

pub fn accessed_symbols(&self) -> &HashSet<String>

Symbol names accessed by this expression (e.g. Param.Name).

Source

pub fn called_functions(&self) -> &HashSet<String>

Function names called by this expression (e.g. len, upper).

Source

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 ‘.’).

Matches the Python implementation’s approach:

  1. Try to parse
  2. On syntax error, find keyword after ‘.’ at error position
  3. Replace with same-length identifier (preserves error positions)
  4. Retry
  5. After success, record renames so evaluator can map back
Source

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.

Source

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");
Source

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.

Source

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.

Source

pub fn with_library<'a>( &'a self, library: &'a FunctionLibrary, ) -> EvalBuilder<'a>

Start a configured evaluation using the EvalBuilder.

Source

pub fn with_memory_limit(&self, limit: usize) -> EvalBuilder<'_>

Start a configured evaluation with a memory limit.

Source

pub fn with_operation_limit(&self, limit: usize) -> EvalBuilder<'_>

Start a configured evaluation with an operation limit.

Source

pub fn with_path_format(&self, format: PathFormat) -> EvalBuilder<'_>

Start a configured evaluation with an explicit path format.

Source

pub fn with_target_type<'a>( &'a self, target_type: &'a ExprType, ) -> EvalBuilder<'a>

Start a configured evaluation with a target type for coercion.

Source

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

Source§

fn clone(&self) -> ParsedExpression

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParsedExpression

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.