Ajout des instructions.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::expr::{Binary, Expr, ExprVisitor, Grouping, Literal, Unary};
|
||||
use crate::stmt::{ExpressionStatement, PrintStatement, StatementVisitor};
|
||||
|
||||
pub struct ASTPrinter {
|
||||
pub(crate) depth: u32
|
||||
@@ -59,4 +60,22 @@ impl ExprVisitor<()> for ASTPrinter {
|
||||
Expr::UnaryExpr(u) => { self.visit_unary(u); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StatementVisitor<()> for ASTPrinter {
|
||||
fn visit_expr_stmt(&mut self, e: &ExpressionStatement) -> () {
|
||||
println!("{} EXPR_STMT(", self.ast_tab());
|
||||
self.depth+=1;
|
||||
self.visit_expr(&e.expr);
|
||||
self.depth-=1;
|
||||
print!(") ");
|
||||
}
|
||||
|
||||
fn visit_print(&mut self, p: &PrintStatement) -> () {
|
||||
println!("{} EXPR_STMT(", self.ast_tab());
|
||||
self.depth+=1;
|
||||
self.visit_expr(&p.expr);
|
||||
self.depth-=1;
|
||||
print!(") ");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user