mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Generalize
This commit is contained in:
parent
e1829d8959
commit
383247a9ae
@ -61,8 +61,24 @@ fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> {
|
|||||||
do_extract_comment_blocks(text, false)
|
do_extract_comment_blocks(text, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_comment_blocks_with_empty_lines(text: &str) -> Vec<Vec<String>> {
|
fn extract_comment_blocks_with_empty_lines(tag: &str, text: &str) -> Vec<CommentBlock> {
|
||||||
do_extract_comment_blocks(text, true)
|
assert!(tag.starts_with(char::is_uppercase));
|
||||||
|
let tag = format!("{}:", tag);
|
||||||
|
let mut res = Vec::new();
|
||||||
|
for mut block in do_extract_comment_blocks(text, true) {
|
||||||
|
let first = block.remove(0);
|
||||||
|
if first.starts_with(&tag) {
|
||||||
|
let id = first[tag.len()..].trim().to_string();
|
||||||
|
let block = CommentBlock { id, contents: block };
|
||||||
|
res.push(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CommentBlock {
|
||||||
|
id: String,
|
||||||
|
contents: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lines: bool) -> Vec<Vec<String>> {
|
fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lines: bool) -> Vec<Vec<String>> {
|
||||||
|
@ -33,22 +33,18 @@ impl Assist {
|
|||||||
|
|
||||||
fn collect_file(acc: &mut Vec<Assist>, path: &Path) -> Result<()> {
|
fn collect_file(acc: &mut Vec<Assist>, path: &Path) -> Result<()> {
|
||||||
let text = fs::read_to_string(path)?;
|
let text = fs::read_to_string(path)?;
|
||||||
let comment_blocks = extract_comment_blocks_with_empty_lines(&text);
|
let comment_blocks = extract_comment_blocks_with_empty_lines("Assist", &text);
|
||||||
|
|
||||||
for block in comment_blocks {
|
for block in comment_blocks {
|
||||||
// FIXME: doesn't support blank lines yet, need to tweak
|
// FIXME: doesn't support blank lines yet, need to tweak
|
||||||
// `extract_comment_blocks` for that.
|
// `extract_comment_blocks` for that.
|
||||||
let mut lines = block.iter();
|
let id = block.id;
|
||||||
let first_line = lines.next().unwrap();
|
|
||||||
if !first_line.starts_with("Assist: ") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let id = first_line["Assist: ".len()..].to_string();
|
|
||||||
assert!(
|
assert!(
|
||||||
id.chars().all(|it| it.is_ascii_lowercase() || it == '_'),
|
id.chars().all(|it| it.is_ascii_lowercase() || it == '_'),
|
||||||
"invalid assist id: {:?}",
|
"invalid assist id: {:?}",
|
||||||
id
|
id
|
||||||
);
|
);
|
||||||
|
let mut lines = block.contents.iter();
|
||||||
|
|
||||||
let doc = take_until(lines.by_ref(), "```").trim().to_string();
|
let doc = take_until(lines.by_ref(), "```").trim().to_string();
|
||||||
assert!(
|
assert!(
|
||||||
|
Loading…
Reference in New Issue
Block a user