Use old parser if custom_code_classes_in_docs
feature is not enabled
This commit is contained in:
parent
078eb1120a
commit
6f47a858f2
1 changed files with 135 additions and 104 deletions
|
@ -868,7 +868,7 @@ impl<'tcx> ExtraInfo<'tcx> {
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Clone, Debug)]
|
#[derive(Eq, PartialEq, Clone, Debug)]
|
||||||
pub(crate) struct LangString {
|
pub(crate) struct LangString {
|
||||||
original: String,
|
pub(crate) original: String,
|
||||||
pub(crate) should_panic: bool,
|
pub(crate) should_panic: bool,
|
||||||
pub(crate) no_run: bool,
|
pub(crate) no_run: bool,
|
||||||
pub(crate) ignore: Ignore,
|
pub(crate) ignore: Ignore,
|
||||||
|
@ -1158,6 +1158,29 @@ impl<'a, 'tcx> Iterator for TagIterator<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn tokens(string: &str) -> impl Iterator<Item = LangStringToken<'_>> {
|
||||||
|
// Pandoc, which Rust once used for generating documentation,
|
||||||
|
// expects lang strings to be surrounded by `{}` and for each token
|
||||||
|
// to be proceeded by a `.`. Since some of these lang strings are still
|
||||||
|
// loose in the wild, we strip a pair of surrounding `{}` from the lang
|
||||||
|
// string and a leading `.` from each token.
|
||||||
|
|
||||||
|
let string = string.trim();
|
||||||
|
|
||||||
|
let first = string.chars().next();
|
||||||
|
let last = string.chars().last();
|
||||||
|
|
||||||
|
let string =
|
||||||
|
if first == Some('{') && last == Some('}') { &string[1..string.len() - 1] } else { string };
|
||||||
|
|
||||||
|
string
|
||||||
|
.split(|c| c == ',' || c == ' ' || c == '\t')
|
||||||
|
.map(str::trim)
|
||||||
|
.map(|token| token.strip_prefix('.').unwrap_or(token))
|
||||||
|
.filter(|token| !token.is_empty())
|
||||||
|
.map(|token| LangStringToken::LangToken(token))
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for LangString {
|
impl Default for LangString {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -1208,7 +1231,8 @@ impl LangString {
|
||||||
|
|
||||||
data.original = string.to_owned();
|
data.original = string.to_owned();
|
||||||
|
|
||||||
for token in TagIterator::new(string, extra) {
|
let mut call = |tokens: &mut dyn Iterator<Item = LangStringToken<'_>>| {
|
||||||
|
for token in tokens {
|
||||||
match token {
|
match token {
|
||||||
LangStringToken::LangToken("should_panic") => {
|
LangStringToken::LangToken("should_panic") => {
|
||||||
data.should_panic = true;
|
data.should_panic = true;
|
||||||
|
@ -1325,6 +1349,13 @@ impl LangString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if custom_code_classes_in_docs {
|
||||||
|
call(&mut TagIterator::new(string, extra).into_iter())
|
||||||
|
} else {
|
||||||
|
call(&mut tokens(string))
|
||||||
|
}
|
||||||
|
|
||||||
// ignore-foo overrides ignore
|
// ignore-foo overrides ignore
|
||||||
if !ignores.is_empty() {
|
if !ignores.is_empty() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue