AstBuilder: initial outline

This commit is contained in:
Akemi Izuko 2023-11-16 16:27:03 -07:00
parent ba0aafd146
commit 2c15d8547d
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
2 changed files with 45 additions and 3 deletions

40
src/ast_builder.rs Normal file
View file

@ -0,0 +1,40 @@
use crate::params::Params;
use crate::ast::{
Quantifier,
BaseType,
GlobalBlock,
Block,
Literal,
Declaration,
Variable,
BinaryOperator,
};
pub struct AstBuilder {
params: Params,
ast: GlobalBlock,
}
impl AstBuilder {
pub fn from(params: Params) -> Self {
Self {
params,
ast: GlobalBlock::default(),
}
}
pub fn generate(&self) {
}
}
impl ToString for AstBuilder {
fn to_string(&self) -> String {
let mut s = format!("// Generated by {} v{}\n",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
);
s.push_str(&self.ast.to_string());
s
}
}

View file

@ -1,4 +1,3 @@
use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
use clap::Parser; use clap::Parser;
@ -6,9 +5,11 @@ use clap::Parser;
extern crate derive_builder; extern crate derive_builder;
mod ast; mod ast;
mod ast_builder;
mod params; mod params;
use params::Params; use params::Params;
use ast_builder::AstBuilder;
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
@ -18,7 +19,8 @@ struct Args {
fn main() { fn main() {
let args = Args::parse(); let args = Args::parse();
let params_toml = Params::parse(&args.config); let params = Params::parse(&args.config);
let builder = AstBuilder::from(params);
println!("{}", params_toml.global_flow.gen_decl); println!("{}", builder.to_string());
} }