use crate::ast::*;
pub trait Formatter {
type Output;
fn format_symbol(&mut self, sym: &Symbol) -> Self::Output;
fn format_number(&mut self, dec: &str) -> Self::Output;
fn format_binary_expr(
&mut self,
op: &BinaryOp,
arg1: &Box<AST>,
arg2: &Box<AST>,
) -> Self::Output;
fn format_unary_expr(&mut self, op: &UnaryOp, arg: &Box<AST>) -> Self::Output;
fn format_function(&mut self, name: &Symbol, args: &Vec<AST>) -> Self::Output;
fn format(&mut self, ast: &AST) -> Self::Output {
match ast {
AST::Sym(sym) => self.format_symbol(sym),
AST::Number(string) => self.format_number(string),
AST::BinaryExpr(op, arg1, arg2) => self.format_binary_expr(op, arg1, arg2),
AST::UnaryExpr(op, arg) => self.format_unary_expr(op, arg),
AST::Function(name, args) => self.format_function(name, args),
}
}
}