diff options
Diffstat (limited to 'crates/ra_tools/src')
-rw-r--r-- | crates/ra_tools/src/codegen.rs | 20 | ||||
-rw-r--r-- | crates/ra_tools/src/lib.rs | 13 |
2 files changed, 19 insertions, 14 deletions
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 @@ | |||
1 | use std::path::Path; | 1 | use std::{fs, path::Path}; |
2 | 2 | ||
3 | use crate::{Mode, Result}; | 3 | use ron; |
4 | 4 | ||
5 | pub fn generate_ast(grammar_src: &Path, dst: &Path, mode: Mode) -> Result<()> { | 5 | use crate::{project_root, Mode, Result, AST, GRAMMAR}; |
6 | |||
7 | pub 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 | |||
14 | fn 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 | ||
14 | pub use teraron::{Mode, Overwrite, Verify}; | 14 | pub use teraron::{Mode, Overwrite, Verify}; |
15 | 15 | ||
16 | pub use self::codegen::generate_ast; | 16 | pub use self::codegen::generate; |
17 | 17 | ||
18 | pub type Result<T> = std::result::Result<T, Box<dyn Error>>; | 18 | pub 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"; | |||
23 | const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err"; | 23 | const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err"; |
24 | 24 | ||
25 | pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs.tera"; | 25 | pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs.tera"; |
26 | pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs.tera"; | 26 | pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs"; |
27 | const TOOLCHAIN: &str = "stable"; | 27 | const 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 | ||
73 | pub 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 | |||
82 | pub fn project_root() -> PathBuf { | 73 | pub 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 | } |