parse_expression_with_parameters

Function parse_expression_with_parameters 

Source
pub fn parse_expression_with_parameters<'arena>(
    input: &str,
    arena: &'arena Bump,
    parameters: &[String],
) -> Result<AstExpr<'arena>, ExprError>
Expand description

Parse an expression with function parameters that should be treated as variables.

This function is specifically designed for parsing expression function bodies where certain identifiers (the function parameters) should always be treated as variables, not as function calls. This prevents “x(y)” from being parsed as a function call when “x” is a parameter.

§Examples

use exp_rs::engine::parse_expression_with_parameters;
use bumpalo::Bump;

let arena = Bump::new();

// Parse expression function body with parameters
let params = vec!["x".to_string(), "y".to_string()];
let expr = parse_expression_with_parameters("x * y + 2", &arena, &params).unwrap();
// In this case, 'x' and 'y' are treated as variables, not potential function calls

// Without this, "x(y)" would be parsed as a function call
let expr = parse_expression_with_parameters("x(y)", &arena, &params).unwrap();
// This correctly parses as multiplication due to juxtaposition: x * y