pub fn print_tt(s: &mut State, tt: &ast::TokenTree) {
    match *tt {
      ast::TTDelim(ref tts) => print_tts(s, &(tts.as_slice())),
      ast::TTTok(_, ref tk) => {
          word(&mut s.s, parse::token::to_str(s.intr, tk));
      }
      ast::TTSeq(_, ref tts, ref sep, zerok) => {
        word(&mut s.s, "$(");
        for tt_elt in (*tts).iter() { print_tt(s, tt_elt); }
        word(&mut s.s, ")");
        match *sep {
          Some(ref tk) => word(&mut s.s, parse::token::to_str(s.intr, tk)),
          None => ()
        }
        word(&mut s.s, if zerok { "*" } else { "+" });
      }
      ast::TTNonterminal(_, name) => {
        word(&mut s.s, "$");
        print_ident(s, name);
      }
    }
}
/// This doesn't deserve to be called "pretty" printing, but it should be
/// meaning-preserving. A quick hack that might help would be to look at the
/// spans embedded in the TTs to decide where to put spaces and newlines.
/// But it'd be better to parse these according to the grammar of the
/// appropriate macro, transcribe back into the grammar we just parsed from,
/// and then pretty-print the resulting AST nodes (so, e.g., we print
/// expression arguments as expressions). It can be done! I think.
This doesn't deserve to be called "pretty" printing, but it should be
meaning-preserving. A quick hack that might help would be to look at the
spans embedded in the TTs to decide where to put spaces and newlines.
But it'd be better to parse these according to the grammar of the
appropriate macro, transcribe back into the grammar we just parsed from,
and then pretty-print the resulting AST nodes (so, e.g., we print
expression arguments as expressions). It can be done. I think.
This doesn ' t deserve to be called " pretty " printing but it should be meaning - preserving . A quick hack that might help would be to look at the spans embedded in the TTs to decide where to put spaces and newlines . But it ' d be better to parse these according to the grammar of the appropriate macro transcribe back into the grammar we just parsed from and then pretty - print the resulting AST nodes ( so e . g . we print expression arguments as expressions ) . It can be done . I think .
pub fn print_tt(s: &mut State, tt: &ast::TokenTree) {
    match *tt {
      ast::TTDelim(ref tts) => print_tts(s, &(tts.as_slice())),
      ast::TTTok(_, ref tk) => {
          word(&mut s.s, parse::token::to_str(s.intr, tk));
      }
      ast::TTSeq(_, ref tts, ref sep, zerok) => {
        word(&mut s.s, "$(");
        for tt_elt in (*tts).iter() { print_tt(s, tt_elt); }
        word(&mut s.s, ")");
        match *sep {
          Some(ref tk) => word(&mut s.s, parse::token::to_str(s.intr, tk)),
          None => ()
        }
        word(&mut s.s, if zerok { "*" } else { "+" });
      }
      ast::TTNonterminal(_, name) => {
        word(&mut s.s, "$");
        print_ident(s, name);
      }
    }
}
pub fn print_tt ( s : & mut State , tt : & ast :: TokenTree ) { match * tt { ast :: TTDelim ( ref tts ) => print_tts ( s , & ( tts . as_slice ( ) ) ) , ast :: TTTok ( _ , ref tk ) => { word ( & mut s . s , parse :: token :: to_str ( s . intr , tk ) ) ; } ast :: TTSeq ( _ , ref tts , ref sep , zerok ) => { word ( & mut s . s , " " ) ; for tt_elt in ( * tts ) . iter ( ) { print_tt ( s , tt_elt ) ; } word ( & mut s . s , " " ) ; match * sep { Some ( ref tk ) => word ( & mut s . s , parse :: token :: to_str ( s . intr , tk ) ) , None => ( ) } word ( & mut s . s , if zerok { " " } else { " " } ) ; } ast :: TTNonterminal ( _ , name ) => { word ( & mut s . s , " " ) ; print_ident ( s , name ) ; } } }
This doesn't deserve to be called "pretty" printing, but it should be
meaning-preserving.
This doesn ' t deserve to be called " pretty " printing but it should be meaning - preserving .
s
&mut State
tt
&ast::TokenTree
s
&mut State
tt
&ast::TokenTree