From d545a5c75cb181758dd745b031eacfd7fc8a6929 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 18 Aug 2019 21:54:51 +0300 Subject: deserialize grammar --- crates/ra_tools/Cargo.toml | 1 + crates/ra_tools/src/codegen.rs | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) (limited to 'crates/ra_tools') 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" clap = "2.32.0" quote = "1.0.2" ron = "0.5.1" +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 @@ -use std::{fs, path::Path}; +use std::{collections::BTreeMap, fs, path::Path}; +use quote::quote; use ron; +use serde::Deserialize; use crate::{project_root, Mode, Result, AST, GRAMMAR}; @@ -12,10 +14,38 @@ pub fn generate(mode: Mode) -> Result<()> { } fn generate_ast(grammar_src: &Path, dst: &Path, mode: Mode) -> Result<()> { - let src: ron::Value = { + let src: Grammar = { let text = fs::read_to_string(grammar_src)?; ron::de::from_str(&text)? }; - eprintln!("{:?}", src); + eprintln!("{:#?}", src); Ok(()) } + +#[derive(Deserialize, Debug)] +struct Grammar { + single_byte_tokens: Vec<(String, String)>, + multi_byte_tokens: Vec<(String, String)>, + keywords: Vec, + contextual_keywords: Vec, + literals: Vec, + tokens: Vec, + ast: BTreeMap, +} + +#[derive(Deserialize, Debug)] +struct AstNode { + #[serde(default)] + traits: Vec, + #[serde(default)] + collections: Vec, + #[serde(default)] + options: Vec, +} + +#[derive(Deserialize, Debug)] +#[serde(untagged)] +enum Attr { + Type(String), + NameType(String, String), +} -- cgit v1.2.3