deserialize grammar
This commit is contained in:
@@ -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<String>,
|
||||
contextual_keywords: Vec<String>,
|
||||
literals: Vec<String>,
|
||||
tokens: Vec<String>,
|
||||
ast: BTreeMap<String, AstNode>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct AstNode {
|
||||
#[serde(default)]
|
||||
traits: Vec<String>,
|
||||
#[serde(default)]
|
||||
collections: Vec<Attr>,
|
||||
#[serde(default)]
|
||||
options: Vec<Attr>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(untagged)]
|
||||
enum Attr {
|
||||
Type(String),
|
||||
NameType(String, String),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user