diff --git a/schala-lang/language/src/ast_visitor.rs b/schala-lang/language/src/ast_visitor.rs index a65bcbf..21dcdbe 100644 --- a/schala-lang/language/src/ast_visitor.rs +++ b/schala-lang/language/src/ast_visitor.rs @@ -95,6 +95,43 @@ impl DeclarationVisitor<()> for NullVisitor { } } + +#[derive(Default, Clone)] +struct SchalaPrinter { + s: String +} + +impl ASTVisitor for SchalaPrinter { + type EV = SchalaPrinter; + type DV = SchalaPrinter; + fn ast(&mut self, _: &AST) { + self.s.push_str("Pretty-printed AST"); + } + + fn expression(&mut self) -> Self::EV { + SchalaPrinter::default() + } + fn declaration(&mut self) -> Self::DV { + SchalaPrinter::default() + } + + fn done(&mut self) -> String { + self.s.clone() + } +} + +impl ExpressionVisitor for SchalaPrinter { + fn done(&mut self) -> String { + format!("some_expr") + } +} + +impl DeclarationVisitor for SchalaPrinter { + fn done(&mut self) -> String { + format!("some_decl") + } +} + #[cfg(test)] mod visitor_tests { use ::tokenizing::{Token, tokenize};