Ast: add decl statement
All checks were successful
ci/woodpecker/push/build_rust Pipeline was successful

This commit is contained in:
Akemi Izuko 2023-11-17 14:49:10 -07:00
parent 16a9632f9d
commit d70d12ea1f
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC

View file

@ -8,18 +8,50 @@ use super::GazType;
pub enum Stat {
Block(Box<Block>),
GlobalBlock(Box<GlobalBlock>),
Declaration(Box<Declaration>),
}
impl Stat {
pub fn new_block(x: Block) -> Self {
Self::Block(Box::new(x))
}
pub fn new_decl(x: Declaration) -> Self {
Self::Declaration(Box::new(x))
}
}
impl ToString for Stat {
fn to_string(&self) -> String {
match self {
Stat::Block(x) => x.to_string(),
Stat::GlobalBlock(x) => x.to_string(),
Stat::Declaration(x) => x.to_string(),
}
}
}
#[derive(Default)]
pub struct GlobalBlock {
statements: Vec<Stat>,
}
impl GlobalBlock {
pub fn push(&mut self, node: Stat) {
self.statements.push(node);
}
}
impl ToString for GlobalBlock {
fn to_string(&self) -> String {
let mut s = String::new();
for stat in &self.statements {
s.push_str(&stat.to_string());
}
s
}
}
pub struct Block {
statements: Vec<Stat>,
}
@ -69,27 +101,3 @@ impl ToString for Declaration {
s
}
}
#[derive(Default)]
pub struct GlobalBlock {
statements: Vec<Stat>,
}
impl GlobalBlock {
pub fn push(&mut self, node: Stat) {
self.statements.push(node);
}
}
impl ToString for GlobalBlock {
fn to_string(&self) -> String {
let mut s = String::new();
for stat in &self.statements {
s.push_str(&stat.to_string());
}
s.push('\n');
s
}
}