aboutsummaryrefslogtreecommitdiff
path: root/crates/tools/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/tools/src/lib.rs')
-rw-r--r--crates/tools/src/lib.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs
index ba7d10caa..548b157dd 100644
--- a/crates/tools/src/lib.rs
+++ b/crates/tools/src/lib.rs
@@ -8,13 +8,19 @@ extern crate heck;
8use std::{ 8use std::{
9 collections::HashMap, 9 collections::HashMap,
10 fs, 10 fs,
11 path::Path, 11 path::{Path, PathBuf},
12}; 12};
13use itertools::Itertools; 13use itertools::Itertools;
14use heck::{CamelCase, ShoutySnakeCase, SnakeCase}; 14use heck::{CamelCase, ShoutySnakeCase, SnakeCase};
15 15
16pub type Result<T> = ::std::result::Result<T, failure::Error>; 16pub type Result<T> = ::std::result::Result<T, failure::Error>;
17 17
18const GRAMMAR: &str = "ra_syntax/src/grammar.ron";
19pub const SYNTAX_KINDS: &str = "ra_syntax/src/syntax_kinds/generated.rs";
20pub const SYNTAX_KINDS_TEMPLATE: &str = "ra_syntax/src/syntax_kinds/generated.rs.tera";
21pub const AST: &str = "ra_syntax/src/ast/generated.rs";
22pub const AST_TEMPLATE: &str = "ra_syntax/src/ast/generated.rs.tera";
23
18#[derive(Debug)] 24#[derive(Debug)]
19pub struct Test { 25pub struct Test {
20 pub name: String, 26 pub name: String,
@@ -71,9 +77,9 @@ pub fn update(path: &Path, contents: &str, verify: bool) -> Result<()> {
71 Ok(()) 77 Ok(())
72} 78}
73 79
74pub fn render_template(template: &str) -> Result<String> { 80pub fn render_template(template: PathBuf) -> Result<String> {
75 let grammar: ron::value::Value = { 81 let grammar: ron::value::Value = {
76 let text = fs::read_to_string(format!("{}{}", Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).parent().unwrap().to_str().unwrap(), "/ra_syntax/src/grammar.ron"))?; 82 let text = fs::read_to_string(project_root().join(GRAMMAR))?;
77 ron::de::from_str(&text)? 83 ron::de::from_str(&text)?
78 }; 84 };
79 let template = fs::read_to_string(template)?; 85 let template = fs::read_to_string(template)?;
@@ -108,3 +114,7 @@ pub fn render_template(template: &str) -> Result<String> {
108 Ok(tera::Value::Array(elements)) 114 Ok(tera::Value::Array(elements))
109 } 115 }
110} 116}
117
118pub fn project_root() -> PathBuf {
119 Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).parent().unwrap().to_path_buf()
120}