-
Notifications
You must be signed in to change notification settings - Fork 17
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
Improve docs #64
Improve docs #64
Changes from 5 commits
be42c73
87b222a
1e8c6cc
d4db25c
5446f97
1eca556
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//! This script transforms _some_ Boxygen comments to Rustdoc format | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! I had been looking for something like this builtin to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm working on something more advanced on a personal repo, if you are interested to check it out: Techie-Pi/doxygen-rs |
||
//! | ||
//! # Usage | ||
//! | ||
//! ``cargo run --bin docstring-to-rustdoc -- [location of the bindings.rs]`` | ||
Techie-Pi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//! Example: ``cargo run --bin docstring-to-rustdoc -- src/bindings.rs`` | ||
//! | ||
//! # Transformations | ||
//! | ||
//! The following are _completely_ removed, but _its contents are kept_: | ||
//! * ``@brief`` | ||
//! * ``@ref`` | ||
//! * ``@note`` | ||
//! * ``@return`` | ||
//! * ``@sa`` | ||
//! * ``<`` | ||
//! * ``[out]`` and ``[in]`` | ||
//! | ||
//! The followings are _partially_ transformed to Rustdoc format: | ||
//! * ``@param`` | ||
|
||
use std::{env, fs, io}; | ||
Techie-Pi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use std::path::Path; | ||
|
||
fn main() -> io::Result<()> { | ||
let args: Vec<String> = env::args().collect(); | ||
|
||
let bindings_path = Path::new(args.get(1).expect("bindings.rs not provided in the args")); | ||
let bindings_string: String = fs::read_to_string(bindings_path)?; | ||
|
||
let parsed = bindings_string | ||
.lines() | ||
.map(|v| { | ||
// Only modify lines with the following structure: `` #[doc ... ] `` | ||
if v.trim_start().starts_with("#[doc") && v.trim_end().ends_with("]") { | ||
v | ||
.replace("@brief", "") | ||
// Example: ``@param offset Offset of the RomFS...`` -> ``- offset Offset of the RomFS...`` | ||
// Will improve in the future | ||
.replace("@param", "* ") | ||
.replace("@ref", "") | ||
.replace("@note", "") | ||
.replace("@return", "") | ||
.replace("@sa", "") | ||
.replace("< ", "") | ||
// Remove things like ``@param[out]`` | ||
.replace("[out]", "") | ||
.replace("[in]", "") | ||
// Trim start of the Rustdoc: ``...= " ...`` -> ``...= "...`` | ||
.replace("= \" ", "= \"") | ||
// Double pass because _most_ annotations are at the start | ||
.replace("= \" ", "= \"") | ||
} else { | ||
String::from(v) | ||
} | ||
}) | ||
.map(|v| { | ||
v + "\n" | ||
}) | ||
.collect::<String>(); | ||
|
||
let old_bindings_path = bindings_path.to_str().unwrap().to_owned() + ".old"; | ||
|
||
// If something fails, the original bindings are available at ``bindings.rs.old`` | ||
fs::rename(bindings_path, &old_bindings_path)?; | ||
fs::write(bindings_path, parsed)?; | ||
fs::remove_file(&old_bindings_path)?; | ||
|
||
Ok(()) | ||
} |
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.
Related (fyi): rust-lang/rust-bindgen#955
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.
Ohh, I didn't see that until now! Thanks, I'll check it out!
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.
Nothing's implemented there, but someone else did have the idea to open an issue at least.