aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_tools/Cargo.toml1
-rw-r--r--crates/ra_tools/src/codegen.rs20
-rw-r--r--crates/ra_tools/src/lib.rs13
3 files changed, 20 insertions, 14 deletions
diff --git a/crates/ra_tools/Cargo.toml b/crates/ra_tools/Cargo.toml
index a70079b95..02bab8f52 100644
--- a/crates/ra_tools/Cargo.toml
+++ b/crates/ra_tools/Cargo.toml
@@ -11,3 +11,4 @@ walkdir = "2.1.3"
11itertools = "0.8.0" 11itertools = "0.8.0"
12clap = "2.32.0" 12clap = "2.32.0"
13quote = "1.0.2" 13quote = "1.0.2"
14ron = "0.5.1"
diff --git a/crates/ra_tools/src/codegen.rs b/crates/ra_tools/src/codegen.rs
index edb01aceb..405fb623c 100644
--- a/crates/ra_tools/src/codegen.rs
+++ b/crates/ra_tools/src/codegen.rs
@@ -1,7 +1,21 @@
1use std::path::Path; 1use std::{fs, path::Path};
2 2
3use crate::{Mode, Result}; 3use ron;
4 4
5pub fn generate_ast(grammar_src: &Path, dst: &Path, mode: Mode) -> Result<()> { 5use crate::{project_root, Mode, Result, AST, GRAMMAR};
6
7pub fn generate(mode: Mode) -> Result<()> {
8 let grammar = project_root().join(GRAMMAR);
9 // let syntax_kinds = project_root().join(SYNTAX_KINDS);
10 let ast = project_root().join(AST);
11 generate_ast(&grammar, &ast, mode)
12}
13
14fn generate_ast(grammar_src: &Path, dst: &Path, mode: Mode) -> Result<()> {
15 let src: ron::Value = {
16 let text = fs::read_to_string(grammar_src)?;
17 ron::de::from_str(&text)?
18 };
19 eprintln!("{:?}", src);
6 Ok(()) 20 Ok(())
7} 21}
diff --git a/crates/ra_tools/src/lib.rs b/crates/ra_tools/src/lib.rs
index 2cbb07ebf..de8c472d1 100644
--- a/crates/ra_tools/src/lib.rs
+++ b/crates/ra_tools/src/lib.rs
@@ -13,7 +13,7 @@ use itertools::Itertools;
13 13
14pub use teraron::{Mode, Overwrite, Verify}; 14pub use teraron::{Mode, Overwrite, Verify};
15 15
16pub use self::codegen::generate_ast; 16pub use self::codegen::generate;
17 17
18pub type Result<T> = std::result::Result<T, Box<dyn Error>>; 18pub type Result<T> = std::result::Result<T, Box<dyn Error>>;
19 19
@@ -23,7 +23,7 @@ const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok";
23const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err"; 23const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err";
24 24
25pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs.tera"; 25pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs.tera";
26pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs.tera"; 26pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs";
27const TOOLCHAIN: &str = "stable"; 27const TOOLCHAIN: &str = "stable";
28 28
29#[derive(Debug)] 29#[derive(Debug)]
@@ -70,15 +70,6 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> {
70 res 70 res
71} 71}
72 72
73pub fn generate(mode: Mode) -> Result<()> {
74 let grammar = project_root().join(GRAMMAR);
75 let syntax_kinds = project_root().join(SYNTAX_KINDS);
76 let ast = project_root().join(AST);
77 teraron::generate(&syntax_kinds, &grammar, mode)?;
78 teraron::generate(&ast, &grammar, mode)?;
79 Ok(())
80}
81
82pub fn project_root() -> PathBuf { 73pub fn project_root() -> PathBuf {
83 Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf() 74 Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf()
84} 75}