aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/codegen.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src/codegen.rs')
-rw-r--r--xtask/src/codegen.rs27
1 files changed, 22 insertions, 5 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index b4907f4b2..f47d54125 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -8,14 +8,15 @@
8mod gen_syntax; 8mod gen_syntax;
9mod gen_parser_tests; 9mod gen_parser_tests;
10mod gen_assists_docs; 10mod gen_assists_docs;
11mod gen_feature_docs;
11 12
12use std::{mem, path::Path}; 13use std::{mem, path::Path};
13 14
14use crate::{not_bash::fs2, Result}; 15use crate::{not_bash::fs2, Result};
15 16
16pub use self::{ 17pub use self::{
17 gen_assists_docs::generate_assists_docs, gen_parser_tests::generate_parser_tests, 18 gen_assists_docs::generate_assists_docs, gen_feature_docs::generate_feature_docs,
18 gen_syntax::generate_syntax, 19 gen_parser_tests::generate_parser_tests, gen_syntax::generate_syntax,
19}; 20};
20 21
21const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; 22const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar";
@@ -40,7 +41,7 @@ pub enum Mode {
40/// With verify = false, 41/// With verify = false,
41fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { 42fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
42 match fs2::read_to_string(path) { 43 match fs2::read_to_string(path) {
43 Ok(ref old_contents) if normalize(old_contents) == normalize(contents) => { 44 Ok(old_contents) if normalize(&old_contents) == normalize(contents) => {
44 return Ok(()); 45 return Ok(());
45 } 46 }
46 _ => (), 47 _ => (),
@@ -61,8 +62,24 @@ fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> {
61 do_extract_comment_blocks(text, false) 62 do_extract_comment_blocks(text, false)
62} 63}
63 64
64fn extract_comment_blocks_with_empty_lines(text: &str) -> Vec<Vec<String>> { 65fn extract_comment_blocks_with_empty_lines(tag: &str, text: &str) -> Vec<CommentBlock> {
65 do_extract_comment_blocks(text, true) 66 assert!(tag.starts_with(char::is_uppercase));
67 let tag = format!("{}:", tag);
68 let mut res = Vec::new();
69 for mut block in do_extract_comment_blocks(text, true) {
70 let first = block.remove(0);
71 if first.starts_with(&tag) {
72 let id = first[tag.len()..].trim().to_string();
73 let block = CommentBlock { id, contents: block };
74 res.push(block);
75 }
76 }
77 res
78}
79
80struct CommentBlock {
81 id: String,
82 contents: Vec<String>,
66} 83}
67 84
68fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lines: bool) -> Vec<Vec<String>> { 85fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lines: bool) -> Vec<Vec<String>> {