Skip to main content

attach_trivia

Function attach_trivia 

Source
pub fn attach_trivia(source: &str, sheet: &mut Sheet)
Expand description

Recovers comments/blank-lines from every gap in sheet — a leading comment before the sheet keyword itself, its own top-level items, and every nested relationship/conditional body — attaching each to the nearest following node.

  • Precondition: sheet was parsed from exactly source (unmodified), so its items’ spans’ line/column positions resolve correctly against it.

  • Complexity: O(n) in the length of source plus the number of nested lists — every gap’s LineColumn -> byte offset conversion reuses the shared line_starts table computed once up front (see line_start_byte_offsets), rather than rescanning source per gap.