pub fn format_sheet(sheet: &Sheet, source: &str) -> StringExpand description
Pretty-prints sheet back to adam-lang source text — see the module doc for the printing
rules.
source is the text sheet was parsed from (or "" for a programmatically built Sheet);
it’s forwarded to [cel_parser::format_expr] for every embedded expression.
- Precondition:
sheethas no recorded syntax errors (sheet.errors.is_empty()) — a sheet with aSheetItem::Errorplaceholder cannot be printed back to valid source. - Complexity: O(n + v + b + g + c + p) time plus delegated CEL layout, for source bytes n, visited AST nodes v, emitted bytes b including indentation, summed scanned region bytes g, converted character prefixes c, and measured output-line prefixes p. O(l + b + g + h) space plus CEL layout storage, for source lines l and writer call depth h. Repeated prefix/region work is not globally linear.
§Examples
use adam_lang::{AdamAstParser, attach_trivia, format_sheet};
let source = "sheet s { cell x: i32 = 1; }";
let mut sheet = AdamAstParser::new().parse_str(source).unwrap();
attach_trivia(source, &mut sheet);
assert_eq!(format_sheet(&sheet, source), "sheet s {\n cell x: i32 = 1;\n}\n");