diff --git a/src/ast/statement.rs b/src/ast/statement.rs index aadc6d5..4ff3d5d 100644 --- a/src/ast/statement.rs +++ b/src/ast/statement.rs @@ -8,18 +8,50 @@ use super::GazType; pub enum Stat { Block(Box), - GlobalBlock(Box), + Declaration(Box), +} + +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, +} + +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, } @@ -69,27 +101,3 @@ impl ToString for Declaration { s } } - -#[derive(Default)] -pub struct GlobalBlock { - statements: Vec, -} - -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 - } -}