Ast: trait objects on blocks
This commit is contained in:
parent
560423b742
commit
ba0aafd146
1 changed files with 24 additions and 6 deletions
30
src/ast.rs
30
src/ast.rs
|
@ -41,12 +41,30 @@ impl ToString for BaseType {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Builder)]
|
||||
pub struct Block<T: Statement> {
|
||||
statements: Vec<T>,
|
||||
#[derive(Default)]
|
||||
pub struct GlobalBlock {
|
||||
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 {
|
||||
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 {
|
||||
Int(i32),
|
||||
|
|
Loading…
Reference in a new issue