-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implementation of fmt #272
Conversation
Note: for now, this version does not use Knuth-Plass, but everything else is in place with "greedy" breaking. All options (should) work, and performance is nearly on par with GNU fmt. Squashed commit of the following local commits: commit ebc12f5 commit 125fdab commit dadd62a commit e436fda commit bbc4f4f commit 12bc4ec commit 2e69355 commit 9b15a13 commit ea335eb Merge: ee92573 23cc41d commit 23cc41d commit 2fa7c48 commit eb71558 commit c8baabc commit ee4fab4 commit c544441 commit e1177d4 commit c7fb30e commit 99a9406 commit 3d244d6 commit 2d4f09c commit 947c32b commit 8556d2a commit a2e4bc3 Merge: 0308884 439e65d commit 0308884 commit ac80d88 commit c1d6b36 commit 6539b10 commit 439e65d commit fac27de commit 365989c commit 3dd7136
($exp:expr) => ( | ||
match $exp { | ||
Ok(_) => (), | ||
Err(_) => unsafe { ::libc::exit(1) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be fail!()
instead of ::libc::exit(1)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of this was to exit silently if writing to stdout fails. This will happen, e.g., if we get a broken pipe. GNU utils for the most part do not report "Broken pipe" in this case.
If you'd prefer, I can just use crash! or the like here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see what you mean. I suppose this is fine.
Basically all of my problems are with spacing right now. I think the rest of the code is good. Does this support all of the GNU options (you said "sort of a combination" above). |
Got it. I'm pulling in all your comments now, just have to check that I haven't broken anything! Thanks for the review. Thorough and helpful as I get my Rust-style-legs under me :) It supports all of the GNU options with almost identical semantics. The only place where I explicitly broke with GNU semantics is in tagged-paragraph mode. Specifically, if in this mode AND we have a single long line by itself, we have to determine what the indent is. In GNU fmt, it seems to choose the smallest column number divisible by three. To me that is just weird. So I said that we will indent 4 extra spaces in this case. (Note that if we're in tagged paragraph mode and a paragraph has multiple lines in the source file, then the following lines determine this indent level for us, so this is a pretty narrow case.) The additional options that I added are:
I'll add another commit to address your comments. I'm not 100% sure on the |
// handle "init" portion | ||
silent_unwrap!(ostream.write(para.init_str.as_bytes())); | ||
para.init_len | ||
} else if ! para.mail_header { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!
issue from before.
|
||
// iterator that produces a stream of Lines from a file | ||
struct FileLines<'a> { | ||
opts : &'a FmtOptions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing.
Your welcome. :) The indentation thing that you did seems reasonable, so I suppose it's okay that it's not 100% compatible with GNU. Also, the arguments you added seem nice. You handled the struct formatting thing in a nice way (sorry that I wasn't very clear before). |
Some(t) => t, | ||
None => { crash!(1, "Invalid GOAL specification: `{}'", s); } | ||
}; | ||
if ! matches.opt_present("w") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, I missed this one too. Sorry. :(
I believe all your comments are addressed now. I can squash those last few commits if you don't want me to muck up the history. |
Yeah, please squash the last few. |
Done, and thanks again for the comments :) I should have the Knuth-Plass implementation done in the next couple days, which will make the line breaking somewhat prettier but with a (hopefully only slight) speed impact. |
No problem. :) That sounds good. Looking forward to seeing it. |
implementation of fmt
I've got an initial implementation of fmt completed. The options are sort of a combination of GNU and BSD, with a couple extra minor ones that I added because it seemed sensible and relatively straightforward.
Note: for now, this version does not use Knuth-Plass, but everything else is in place using "greedy" breaking. I've got a working Knuth-Plass implementation in Haskell that I'm going to port over.
All options (should) work, and performance is nearly on par with GNU fmt.
(GNU fmt is the first run, this version is the second.)