Starting to implement a pretty-printer to test visitor

This commit is contained in:
greg 2018-11-17 21:21:06 -08:00
parent 627a740b0d
commit 1a934d7804

View File

@ -95,6 +95,43 @@ impl DeclarationVisitor<()> for NullVisitor {
}
}
#[derive(Default, Clone)]
struct SchalaPrinter {
s: String
}
impl ASTVisitor<String> 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<String> for SchalaPrinter {
fn done(&mut self) -> String {
format!("some_expr")
}
}
impl DeclarationVisitor<String> for SchalaPrinter {
fn done(&mut self) -> String {
format!("some_decl")
}
}
#[cfg(test)]
mod visitor_tests {
use ::tokenizing::{Token, tokenize};