• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::pp::{BeginToken, BreakToken, Breaks, IndentStyle, Printer, Token, SIZE_INFINITY};
2 use std::borrow::Cow;
3 
4 impl Printer {
5     /// "raw box"
rbox(&mut self, indent: isize, breaks: Breaks)6     pub fn rbox(&mut self, indent: isize, breaks: Breaks) {
7         self.scan_begin(BeginToken { indent: IndentStyle::Block { offset: indent }, breaks })
8     }
9 
10     /// Inconsistent breaking box
ibox(&mut self, indent: isize)11     pub fn ibox(&mut self, indent: isize) {
12         self.rbox(indent, Breaks::Inconsistent)
13     }
14 
15     /// Consistent breaking box
cbox(&mut self, indent: isize)16     pub fn cbox(&mut self, indent: isize) {
17         self.rbox(indent, Breaks::Consistent)
18     }
19 
visual_align(&mut self)20     pub fn visual_align(&mut self) {
21         self.scan_begin(BeginToken { indent: IndentStyle::Visual, breaks: Breaks::Consistent });
22     }
23 
break_offset(&mut self, n: usize, off: isize)24     pub fn break_offset(&mut self, n: usize, off: isize) {
25         self.scan_break(BreakToken {
26             offset: off,
27             blank_space: n as isize,
28             ..BreakToken::default()
29         });
30     }
31 
end(&mut self)32     pub fn end(&mut self) {
33         self.scan_end()
34     }
35 
eof(mut self) -> String36     pub fn eof(mut self) -> String {
37         self.scan_eof();
38         self.out
39     }
40 
word<S: Into<Cow<'static, str>>>(&mut self, wrd: S)41     pub fn word<S: Into<Cow<'static, str>>>(&mut self, wrd: S) {
42         let string = wrd.into();
43         self.scan_string(string)
44     }
45 
spaces(&mut self, n: usize)46     fn spaces(&mut self, n: usize) {
47         self.break_offset(n, 0)
48     }
49 
zerobreak(&mut self)50     pub fn zerobreak(&mut self) {
51         self.spaces(0)
52     }
53 
space(&mut self)54     pub fn space(&mut self) {
55         self.spaces(1)
56     }
57 
hardbreak(&mut self)58     pub fn hardbreak(&mut self) {
59         self.spaces(SIZE_INFINITY as usize)
60     }
61 
is_beginning_of_line(&self) -> bool62     pub fn is_beginning_of_line(&self) -> bool {
63         match self.last_token() {
64             Some(last_token) => last_token.is_hardbreak_tok(),
65             None => true,
66         }
67     }
68 
hardbreak_tok_offset(off: isize) -> Token69     pub fn hardbreak_tok_offset(off: isize) -> Token {
70         Token::Break(BreakToken {
71             offset: off,
72             blank_space: SIZE_INFINITY,
73             ..BreakToken::default()
74         })
75     }
76 
trailing_comma(&mut self)77     pub fn trailing_comma(&mut self) {
78         self.scan_break(BreakToken { pre_break: Some(','), ..BreakToken::default() });
79     }
80 
trailing_comma_or_space(&mut self)81     pub fn trailing_comma_or_space(&mut self) {
82         self.scan_break(BreakToken {
83             blank_space: 1,
84             pre_break: Some(','),
85             ..BreakToken::default()
86         });
87     }
88 }
89 
90 impl Token {
is_hardbreak_tok(&self) -> bool91     pub fn is_hardbreak_tok(&self) -> bool {
92         *self == Printer::hardbreak_tok_offset(0)
93     }
94 }
95