aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tools/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-08-18 19:54:51 +0100
committerAleksey Kladov <[email protected]>2019-08-18 19:54:51 +0100
commitd545a5c75cb181758dd745b031eacfd7fc8a6929 (patch)
tree579057500a85b87fdded27394224246d3803d9ee /crates/ra_tools/src
parent229d7943d8471eb114f961ab419c318736772da4 (diff)
deserialize grammar
Diffstat (limited to 'crates/ra_tools/src')
-rw-r--r--crates/ra_tools/src/codegen.rs36
1 files changed, 33 insertions, 3 deletions
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 @@
1use std::{fs, path::Path}; 1use std::{collections::BTreeMap, fs, path::Path};
2 2
3use quote::quote;
3use ron; 4use ron;
5use serde::Deserialize;
4 6
5use crate::{project_root, Mode, Result, AST, GRAMMAR}; 7use crate::{project_root, Mode, Result, AST, GRAMMAR};
6 8
@@ -12,10 +14,38 @@ pub fn generate(mode: Mode) -> Result<()> {
12} 14}
13 15
14fn generate_ast(grammar_src: &Path, dst: &Path, mode: Mode) -> Result<()> { 16fn 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)]
26struct 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)]
37struct 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)]
48enum Attr {
49 Type(String),
50 NameType(String, String),
51}