Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed May 16, 2024
1 parent e0c02e7 commit 4e47f09
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions prqlc/prqlc/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ pub trait WriteSource: std::fmt::Debug {
Some(r)
}

/// Attempts to write the current item, expanding the maximum width where necessary.
fn write_or_expand(&self, mut opt: WriteOpt) -> String {
loop {
if let Some(s) = self.write(opt.clone()) {
return s;
} else {
// TODO: could we just set the max width rather than increasing
// it in a loop?
opt.max_width += opt.max_width / 2;
opt.reset_line();
}
Expand Down Expand Up @@ -113,6 +116,8 @@ impl WriteOpt {
Some(())
}

/// Sets [WriteOpt::rem_width] to (max_width - indent_width), returning
/// `Some(())`, or `None` if there's not enough space.
fn reset_line(&mut self) -> Option<()> {
let ident = self.tab.len() as u16 * self.indent;
self.rem_width = self.max_width.checked_sub(ident)?;
Expand Down

0 comments on commit 4e47f09

Please sign in to comment.