Skip to main content

format_source

Function format_source 

Source
pub fn format_source(source: &str) -> Result<String, FormatSourceError>
Expand description

Parses and formats source as a complete adam-lang module.

Mixed or detached comment runs in ordinary AST attachments normalize to line comments while retaining payload order; see crate::attach_trivia.

  • Complexity: parsing plus crate::attach_module_trivia and format_module time, including their repeated character-prefix and region scans and delegated CEL layout. Space holds the parsed AST, recovered trivia, line indexes, output, writer stack, and peak CEL layout temporaries. Sharing indexes does not make the whole pipeline linear in source length.

§Errors

Returns FormatSourceError::Recovered for recovered syntax errors. Tokenization failures, empty input, and input with no recognizable module declaration return FormatSourceError::Parse. Refuses to format code it cannot fully understand.

§Examples

use adam_lang::format_source;

assert_eq!(
    format_source("sheet   s{cell x:i32=1;}").unwrap(),
    "sheet s {\n    cell x: i32 = 1;\n}\n"
);
assert!(format_source("not a sheet at all").is_err());