pub struct Printer<'a> { /* private fields */ }Expand description
Output buffer driven by the emit functions in crate::emit.
Implementations§
Source§impl<'a> Printer<'a>
impl<'a> Printer<'a>
pub fn new(interner: &'a ThreadedRodeo, src: &'a str) -> Self
Sourcepub fn write_str(&mut self, s: &str)
pub fn write_str(&mut self, s: &str)
Write s at the current cursor; emits pending indent first.
Sourcepub fn write_ident(&mut self, spur: Spur)
pub fn write_ident(&mut self, spur: Spur)
Resolve and emit an interned identifier.
Sourcepub fn resolve(&self, spur: Spur) -> &str
pub fn resolve(&self, spur: Spur) -> &str
Resolve an interned string without emitting it; callers re-escape before writing (e.g. string literals).
Sourcepub fn newline(&mut self)
pub fn newline(&mut self)
Begin a new line. Subsequent writes will be preceded by indent whitespace.
Sourcepub fn blank_line(&mut self)
pub fn blank_line(&mut self)
Emit a blank line between sibling items. Idempotent — repeated calls without intervening writes produce at most one blank line, matching the “at most one consecutive blank line” rule. Also no-ops when the cursor is directly inside a freshly-opened brace (style rule: “No blank line at the start of a block”).
pub fn indent(&mut self)
pub fn dedent(&mut self)
Sourcepub fn drain_trivia_before(&mut self, offset: u32)
pub fn drain_trivia_before(&mut self, offset: u32)
Drain every trivia entry whose start is strictly before offset —
these are the comments and blank-line runs that fall before the
next AST node.
Sourcepub fn drain_trivia_remaining(&mut self)
pub fn drain_trivia_remaining(&mut self)
Drain every remaining trivia entry — used once at end-of-AST to flush any trailing comments past the last item.
Sourcepub fn drain_trailing_comment_on_line(&mut self)
pub fn drain_trailing_comment_on_line(&mut self)
Drain // comment trivia that begins on the same source line as the
most recently emitted node. The comment is appended inline with two
leading spaces; the caller emits the terminating newline.
Call this immediately after mark_emitted_end and before the
newline() that ends the line — that ordering keeps the comment glued
to the statement/item it follows in source.
Sourcepub fn mark_emitted_end(&mut self, byte: u32)
pub fn mark_emitted_end(&mut self, byte: u32)
Record that the AST node ending at byte has just been emitted. Used
to decide whether a following comment is a trailing same-line one.