Skip to main content

format_expr_with_layout

Function format_expr_with_layout 

Source
pub fn format_expr_with_layout(
    expr: &Expr,
    source: &str,
    depth: usize,
    column: usize,
    width: usize,
    suffix_columns: usize,
) -> String
Expand description

Formats an expression at the actual output column with a target width.

Reserves suffix_columns for following punctuation on the final line. Short expressions remain inline. Lists, records and closure bodies nest four spaces; binary continuations lead with their operator. Unbreakable tokens and comments may exceed the target. The result excludes the prefix, suffix and initial indentation; continuation indentation starts at depth * 4. When an indented continuation has more room and the first fragment cannot fit after the prefix, the expression starts on a new line indented four spaces beyond depth.

  • Precondition: source is the expression’s parsed source, or empty for a hand-built AST.
  • Complexity: O(n) document space plus layout and existing source-gap scans.

§Examples

use cel_parser::{AstContext, OpLookup, Parser, format_expr_with_layout};
let source = "first + second";
let expr = Parser::<AstContext>::new(OpLookup::new()).parse_str_ast(source).unwrap();
assert_eq!(format_expr_with_layout(&expr, source, 1, 12, 26, 1),
    "first\n        + second");