Skip to main content

attach_module_trivia

Function attach_module_trivia 

Source
pub fn attach_module_trivia(source: &str, module: &mut Module)
Expand description

Attaches every file-boundary comment and each sheet’s existing nested trivia.

  • Precondition: module was parsed from exactly source.
  • Postcondition: each file-boundary comment belongs to exactly one gap.
  • Complexity: O(n + v + g + c) time for source bytes n, visited AST nodes v, summed scanned gap bytes g, and summed converted character-column prefixes c, including every nested attachment. O(l + g + h) space for source lines l, recovered/scanned gaps, and call depth h. Repeated prefix scans can be quadratic for many declarations on one long line.

§Examples

let source = "// header\nsheet root {}\n// end\n";
let mut module = adam_lang::AdamAstParser::new().parse_module_str(source).unwrap();
adam_lang::attach_module_trivia(source, &mut module);
assert_eq!(module.comments.len(), 2);