Skip to content

Commit c0abd6a

Browse files
committed
We're going to have a hard time if we want to pretty-print token trees.
1 parent f3e8746 commit c0abd6a

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/libsyntax/print/pprust.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,29 @@ fn print_item(s: ps, &&item: @ast::item) {
601601
for methods.each |meth| { print_ty_method(s, meth); }
602602
bclose(s, item.span);
603603
}
604-
ast::item_mac(_m) {
605-
fail "item macros unimplemented"
604+
ast::item_mac({node: ast::mac_invoc_tt(pth, tts), _}) {
605+
606+
word(s.s, *item.ident);
607+
bopen(s);
608+
for tts.each |tt| { print_tt(s, tt); }
609+
bclose(s, item.span);
610+
}
611+
ast::item_mac(_) {
612+
fail "invalid item-position syntax bit"
606613
}
607614
}
608615
s.ann.post(ann_node);
609616
}
610617

618+
/// Unimplemented because ident tokens lose their meaning without the interner
619+
/// present. Fixing that would make invoking the pretty printer painful.
620+
/// If this did work, the naive way of implementing it would be really ugly.
621+
/// A prettier option would involve scraping the macro grammar for formatting
622+
/// advice. But that would be hard.
623+
fn print_tt(_s: ps, _tt: ast::token_tree) {
624+
fail "token trees cannot be pretty-printed"
625+
}
626+
611627
fn print_variant(s: ps, v: ast::variant) {
612628
word(s.s, *v.node.name);
613629
if vec::len(v.node.args) > 0u {
@@ -822,6 +838,13 @@ fn print_mac(s: ps, m: ast::mac) {
822838
option::iter(arg, |a| print_expr(s, a));
823839
// FIXME: extension 'body' (#2339)
824840
}
841+
ast::mac_invoc_tt(path, tts) {
842+
print_path(s, path, false);
843+
word(s.s, "!");
844+
bopen(s);
845+
for tts.each() |tt| { print_tt(s, tt); }
846+
bclose(s, m.span);
847+
}
825848
ast::mac_embed_type(ty) {
826849
word(s.s, "#<");
827850
print_type(s, ty);

0 commit comments

Comments
 (0)