Starting to implement a pretty-printer to test visitor
This commit is contained in:
parent
627a740b0d
commit
1a934d7804
@ -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};
|
||||
|
Loading…
Reference in New Issue
Block a user