diff options
Diffstat (limited to 'xtask/src/codegen.rs')
-rw-r--r-- | xtask/src/codegen.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 948b86719..bf3a90119 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs | |||
@@ -8,7 +8,7 @@ | |||
8 | mod gen_syntax; | 8 | mod gen_syntax; |
9 | mod gen_parser_tests; | 9 | mod gen_parser_tests; |
10 | 10 | ||
11 | use std::{fs, path::Path}; | 11 | use std::{fs, mem, path::Path}; |
12 | 12 | ||
13 | use crate::Result; | 13 | use crate::Result; |
14 | 14 | ||
@@ -44,3 +44,26 @@ pub fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { | |||
44 | fs::write(path, contents)?; | 44 | fs::write(path, contents)?; |
45 | Ok(()) | 45 | Ok(()) |
46 | } | 46 | } |
47 | |||
48 | fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> { | ||
49 | let mut res = Vec::new(); | ||
50 | |||
51 | let prefix = "// "; | ||
52 | let lines = text.lines().map(str::trim_start); | ||
53 | |||
54 | let mut block = vec![]; | ||
55 | for line in lines { | ||
56 | let is_comment = line.starts_with(prefix); | ||
57 | if is_comment { | ||
58 | block.push(line[prefix.len()..].to_string()); | ||
59 | } else { | ||
60 | if !block.is_empty() { | ||
61 | res.push(mem::replace(&mut block, Vec::new())) | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | if !block.is_empty() { | ||
66 | res.push(mem::replace(&mut block, Vec::new())) | ||
67 | } | ||
68 | res | ||
69 | } | ||