pub fn format_expr_header(
expr: &Expr,
source: &str,
depth: usize,
bounds: (LineColumn, LineColumn),
) -> StringExpand description
Formats a brace-reserving header and its surrounding comments within explicit boundaries.
bounds runs from just after the introducing keyword to just before the body brace.
Grouping parentheses omitted from the AST do not interrupt comment recovery.
- Precondition:
sourceis the parsed source andboundsenclosesexpr, or source is empty. - Postcondition: boundary comments appear exactly once in source order.
- Complexity: O(n) document space plus layout and existing source-gap scans.
ยงExamples
use cel_parser::{AstContext, OpLookup, Parser, format_expr_header};
let source = "(Point { x: 1.0 }) /* keep */";
let expr = Parser::<AstContext>::new(OpLookup::new()).parse_str_ast(source).unwrap();
let text = format_expr_header(&expr, source, 0, (
proc_macro2::LineColumn { line: 1, column: 0 },
proc_macro2::LineColumn { line: 1, column: source.len() },
));
assert_eq!(text, "(Point { x: 1.0 }) /* keep */");