Expand description
Shared trivia recovery: turns the raw source text of a grammatically-constrained gap
(whitespace, comments, and a known fixed sequence of literal tokens) into an ordered sequence
of GapPieces, and converts proc_macro2 span positions to byte offsets. Used by
cel-parser’s own expression formatter and by adam-lang’s declaration formatter, so both
recover comments the same way. See https://github.com/stlab/cel-rs/issues/201.
Enums§
- Comment
- A recovered
////* */comment, remembering which delimiter style the source used so a formatter can reproduce it instead of normalizing every comment to one style. - GapPiece
- One element of a scanned gap: either a recovered comment or one of the literal tokens the caller declared it expected to find there.
Functions§
- line_
column_ to_ byte - Converts a
LineColumn(1-based line, 0-based character column) to a byte offset insource, usingline_starts(fromline_start_byte_offsets). - line_
start_ byte_ offsets - Returns the byte offset of the start of each line in
source:result[line - 1]is the start of 1-based lineline(matchingproc_macro2::LineColumn::line’s convention). - scan_
gap - Scans the raw text of a grammatically-constrained gap — whitespace,
////* */comments, and exactly the literal tokens inexpected, in that order — returning every comment found plus everyexpectedtoken, interleaved in source order. Block comments nest; their inner delimiters and text remain intact apart from per-line whitespace normalization.