summaryrefslogtreecommitdiff
path: root/src/syntax/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax/mod.rs')
-rw-r--r--src/syntax/mod.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs
index 9c78fbc3..22f51d82 100644
--- a/src/syntax/mod.rs
+++ b/src/syntax/mod.rs
@@ -12,5 +12,33 @@ pub use node::*;
pub use span::*;
pub use token::*;
-/// A collection of nodes which form a tree together with their children.
+use crate::pretty::{Pretty, Printer};
+
+/// The abstract syntax tree.
pub type Tree = SpanVec<Node>;
+
+impl Pretty for Tree {
+ fn pretty(&self, p: &mut Printer) {
+ for node in self {
+ node.v.pretty(p);
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::parse::parse;
+ use crate::pretty::pretty;
+
+ #[track_caller]
+ pub fn test_pretty(src: &str, exp: &str) {
+ let tree = parse(src).output;
+ let found = pretty(&tree);
+ if exp != found {
+ println!("tree: {:#?}", tree);
+ println!("expected: {}", exp);
+ println!("found: {}", found);
+ panic!("test failed");
+ }
+ }
+}