switch to new codegen

This commit is contained in:
Aleksey Kladov 2019-08-18 21:44:24 +03:00
parent 839d9cce89
commit 229d7943d8
4 changed files with 32 additions and 14 deletions

12
Cargo.lock generated
View file

@ -1364,6 +1364,7 @@ dependencies = [
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"teraron 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "teraron 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -1614,6 +1615,16 @@ dependencies = [
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "ron"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "rowan" name = "rowan"
version = "0.6.2" version = "0.6.2"
@ -2321,6 +2332,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7790c7f1cc73d831d28dc5a7deb316a006e7848e6a7f467cdb10a0a9e0fb1c" "checksum relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7790c7f1cc73d831d28dc5a7deb316a006e7848e6a7f467cdb10a0a9e0fb1c"
"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e"
"checksum ron 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "17f52a24414403f81528b67488cf8edc4eda977d3af1646bb6b106a600ead78f" "checksum ron 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "17f52a24414403f81528b67488cf8edc4eda977d3af1646bb6b106a600ead78f"
"checksum ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ece421e0c4129b90e4a35b6f625e472e96c552136f5093a2f4fa2bbb75a62d5"
"checksum rowan 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dc2b79612dedc9004083a61448eb669d336d56690aab29fbd7249e8c8ab41d8c" "checksum rowan 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dc2b79612dedc9004083a61448eb669d336d56690aab29fbd7249e8c8ab41d8c"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8"

View file

@ -11,3 +11,4 @@ walkdir = "2.1.3"
itertools = "0.8.0" itertools = "0.8.0"
clap = "2.32.0" clap = "2.32.0"
quote = "1.0.2" quote = "1.0.2"
ron = "0.5.1"

View file

@ -1,7 +1,21 @@
use std::path::Path; use std::{fs, path::Path};
use crate::{Mode, Result}; use ron;
pub fn generate_ast(grammar_src: &Path, dst: &Path, mode: Mode) -> Result<()> { use crate::{project_root, Mode, Result, AST, GRAMMAR};
pub fn generate(mode: Mode) -> Result<()> {
let grammar = project_root().join(GRAMMAR);
// let syntax_kinds = project_root().join(SYNTAX_KINDS);
let ast = project_root().join(AST);
generate_ast(&grammar, &ast, mode)
}
fn generate_ast(grammar_src: &Path, dst: &Path, mode: Mode) -> Result<()> {
let src: ron::Value = {
let text = fs::read_to_string(grammar_src)?;
ron::de::from_str(&text)?
};
eprintln!("{:?}", src);
Ok(()) Ok(())
} }

View file

@ -13,7 +13,7 @@ use itertools::Itertools;
pub use teraron::{Mode, Overwrite, Verify}; pub use teraron::{Mode, Overwrite, Verify};
pub use self::codegen::generate_ast; pub use self::codegen::generate;
pub type Result<T> = std::result::Result<T, Box<dyn Error>>; pub type Result<T> = std::result::Result<T, Box<dyn Error>>;
@ -23,7 +23,7 @@ const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok";
const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err"; const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err";
pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs.tera"; pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs.tera";
pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs.tera"; pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs";
const TOOLCHAIN: &str = "stable"; const TOOLCHAIN: &str = "stable";
#[derive(Debug)] #[derive(Debug)]
@ -70,15 +70,6 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> {
res res
} }
pub fn generate(mode: Mode) -> Result<()> {
let grammar = project_root().join(GRAMMAR);
let syntax_kinds = project_root().join(SYNTAX_KINDS);
let ast = project_root().join(AST);
teraron::generate(&syntax_kinds, &grammar, mode)?;
teraron::generate(&ast, &grammar, mode)?;
Ok(())
}
pub fn project_root() -> PathBuf { pub fn project_root() -> PathBuf {
Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf() Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf()
} }