1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
b0VIM 7.4 ��0U�g�- erickt Erick-Tryzelaar-MBP.local ~erickt/projects/rust/rust/src/libsyntax/print/pp.rs utf-8
3210 #"! U tp G � H S � d # m � ` � \ T ad @ G � � ] Z � � R . - �
�
�
k
4
0
� � L " � � : �
w
3
� � a � v ) % � � B > � � U
� w ' � � : � � R � g � � � � � � w e U C A @ ? } Inconsistent, Consistent, pub enum Breaks { #[derive(Clone, Copy, PartialEq)] use std::iter::repeat; use std::string; use std::io; //! avoid combining it with other lines and making matters even worse. //! line (which it can't) and so naturally place the content on its own line to //! by two zero-length breaks. The algorithm will try its best to fit it on a //! we want isolated to a line and an explicit length that's huge, surrounded //! and explicit blank lines. So in those cases we use a string with a payload //! rare case of "really small functions" or such. This re-occurs with comments //! "thing which should be on its own line" not getting its own line in the //! extra blank lines. If you don't put hardbreaks you can wind up with the //! there anyways (because the functions themselves are long) you wind up with //! each function (or before each) and the breaking algorithm decides to break //! line" between two long blocks, say functions. If you put a hardbreak after //! work. To see why, consider when there is a "thing that should be on its own //! hardbreak-like Break tokens with long blankness indication doesn't actually //! classes of comment and blank-line -- where relying on adjacent //! encoding things that are supposed to "go on their own line" -- certain //! the accompanying string. But it's necessary to permit it to differ, for //! explicit length for the string. For most tokens this is just the length of //! I also implemented a small change in the String token, in that I store an //! //! stack in terms of margin-col rather than col itself. I store col. //! the Mesa implementation (somewhat randomly) stores the offset on the print //! I also inverted the indentation arithmetic used in the print stack, since //! //! helps differentiate all the numbers flying around internally (slightly). //! for ints to "go negative" while carrying a pending-calculation balance, and //! ints for character-sizes-and-indentation-offsets. This respects the need //! somewhat readily? In any case, I've used usize for indices-in-buffers and //! CARDINAL in the Mesa implementation. Mesa apparently interconverts the two //! In particular you'll see a certain amount of churn related to INTEGER vs. //! //! non-idiomatic rust that it really stuck out. //! changing only what was blatantly wrong, a typo, or sufficiently //! paper, I've opted to keep the implementation here as similar as I can, //! Despite some redundancies and quirks in the way it's implemented in that //! //! it's 32 years old. What can I say? //! concerns I've seen other pretty-printers fall down on. Weirdly. Even though //! documentation explaining its theory, and because it addresses the set of //! I am implementing this algorithm because it comes with 20 pages of //! //! example, between "x" and ")" in "x)". //! block, and avoiding breaking at silly places on block boundaries, for //! while respecting the indentation-consistency requirements of the enclosing //! The algorithm's aim is to break a stream into as few lines as possible //! //! Stanford Department of Computer Science, 1979. //! STAN-CS-79-770: "Pretty Printing", by Derek C. Oppen. //! //! Mesa pretty-printer, as described in appendix A of //! This pretty-printer is a direct reimplementation of Philip Karlton's // except according to those terms. // option. This file may not be copied, modified, or distributed // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or //