diff options
Diffstat (limited to 'crates/ra_tools')
-rw-r--r-- | crates/ra_tools/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_tools/src/codegen.rs | 36 |
2 files changed, 34 insertions, 3 deletions
diff --git a/crates/ra_tools/Cargo.toml b/crates/ra_tools/Cargo.toml index 02bab8f52..ab9fa5d86 100644 --- a/crates/ra_tools/Cargo.toml +++ b/crates/ra_tools/Cargo.toml | |||
@@ -12,3 +12,4 @@ itertools = "0.8.0" | |||
12 | clap = "2.32.0" | 12 | clap = "2.32.0" |
13 | quote = "1.0.2" | 13 | quote = "1.0.2" |
14 | ron = "0.5.1" | 14 | ron = "0.5.1" |
15 | serde = { version = "1.0.0", features = ["derive"] } | ||
diff --git a/crates/ra_tools/src/codegen.rs b/crates/ra_tools/src/codegen.rs index 405fb623c..f0a54808a 100644 --- a/crates/ra_tools/src/codegen.rs +++ b/crates/ra_tools/src/codegen.rs | |||
@@ -1,6 +1,8 @@ | |||
1 | use std::{fs, path::Path}; | 1 | use std::{collections::BTreeMap, fs, path::Path}; |
2 | 2 | ||
3 | use quote::quote; | ||
3 | use ron; | 4 | use ron; |
5 | use serde::Deserialize; | ||
4 | 6 | ||
5 | use crate::{project_root, Mode, Result, AST, GRAMMAR}; | 7 | use crate::{project_root, Mode, Result, AST, GRAMMAR}; |
6 | 8 | ||
@@ -12,10 +14,38 @@ pub fn generate(mode: Mode) -> Result<()> { | |||
12 | } | 14 | } |
13 | 15 | ||
14 | fn generate_ast(grammar_src: &Path, dst: &Path, mode: Mode) -> Result<()> { | 16 | fn generate_ast(grammar_src: &Path, dst: &Path, mode: Mode) -> Result<()> { |
15 | let src: ron::Value = { | 17 | let src: Grammar = { |
16 | let text = fs::read_to_string(grammar_src)?; | 18 | let text = fs::read_to_string(grammar_src)?; |
17 | ron::de::from_str(&text)? | 19 | ron::de::from_str(&text)? |
18 | }; | 20 | }; |
19 | eprintln!("{:?}", src); | 21 | eprintln!("{:#?}", src); |
20 | Ok(()) | 22 | Ok(()) |
21 | } | 23 | } |
24 | |||
25 | #[derive(Deserialize, Debug)] | ||
26 | struct Grammar { | ||
27 | single_byte_tokens: Vec<(String, String)>, | ||
28 | multi_byte_tokens: Vec<(String, String)>, | ||
29 | keywords: Vec<String>, | ||
30 | contextual_keywords: Vec<String>, | ||
31 | literals: Vec<String>, | ||
32 | tokens: Vec<String>, | ||
33 | ast: BTreeMap<String, AstNode>, | ||
34 | } | ||
35 | |||
36 | #[derive(Deserialize, Debug)] | ||
37 | struct AstNode { | ||
38 | #[serde(default)] | ||
39 | traits: Vec<String>, | ||
40 | #[serde(default)] | ||
41 | collections: Vec<Attr>, | ||
42 | #[serde(default)] | ||
43 | options: Vec<Attr>, | ||
44 | } | ||
45 | |||
46 | #[derive(Deserialize, Debug)] | ||
47 | #[serde(untagged)] | ||
48 | enum Attr { | ||
49 | Type(String), | ||
50 | NameType(String, String), | ||
51 | } | ||