pub fn parse_expression<'arena>(
input: &str,
arena: &'arena Bump,
) -> Result<AstExpr<'arena>, ExprError>Expand description
Parse an expression string into an AST.
This is the primary parsing function that requires an explicit arena for memory allocation.
For parsing expression function bodies with parameters, use parse_expression_with_parameters.
§Supported Features
- Arithmetic operators: +, -, *, /, %, ^, **
- Comparison operators: ==, !=, <, >, <=, >=, <>
- Logical operators: &&, ||
- Ternary conditional: condition ? true_expr : false_expr
- Function calls: func(arg1, arg2)
- Variables and constants
- Array access: array[index]
- Attribute access: object.attribute
§Examples
use exp_rs::engine::parse_expression;
use bumpalo::Bump;
let arena = Bump::new();
// Basic arithmetic
let expr = parse_expression("2 + 3 * 4", &arena).unwrap();
// Ternary conditional
let expr = parse_expression("x > 0 ? 1 : -1", &arena).unwrap();
// Function calls
let expr = parse_expression("sin(x) + cos(y)", &arena).unwrap();