aboutsummaryrefslogtreecommitdiff
path: root/crates/tools/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/tools/src')
-rw-r--r--crates/tools/src/lib.rs35
-rw-r--r--crates/tools/src/main.rs19
2 files changed, 21 insertions, 33 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs
index 63ede5315..444745be5 100644
--- a/crates/tools/src/lib.rs
+++ b/crates/tools/src/lib.rs
@@ -1,13 +1,15 @@
1extern crate itertools; 1extern crate itertools;
2#[macro_use]
3extern crate failure; 2extern crate failure;
3extern crate teraron;
4 4
5use itertools::Itertools;
6use std::{ 5use std::{
7 fs,
8 path::{Path, PathBuf}, 6 path::{Path, PathBuf},
9}; 7};
10 8
9use itertools::Itertools;
10
11pub use teraron::{Mode, Verify, Overwrite};
12
11pub type Result<T> = ::std::result::Result<T, failure::Error>; 13pub type Result<T> = ::std::result::Result<T, failure::Error>;
12 14
13pub const GRAMMAR: &str = "ra_syntax/src/grammar.ron"; 15pub const GRAMMAR: &str = "ra_syntax/src/grammar.ron";
@@ -54,22 +56,23 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> {
54 res 56 res
55} 57}
56 58
57pub fn update(path: &Path, contents: &str, verify: bool) -> Result<()> { 59pub fn generate(mode: Mode) -> Result<()> {
58 match fs::read_to_string(path) { 60 let grammar = project_root().join(GRAMMAR);
59 Ok(ref old_contents) if old_contents == contents => { 61 let syntax_kinds = project_root().join(SYNTAX_KINDS);
60 return Ok(()); 62 let ast = project_root().join(AST);
61 } 63 teraron::generate(
62 _ => (), 64 &syntax_kinds,
63 } 65 &grammar,
64 if verify { 66 mode,
65 bail!("`{}` is not up-to-date", path.display()); 67 )?;
66 } 68 teraron::generate(
67 eprintln!("updating {}", path.display()); 69 &ast,
68 fs::write(path, contents)?; 70 &grammar,
71 mode,
72 )?;
69 Ok(()) 73 Ok(())
70} 74}
71 75
72
73pub fn project_root() -> PathBuf { 76pub fn project_root() -> PathBuf {
74 Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()) 77 Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap())
75 .parent() 78 .parent()
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs
index 1bbc43123..965bc7729 100644
--- a/crates/tools/src/main.rs
+++ b/crates/tools/src/main.rs
@@ -13,9 +13,8 @@ use std::{
13 process::Command, 13 process::Command,
14}; 14};
15use tools::{ 15use tools::{
16 collect_tests, project_root, Result, Test, AST, SYNTAX_KINDS, GRAMMAR, 16 collect_tests, Result, Test, generate, Mode, Overwrite, Verify,
17}; 17};
18use teraron::{Mode, Verify, Overwrite};
19 18
20const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar"; 19const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar";
21const INLINE_TESTS_DIR: &str = "./crates/ra_syntax/tests/data/parser/inline"; 20const INLINE_TESTS_DIR: &str = "./crates/ra_syntax/tests/data/parser/inline";
@@ -41,21 +40,7 @@ fn main() -> Result<()> {
41 match matches.subcommand() { 40 match matches.subcommand() {
42 ("install-code", _) => install_code_extension()?, 41 ("install-code", _) => install_code_extension()?,
43 ("gen-tests", _) => gen_tests(mode)?, 42 ("gen-tests", _) => gen_tests(mode)?,
44 ("gen-kinds", _) => { 43 ("gen-kinds", _) => generate(Overwrite)?,
45 let grammar = project_root().join(GRAMMAR);
46 let syntax_kinds = project_root().join(SYNTAX_KINDS);
47 let ast = project_root().join(AST);
48 teraron::generate(
49 &syntax_kinds,
50 &grammar,
51 mode,
52 )?;
53 teraron::generate(
54 &ast,
55 &grammar,
56 mode,
57 )?;
58 }
59 _ => unreachable!(), 44 _ => unreachable!(),
60 } 45 }
61 Ok(()) 46 Ok(())