mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
switch to new codegen
This commit is contained in:
parent
839d9cce89
commit
229d7943d8
4 changed files with 32 additions and 14 deletions
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ use itertools::Itertools;
|
|||
|
||||
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>>;
|
||||
|
||||
|
@ -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";
|
||||
|
||||
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";
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -70,15 +70,6 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> {
|
|||
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 {
|
||||
Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue