-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Quotes from doc comments are unnecessarily escaped #885
Comments
The discussion about What didn't convince me last time was the suggestion to create extra intermediate representations for input literals -- if at all, litr types should just be used at the parsing stage, and then converted to canonical Rust ones ( Maybe we should check more concretely which other places could benefit from it? |
I believe you linked wrong snippet: gdext/godot-macros/src/docs.rs Line 139 in 90d8064
.filter(|x| x.get_single_path_segment().is_some_and(|x| x == "doc")) ) to handle inline attributes such as:
#[doc = r#"this is very documented"#]
#[var]
item: f32, |
@Yarwin you've probably missed the comment before this snippet: gdext/godot-macros/src/docs.rs Line 102 in 90d8064
The doc comments are expanded to regular, non-raw strings. This means that quotes inside these doc strings are always escaped with Also, note that some other characters are also escaped. For example, try using a tab inside a doc string: /// a b You'll get |
You are right, sorry for doubting you! – it was a bit late. pub fn unescape(escaped: &str) -> String {
let mut unescaped_string = String::new();
let mut iterator = escaped.chars();
while let Some(c) = iterator.next() {
match c {
'\\' => match iterator.next() {
Some('t') => {
unescaped_string.push_str(r#" "#)
},
Some('"') => {
unescaped_string.push('"')
},
Some(other) => {
unescaped_string.push(c);
unescaped_string.push(other);
}
None => unescaped_string.push(c),
},
_ => unescaped_string.push(c)
}
}
unescaped_string
}
(…)
unescape(&x.to_string()
.trim_start_matches('r')
.trim_start_matches('#')
.trim_start_matches('"')
.trim_end_matches('#')
.trim_end_matches('"'))
}) (obviously |
Or we try with |
This is what I originally planned to do, but then I opened The Rust Reference and got |
I literally copied godot/tests/docs.rs into a new project and got this:
The quotes are "double"-escaped because of Rust string literals:
gdext/godot-macros/src/docs.rs
Lines 113 to 123 in 90d8064
Can probably be fixed with litrs:
but not sure adding a new dependency is a good idea
The text was updated successfully, but these errors were encountered: