Ast: trait objects on blocks
This commit is contained in:
parent
560423b742
commit
ba0aafd146
30
src/ast.rs
30
src/ast.rs
|
@ -41,12 +41,30 @@ impl ToString for BaseType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Builder)]
|
#[derive(Default)]
|
||||||
pub struct Block<T: Statement> {
|
pub struct GlobalBlock {
|
||||||
statements: Vec<T>,
|
statements: Vec<Box<dyn Statement>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Statement> ToString for Block<T> {
|
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(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
s.push('\n');
|
||||||
|
s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Block {
|
||||||
|
statements: Vec<Box<dyn Statement>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToString for Block {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
let mut s = String::from("{ ");
|
let mut s = String::from("{ ");
|
||||||
|
|
||||||
|
@ -60,9 +78,9 @@ impl<T: Statement> ToString for Block<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Statement> AstNode for Block<T> {}
|
impl AstNode for Block {}
|
||||||
|
|
||||||
impl<T: Statement> Statement for Block<T> {}
|
impl Statement for Block {}
|
||||||
|
|
||||||
pub enum Literal {
|
pub enum Literal {
|
||||||
Int(i32),
|
Int(i32),
|
||||||
|
|
Loading…
Reference in a new issue