aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-08-19 10:26:34 +0100
committerAleksey Kladov <[email protected]>2019-08-19 10:26:34 +0100
commit038975b348b03dd3063d14cabd30fa71b010baea (patch)
tree43535287459df418afd25f0a672f187f4355f3d7 /crates
parentaa250ff612b10c02bfbc197557adfd4c70e01e43 (diff)
plug new boilerplate_gen into ra_tools
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs4
-rw-r--r--crates/ra_tools/src/boilerplate_gen.rs34
-rw-r--r--crates/ra_tools/src/lib.rs2
-rw-r--r--crates/ra_tools/src/main.rs6
-rw-r--r--crates/ra_tools/tests/cli.rs4
5 files changed, 26 insertions, 24 deletions
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs
index 75f5fb64c..415839cb5 100644
--- a/crates/ra_parser/src/syntax_kind/generated.rs
+++ b/crates/ra_parser/src/syntax_kind/generated.rs
@@ -557,10 +557,6 @@ impl SyntaxKind {
557 "try" => TRY_KW, 557 "try" => TRY_KW,
558 "box" => BOX_KW, 558 "box" => BOX_KW,
559 "await" => AWAIT_KW, 559 "await" => AWAIT_KW,
560 "auto" => AUTO_KW,
561 "default" => DEFAULT_KW,
562 "existential" => EXISTENTIAL_KW,
563 "union" => UNION_KW,
564 _ => return None, 560 _ => return None,
565 }; 561 };
566 Some(kw) 562 Some(kw)
diff --git a/crates/ra_tools/src/boilerplate_gen.rs b/crates/ra_tools/src/boilerplate_gen.rs
index 5547d6969..7ef51e82a 100644
--- a/crates/ra_tools/src/boilerplate_gen.rs
+++ b/crates/ra_tools/src/boilerplate_gen.rs
@@ -2,7 +2,6 @@ use std::{
2 collections::BTreeMap, 2 collections::BTreeMap,
3 fs, 3 fs,
4 io::Write, 4 io::Write,
5 path::Path,
6 process::{Command, Stdio}, 5 process::{Command, Stdio},
7}; 6};
8 7
@@ -12,7 +11,7 @@ use quote::{format_ident, quote};
12use ron; 11use ron;
13use serde::Deserialize; 12use serde::Deserialize;
14 13
15use crate::{project_root, Mode, Result, AST, GRAMMAR, SYNTAX_KINDS}; 14use crate::{project_root, update, Mode, Result, AST, GRAMMAR, SYNTAX_KINDS};
16 15
17pub fn generate_boilerplate(mode: Mode) -> Result<()> { 16pub fn generate_boilerplate(mode: Mode) -> Result<()> {
18 let grammar = project_root().join(GRAMMAR); 17 let grammar = project_root().join(GRAMMAR);
@@ -21,11 +20,14 @@ pub fn generate_boilerplate(mode: Mode) -> Result<()> {
21 ron::de::from_str(&text)? 20 ron::de::from_str(&text)?
22 }; 21 };
23 22
24 let _syntax_kinds = project_root().join(SYNTAX_KINDS); 23 let syntax_kinds_file = project_root().join(SYNTAX_KINDS);
25 let _ast = project_root().join(AST); 24 let syntax_kinds = generate_syntax_kinds(&grammar)?;
25 update(syntax_kinds_file.as_path(), &syntax_kinds, mode)?;
26
27 let ast_file = project_root().join(AST);
28 let ast = generate_ast(&grammar)?;
29 update(ast_file.as_path(), &ast, mode)?;
26 30
27 let ast = generate_syntax_kinds(&grammar)?;
28 println!("{}", ast);
29 Ok(()) 31 Ok(())
30} 32}
31 33
@@ -172,10 +174,14 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> {
172 .chain(grammar.multi_byte_tokens.iter().map(|(_token, name)| format_ident!("{}", name))) 174 .chain(grammar.multi_byte_tokens.iter().map(|(_token, name)| format_ident!("{}", name)))
173 .collect::<Vec<_>>(); 175 .collect::<Vec<_>>();
174 176
175 let keywords_values = 177 let full_keywords_values = &grammar.keywords;
178 let full_keywords =
179 full_keywords_values.iter().map(|kw| format_ident!("{}_KW", kw.to_shouty_snake_case()));
180
181 let all_keywords_values =
176 grammar.keywords.iter().chain(grammar.contextual_keywords.iter()).collect::<Vec<_>>(); 182 grammar.keywords.iter().chain(grammar.contextual_keywords.iter()).collect::<Vec<_>>();
177 let keywords_idents = keywords_values.iter().map(|kw| format_ident!("{}", kw)); 183 let all_keywords_idents = all_keywords_values.iter().map(|kw| format_ident!("{}", kw));
178 let keywords = keywords_values 184 let all_keywords = all_keywords_values
179 .iter() 185 .iter()
180 .map(|name| format_ident!("{}_KW", name.to_shouty_snake_case())) 186 .map(|name| format_ident!("{}_KW", name.to_shouty_snake_case()))
181 .collect::<Vec<_>>(); 187 .collect::<Vec<_>>();
@@ -202,7 +208,7 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> {
202 #[doc(hidden)] 208 #[doc(hidden)]
203 EOF, 209 EOF,
204 #(#punctuation,)* 210 #(#punctuation,)*
205 #(#keywords,)* 211 #(#all_keywords,)*
206 #(#literals,)* 212 #(#literals,)*
207 #(#tokens,)* 213 #(#tokens,)*
208 #(#nodes,)* 214 #(#nodes,)*
@@ -229,7 +235,7 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> {
229 impl SyntaxKind { 235 impl SyntaxKind {
230 pub fn is_keyword(self) -> bool { 236 pub fn is_keyword(self) -> bool {
231 match self { 237 match self {
232 #(#keywords)|* => true, 238 #(#all_keywords)|* => true,
233 _ => false, 239 _ => false,
234 } 240 }
235 } 241 }
@@ -251,7 +257,7 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> {
251 pub(crate) fn info(self) -> &'static SyntaxInfo { 257 pub(crate) fn info(self) -> &'static SyntaxInfo {
252 match self { 258 match self {
253 #(#punctuation => &SyntaxInfo { name: stringify!(#punctuation) },)* 259 #(#punctuation => &SyntaxInfo { name: stringify!(#punctuation) },)*
254 #(#keywords => &SyntaxInfo { name: stringify!(#keywords) },)* 260 #(#all_keywords => &SyntaxInfo { name: stringify!(#all_keywords) },)*
255 #(#literals => &SyntaxInfo { name: stringify!(#literals) },)* 261 #(#literals => &SyntaxInfo { name: stringify!(#literals) },)*
256 #(#tokens => &SyntaxInfo { name: stringify!(#tokens) },)* 262 #(#tokens => &SyntaxInfo { name: stringify!(#tokens) },)*
257 #(#nodes => &SyntaxInfo { name: stringify!(#nodes) },)* 263 #(#nodes => &SyntaxInfo { name: stringify!(#nodes) },)*
@@ -263,7 +269,7 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> {
263 269
264 pub fn from_keyword(ident: &str) -> Option<SyntaxKind> { 270 pub fn from_keyword(ident: &str) -> Option<SyntaxKind> {
265 let kw = match ident { 271 let kw = match ident {
266 #(#keywords_values => #keywords,)* 272 #(#full_keywords_values => #full_keywords,)*
267 _ => return None, 273 _ => return None,
268 }; 274 };
269 Some(kw) 275 Some(kw)
@@ -281,7 +287,7 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> {
281 #[macro_export] 287 #[macro_export]
282 macro_rules! T { 288 macro_rules! T {
283 #((#punctuation_values) => { $crate::SyntaxKind::#punctuation };)* 289 #((#punctuation_values) => { $crate::SyntaxKind::#punctuation };)*
284 #((#keywords_idents) => { $crate::SyntaxKind::#keywords };)* 290 #((#all_keywords_idents) => { $crate::SyntaxKind::#all_keywords };)*
285 } 291 }
286 }; 292 };
287 293
diff --git a/crates/ra_tools/src/lib.rs b/crates/ra_tools/src/lib.rs
index f1829d55a..d47660369 100644
--- a/crates/ra_tools/src/lib.rs
+++ b/crates/ra_tools/src/lib.rs
@@ -20,7 +20,7 @@ const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar";
20const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok"; 20const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok";
21const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err"; 21const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err";
22 22
23pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs.tera"; 23pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs";
24pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs"; 24pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs";
25const TOOLCHAIN: &str = "stable"; 25const TOOLCHAIN: &str = "stable";
26 26
diff --git a/crates/ra_tools/src/main.rs b/crates/ra_tools/src/main.rs
index 54d96e446..03cb9d5a7 100644
--- a/crates/ra_tools/src/main.rs
+++ b/crates/ra_tools/src/main.rs
@@ -1,8 +1,8 @@
1use clap::{App, Arg, SubCommand}; 1use clap::{App, Arg, SubCommand};
2use core::str; 2use core::str;
3use ra_tools::{ 3use ra_tools::{
4 gen_tests, generate, install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, Cmd, 4 gen_tests, generate_boilerplate, install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt,
5 Overwrite, Result, 5 Cmd, Overwrite, Result,
6}; 6};
7use std::{env, path::PathBuf}; 7use std::{env, path::PathBuf};
8 8
@@ -49,7 +49,7 @@ fn main() -> Result<()> {
49 install(opts)? 49 install(opts)?
50 } 50 }
51 ("gen-tests", _) => gen_tests(Overwrite)?, 51 ("gen-tests", _) => gen_tests(Overwrite)?,
52 ("gen-syntax", _) => generate(Overwrite)?, 52 ("gen-syntax", _) => generate_boilerplate(Overwrite)?,
53 ("format", _) => run_rustfmt(Overwrite)?, 53 ("format", _) => run_rustfmt(Overwrite)?,
54 ("format-hook", _) => install_format_hook()?, 54 ("format-hook", _) => install_format_hook()?,
55 ("lint", _) => run_clippy()?, 55 ("lint", _) => run_clippy()?,
diff --git a/crates/ra_tools/tests/cli.rs b/crates/ra_tools/tests/cli.rs
index ae0eb337d..c672e5788 100644
--- a/crates/ra_tools/tests/cli.rs
+++ b/crates/ra_tools/tests/cli.rs
@@ -1,10 +1,10 @@
1use walkdir::WalkDir; 1use walkdir::WalkDir;
2 2
3use ra_tools::{gen_tests, generate, project_root, run_rustfmt, Verify}; 3use ra_tools::{gen_tests, generate_boilerplate, project_root, run_rustfmt, Verify};
4 4
5#[test] 5#[test]
6fn generated_grammar_is_fresh() { 6fn generated_grammar_is_fresh() {
7 if let Err(error) = generate(Verify) { 7 if let Err(error) = generate_boilerplate(Verify) {
8 panic!("{}. Please update it by running `cargo gen-syntax`", error); 8 panic!("{}. Please update it by running `cargo gen-syntax`", error);
9 } 9 }
10} 10}