aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-08-18 19:44:24 +0100
committerAleksey Kladov <[email protected]>2019-08-18 19:44:24 +0100
commit229d7943d8471eb114f961ab419c318736772da4 (patch)
tree183655c53e09b82d308b89fecccea7bbf725a344
parent839d9cce89adcae23dfd108acf231dca00724f08 (diff)
switch to new codegen
-rw-r--r--Cargo.lock12
-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
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]]
1619name = "ron"
1620version = "0.5.1"
1621source = "registry+https://github.com/rust-lang/crates.io-index"
1622dependencies = [
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]]
1618name = "rowan" 1629name = "rowan"
1619version = "0.6.2" 1630version = "0.6.2"
1620source = "registry+https://github.com/rust-lang/crates.io-index" 1631source = "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"
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}