Skip to main content

format_expr

Function format_expr 

Source
pub fn format_expr(expr: &Expr, source: &str, depth: usize) -> String
Expand description

Pretty-prints expr back to CEL source text — see the module doc for the printing rules.

source is the text expr was parsed from (or "" for a hand-built Expr); depth supplies the base indentation for wrapped continuations and the assumed initial output column. Postfix bases retain leading group comments, and member-dot comments survive omitted groups. Closure bases stay grouped so following postfixes cannot move into their bodies.

  • Complexity: O(n) document space plus layout and existing source-gap scans.

§Examples

use cel_parser::{AstContext, OpLookup, Parser, format_expr};

let mut parser = Parser::<AstContext>::new(OpLookup::new());
let expr = parser.parse_str_ast("(1i32 + 2i32) * 3i32").unwrap();
assert_eq!(format_expr(&expr, "(1i32 + 2i32) * 3i32", 0), "(1i32 + 2i32) * 3i32");