diff --git a/src/ast/print.rs b/src/ast/print.rs index 648e3bc..b4949a6 100644 --- a/src/ast/print.rs +++ b/src/ast/print.rs @@ -15,8 +15,12 @@ fn option_ident_to_string(ident: &Option) -> String { } } -impl FunctionDeclaration { - pub fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { +pub trait TreePrint { + fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result; +} + +impl TreePrint for FunctionDeclaration { + fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { let indent = std::iter::repeat(INDENT) .take(indent_level) .collect::(); @@ -39,8 +43,8 @@ impl FunctionDeclaration { } } -impl Block { - pub fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { +impl TreePrint for Block { + fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { let indent = std::iter::repeat(INDENT) .take(indent_level) .collect::(); @@ -52,8 +56,8 @@ impl Block { } } -impl BlockItem { - pub fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { +impl TreePrint for BlockItem { + fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { let indent = std::iter::repeat(INDENT) .take(indent_level) .collect::(); @@ -66,8 +70,8 @@ impl BlockItem { } } -impl Declaration { - pub fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { +impl TreePrint for Declaration { + fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { let indent = std::iter::repeat(INDENT) .take(indent_level) .collect::(); @@ -81,8 +85,8 @@ impl Declaration { } } -impl VariableDeclaration { - pub fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { +impl TreePrint for VariableDeclaration { + fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { let indent = std::iter::repeat(INDENT) .take(indent_level) .collect::(); @@ -98,8 +102,8 @@ impl VariableDeclaration { } } -impl Statement { - pub fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { +impl TreePrint for Statement { + fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { let indent = std::iter::repeat(INDENT) .take(indent_level) .collect::(); @@ -177,8 +181,8 @@ impl Statement { } } -impl Expression { - pub fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { +impl TreePrint for Expression { + fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { let indent = std::iter::repeat(INDENT) .take(indent_level) .collect::(); @@ -230,8 +234,8 @@ impl Expression { } } -impl ForInit { - pub fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { +impl TreePrint for ForInit { + fn tree_print(&self, f: &mut fmt::Formatter, indent_level: usize) -> fmt::Result { let indent = std::iter::repeat(INDENT) .take(indent_level) .collect::(); diff --git a/src/ast/tree.rs b/src/ast/tree.rs index 54b7345..955d730 100644 --- a/src/ast/tree.rs +++ b/src/ast/tree.rs @@ -1,3 +1,4 @@ +use super::print::TreePrint; use crate::lexer::*; use std::fmt; use std::mem::discriminant;