]> git.lizzy.rs Git - rust.git/commitdiff
internal: simplify
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 13 Sep 2021 10:35:31 +0000 (13:35 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 13 Sep 2021 10:35:31 +0000 (13:35 +0300)
crates/parser/src/grammar/patterns.rs
crates/sourcegen/src/lib.rs

index fed5cca512d0e576671d04165ba17b98cdbfd0f3..81e2051abb58134638954dd0cb8909b404ce3d0e 100644 (file)
@@ -17,7 +17,7 @@ pub(crate) fn pattern(p: &mut Parser) {
     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) {
     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 `|`
-/// using the given `recovery_set`
+/// using the given `recovery_set`.
 pub(super) fn pattern_top_r(p: &mut Parser, recovery_set: TokenSet) {
     p.eat(T![|]);
     pattern_r(p, recovery_set);
 }
 
 /// Parses a pattern list separated by pipes `|`, with no leading `|`,using the
-/// given `recovery_set`
+/// given `recovery_set`.
+
 // test or_pattern
 // fn main() {
 //     match () {
index d9226d0681c92cc8c20cbebc86a4007e1b6a7708..ae07190f8632d6bccfc794660f1c6e6b9b483077 100644 (file)
@@ -71,25 +71,25 @@ pub fn extract(tag: &str, text: &str) -> Vec<CommentBlock> {
     pub fn extract_untagged(text: &str) -> Vec<CommentBlock> {
         let mut res = Vec::new();
 
-        let prefix = "// ";
         let lines = text.lines().map(str::trim_start);
 
         let dummy_block = CommentBlock { id: String::new(), line: 0, contents: Vec::new() };
         let mut block = dummy_block.clone();
         for (line_num, line) in lines.enumerate() {
-            if line == "//" {
-                block.contents.push(String::new());
-                continue;
-            }
-
-            let is_comment = line.starts_with(prefix);
-            if is_comment {
-                block.contents.push(line[prefix.len()..].to_string());
-            } else {
-                if !block.contents.is_empty() {
-                    res.push(mem::replace(&mut block, dummy_block.clone()));
+            match line.strip_prefix("//") {
+                Some(mut contents) => {
+                    if let Some(' ') = contents.chars().next() {
+                        contents = &contents[1..];
+                    }
+                    block.contents.push(contents.to_string());
+                }
+                None => {
+                    if !block.contents.is_empty() {
+                        let block = 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() {