Parseur d'expression et affichage du résultat avec l'ASTPrinter en arborescence.
This commit is contained in:
22
src/expr.rs
22
src/expr.rs
@@ -30,43 +30,43 @@ pub enum Expr {
|
||||
}
|
||||
|
||||
pub trait ExprVisitor {
|
||||
fn visit_binary(&self, b: &Binary);
|
||||
fn visit_grouping(&self, g: &Grouping);
|
||||
fn visit_literal(&self, l: &Literal);
|
||||
fn visit_unary(&self, u: &Unary);
|
||||
fn visit_expr(&self, e: &Expr);
|
||||
fn visit_binary(&mut self, b: &Binary);
|
||||
fn visit_grouping(&mut self, g: &Grouping);
|
||||
fn visit_literal(&mut self, l: &Literal);
|
||||
fn visit_unary(&mut self, u: &Unary);
|
||||
fn visit_expr(&mut self, e: &Expr);
|
||||
}
|
||||
|
||||
pub trait VisitableExpr {
|
||||
fn accept(&self, visitor: &impl ExprVisitor);
|
||||
fn accept(&self, visitor: &mut impl ExprVisitor);
|
||||
}
|
||||
|
||||
impl VisitableExpr for Binary {
|
||||
fn accept(&self, visitor: &impl ExprVisitor) {
|
||||
fn accept(&self, visitor: &mut impl ExprVisitor) {
|
||||
visitor.visit_binary(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl VisitableExpr for Grouping {
|
||||
fn accept(&self, visitor: &impl ExprVisitor) {
|
||||
fn accept(&self, visitor: &mut impl ExprVisitor) {
|
||||
visitor.visit_grouping(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl VisitableExpr for Literal {
|
||||
fn accept(&self, visitor: &impl ExprVisitor) {
|
||||
fn accept(&self, visitor: &mut impl ExprVisitor) {
|
||||
visitor.visit_literal(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl VisitableExpr for Unary {
|
||||
fn accept(&self, visitor: &impl ExprVisitor) {
|
||||
fn accept(&self, visitor: &mut impl ExprVisitor) {
|
||||
visitor.visit_unary(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl VisitableExpr for Expr {
|
||||
fn accept(&self, visitor: &impl ExprVisitor) {
|
||||
fn accept(&self, visitor: &mut impl ExprVisitor) {
|
||||
visitor.visit_expr(self);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user