diff options
Diffstat (limited to 'crates/tools/src/lib.rs')
-rw-r--r-- | crates/tools/src/lib.rs | 16 |
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; | |||
8 | use std::{ | 8 | use std::{ |
9 | collections::HashMap, | 9 | collections::HashMap, |
10 | fs, | 10 | fs, |
11 | path::Path, | 11 | path::{Path, PathBuf}, |
12 | }; | 12 | }; |
13 | use itertools::Itertools; | 13 | use itertools::Itertools; |
14 | use heck::{CamelCase, ShoutySnakeCase, SnakeCase}; | 14 | use heck::{CamelCase, ShoutySnakeCase, SnakeCase}; |
15 | 15 | ||
16 | pub type Result<T> = ::std::result::Result<T, failure::Error>; | 16 | pub type Result<T> = ::std::result::Result<T, failure::Error>; |
17 | 17 | ||
18 | const GRAMMAR: &str = "ra_syntax/src/grammar.ron"; | ||
19 | pub const SYNTAX_KINDS: &str = "ra_syntax/src/syntax_kinds/generated.rs"; | ||
20 | pub const SYNTAX_KINDS_TEMPLATE: &str = "ra_syntax/src/syntax_kinds/generated.rs.tera"; | ||
21 | pub const AST: &str = "ra_syntax/src/ast/generated.rs"; | ||
22 | pub const AST_TEMPLATE: &str = "ra_syntax/src/ast/generated.rs.tera"; | ||
23 | |||
18 | #[derive(Debug)] | 24 | #[derive(Debug)] |
19 | pub struct Test { | 25 | pub 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 | ||
74 | pub fn render_template(template: &str) -> Result<String> { | 80 | pub 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 | |||
118 | pub fn project_root() -> PathBuf { | ||
119 | Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).parent().unwrap().to_path_buf() | ||
120 | } | ||