internal: simplify

This commit is contained in:
Aleksey Kladov 2021-09-13 13:35:31 +03:00
parent 940b3afd00
commit c56f041477
2 changed files with 17 additions and 16 deletions

View file

@ -17,7 +17,7 @@ pub(crate) fn pattern(p: &mut Parser) {
pattern_r(p, PAT_RECOVERY_SET); pattern_r(p, PAT_RECOVERY_SET);
} }
/// Parses a pattern list separated by pipes `|` /// Parses a pattern list separated by pipes `|`.
pub(super) fn pattern_top(p: &mut Parser) { pub(super) fn pattern_top(p: &mut Parser) {
pattern_top_r(p, PAT_RECOVERY_SET) pattern_top_r(p, PAT_RECOVERY_SET)
} }
@ -27,14 +27,15 @@ pub(crate) fn pattern_single(p: &mut Parser) {
} }
/// Parses a pattern list separated by pipes `|` /// Parses a pattern list separated by pipes `|`
/// using the given `recovery_set` /// using the given `recovery_set`.
pub(super) fn pattern_top_r(p: &mut Parser, recovery_set: TokenSet) { pub(super) fn pattern_top_r(p: &mut Parser, recovery_set: TokenSet) {
p.eat(T![|]); p.eat(T![|]);
pattern_r(p, recovery_set); pattern_r(p, recovery_set);
} }
/// Parses a pattern list separated by pipes `|`, with no leading `|`,using the /// Parses a pattern list separated by pipes `|`, with no leading `|`,using the
/// given `recovery_set` /// given `recovery_set`.
// test or_pattern // test or_pattern
// fn main() { // fn main() {
// match () { // match () {

View file

@ -71,25 +71,25 @@ impl CommentBlock {
pub fn extract_untagged(text: &str) -> Vec<CommentBlock> { pub fn extract_untagged(text: &str) -> Vec<CommentBlock> {
let mut res = Vec::new(); let mut res = Vec::new();
let prefix = "// ";
let lines = text.lines().map(str::trim_start); let lines = text.lines().map(str::trim_start);
let dummy_block = CommentBlock { id: String::new(), line: 0, contents: Vec::new() }; let dummy_block = CommentBlock { id: String::new(), line: 0, contents: Vec::new() };
let mut block = dummy_block.clone(); let mut block = dummy_block.clone();
for (line_num, line) in lines.enumerate() { for (line_num, line) in lines.enumerate() {
if line == "//" { match line.strip_prefix("//") {
block.contents.push(String::new()); Some(mut contents) => {
continue; if let Some(' ') = contents.chars().next() {
} contents = &contents[1..];
}
let is_comment = line.starts_with(prefix); block.contents.push(contents.to_string());
if is_comment { }
block.contents.push(line[prefix.len()..].to_string()); None => {
} else { if !block.contents.is_empty() {
if !block.contents.is_empty() { let block = mem::replace(&mut block, dummy_block.clone());
res.push(mem::replace(&mut block, dummy_block.clone())); res.push(block);
}
block.line = line_num + 2;
} }
block.line = line_num + 2;
} }
} }
if !block.contents.is_empty() { if !block.contents.is_empty() {