Ast: add decl statement
All checks were successful
ci/woodpecker/push/build_rust Pipeline was successful
All checks were successful
ci/woodpecker/push/build_rust Pipeline was successful
This commit is contained in:
parent
16a9632f9d
commit
d70d12ea1f
|
@ -8,18 +8,50 @@ use super::GazType;
|
||||||
|
|
||||||
pub enum Stat {
|
pub enum Stat {
|
||||||
Block(Box<Block>),
|
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 {
|
impl ToString for Stat {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Stat::Block(x) => x.to_string(),
|
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 {
|
pub struct Block {
|
||||||
statements: Vec<Stat>,
|
statements: Vec<Stat>,
|
||||||
}
|
}
|
||||||
|
@ -69,27 +101,3 @@ impl ToString for Declaration {
|
||||||
s
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue