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:
sheetwas parsed from exactlysource(unmodified), so its items’ spans’ line/column positions resolve correctly against it. -
Postcondition: preserves comment payload order. Multiple mixed or detached runs sharing one ordinary AST attachment normalize to line-comment text; a single comment retains its style.
-
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. O(l + g + h) space for source lines l, recovered/scanned gaps, and call depth h. Sharing line starts does not eliminate repeated prefix scans; c can be quadratic for many declarations on one long line.
§Examples
See crate::format_sheet for recovering trivia before formatting a parsed sheet.