Change pp indent to signed to allow negative indents
This commit is contained in:
parent
0b7e1baa58
commit
8bdf08fbed
4 changed files with 9 additions and 10 deletions
|
@ -392,7 +392,9 @@ impl Printer {
|
||||||
if size > self.space {
|
if size > self.space {
|
||||||
self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks });
|
self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks });
|
||||||
self.indent = match token.indent {
|
self.indent = match token.indent {
|
||||||
IndentStyle::Block { offset } => (self.indent as isize + offset) as usize,
|
IndentStyle::Block { offset } => {
|
||||||
|
usize::try_from(self.indent as isize + offset).unwrap()
|
||||||
|
}
|
||||||
IndentStyle::Visual => (MARGIN - self.space) as usize,
|
IndentStyle::Visual => (MARGIN - self.space) as usize,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,20 +3,17 @@ use std::borrow::Cow;
|
||||||
|
|
||||||
impl Printer {
|
impl Printer {
|
||||||
/// "raw box"
|
/// "raw box"
|
||||||
pub fn rbox(&mut self, indent: usize, breaks: Breaks) {
|
pub fn rbox(&mut self, indent: isize, breaks: Breaks) {
|
||||||
self.scan_begin(BeginToken {
|
self.scan_begin(BeginToken { indent: IndentStyle::Block { offset: indent }, breaks })
|
||||||
indent: IndentStyle::Block { offset: indent as isize },
|
|
||||||
breaks,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inconsistent breaking box
|
/// Inconsistent breaking box
|
||||||
pub fn ibox(&mut self, indent: usize) {
|
pub fn ibox(&mut self, indent: isize) {
|
||||||
self.rbox(indent, Breaks::Inconsistent)
|
self.rbox(indent, Breaks::Inconsistent)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consistent breaking box
|
/// Consistent breaking box
|
||||||
pub fn cbox(&mut self, indent: usize) {
|
pub fn cbox(&mut self, indent: isize) {
|
||||||
self.rbox(indent, Breaks::Consistent)
|
self.rbox(indent, Breaks::Consistent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ pub struct State<'a> {
|
||||||
ann: &'a (dyn PpAnn + 'a),
|
ann: &'a (dyn PpAnn + 'a),
|
||||||
}
|
}
|
||||||
|
|
||||||
crate const INDENT_UNIT: usize = 4;
|
crate const INDENT_UNIT: isize = 4;
|
||||||
|
|
||||||
/// Requires you to pass an input filename and reader so that
|
/// Requires you to pass an input filename and reader so that
|
||||||
/// it can scan the input text for comments to copy forward.
|
/// it can scan the input text for comments to copy forward.
|
||||||
|
|
|
@ -139,7 +139,7 @@ impl<'a> PrintState<'a> for State<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const INDENT_UNIT: usize = 4;
|
pub const INDENT_UNIT: isize = 4;
|
||||||
|
|
||||||
/// Requires you to pass an input filename and reader so that
|
/// Requires you to pass an input filename and reader so that
|
||||||
/// it can scan the input text for comments to copy forward.
|
/// it can scan the input text for comments to copy forward.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue