Skip to content

Commit 8a80e0f

Browse files
committed
Helper method for pprust::State for printing instances of ast_map::Node.
1 parent a9b1a3b commit 8a80e0f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/libsyntax/ast_map/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use util::small_vector::SmallVector;
2121
use std::cell::RefCell;
2222
use std::fmt;
2323
use std::gc::{Gc, GC};
24+
use std::io::IoResult;
2425
use std::iter;
2526
use std::slice;
2627

@@ -819,6 +820,34 @@ pub fn map_decoded_item<F: FoldOps>(map: &Map,
819820
ii
820821
}
821822

823+
pub trait NodePrinter {
824+
fn print_node(&mut self, node: &Node) -> IoResult<()>;
825+
}
826+
827+
impl<'a> NodePrinter for pprust::State<'a> {
828+
fn print_node(&mut self, node: &Node) -> IoResult<()> {
829+
match *node {
830+
NodeItem(a) => self.print_item(&*a),
831+
NodeForeignItem(a) => self.print_foreign_item(&*a),
832+
NodeTraitMethod(a) => self.print_trait_method(&*a),
833+
NodeMethod(a) => self.print_method(&*a),
834+
NodeVariant(a) => self.print_variant(&*a),
835+
NodeExpr(a) => self.print_expr(&*a),
836+
NodeStmt(a) => self.print_stmt(&*a),
837+
NodePat(a) => self.print_pat(&*a),
838+
NodeBlock(a) => self.print_block(&*a),
839+
NodeLifetime(a) => self.print_lifetime(&*a),
840+
841+
// these cases do not carry enough information in the
842+
// ast_map to reconstruct their full structure for pretty
843+
// printing.
844+
NodeLocal(_) => fail!("cannot print isolated Local"),
845+
NodeArg(_) => fail!("cannot print isolated Arg"),
846+
NodeStructCtor(_) => fail!("cannot print isolated StructCtor"),
847+
}
848+
}
849+
}
850+
822851
fn node_id_to_string(map: &Map, id: NodeId) -> String {
823852
match map.find(id) {
824853
Some(NodeItem(item)) => {

0 commit comments

Comments
 (0)