diff options
-rw-r--r-- | Cargo.lock | 12 | ||||
-rw-r--r-- | crates/ra_tools/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_tools/src/codegen.rs | 20 | ||||
-rw-r--r-- | crates/ra_tools/src/lib.rs | 13 |
4 files changed, 32 insertions, 14 deletions
diff --git a/Cargo.lock b/Cargo.lock index 0885ac5f4..4f8be3212 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1364,6 +1364,7 @@ dependencies = [ | |||
1364 | "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1364 | "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1365 | "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1365 | "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1366 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", | 1366 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", |
1367 | "ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1367 | "teraron 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1368 | "teraron 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1368 | "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", | 1369 | "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", |
1369 | ] | 1370 | ] |
@@ -1615,6 +1616,16 @@ dependencies = [ | |||
1615 | ] | 1616 | ] |
1616 | 1617 | ||
1617 | [[package]] | 1618 | [[package]] |
1619 | name = "ron" | ||
1620 | version = "0.5.1" | ||
1621 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1622 | dependencies = [ | ||
1623 | "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1624 | "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1625 | "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1626 | ] | ||
1627 | |||
1628 | [[package]] | ||
1618 | name = "rowan" | 1629 | name = "rowan" |
1619 | version = "0.6.2" | 1630 | version = "0.6.2" |
1620 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1631 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -2321,6 +2332,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
2321 | "checksum relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7790c7f1cc73d831d28dc5a7deb316a006e7848e6a7f467cdb10a0a9e0fb1c" | 2332 | "checksum relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7790c7f1cc73d831d28dc5a7deb316a006e7848e6a7f467cdb10a0a9e0fb1c" |
2322 | "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" | 2333 | "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" |
2323 | "checksum ron 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "17f52a24414403f81528b67488cf8edc4eda977d3af1646bb6b106a600ead78f" | 2334 | "checksum ron 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "17f52a24414403f81528b67488cf8edc4eda977d3af1646bb6b106a600ead78f" |
2335 | "checksum ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ece421e0c4129b90e4a35b6f625e472e96c552136f5093a2f4fa2bbb75a62d5" | ||
2324 | "checksum rowan 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dc2b79612dedc9004083a61448eb669d336d56690aab29fbd7249e8c8ab41d8c" | 2336 | "checksum rowan 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dc2b79612dedc9004083a61448eb669d336d56690aab29fbd7249e8c8ab41d8c" |
2325 | "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" | 2337 | "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" |
2326 | "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" | 2338 | "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" |
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" | |||
11 | itertools = "0.8.0" | 11 | itertools = "0.8.0" |
12 | clap = "2.32.0" | 12 | clap = "2.32.0" |
13 | quote = "1.0.2" | 13 | quote = "1.0.2" |
14 | ron = "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 @@ | |||
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 | } |