use parse::lexer;
use parse;
use parse::token::{self, Token, Lit, Nonterminal};
+use print::pprust;
use std::fmt;
use std::iter::*;
TokenStream::mk_leaf(Rc::new(trees), span)
}
+ /// Convert a vector of Tokens into a TokenStream.
+ pub fn from_tokens(tokens: Vec<Token>) -> TokenStream {
+ // FIXME do something nicer with the spans
+ TokenStream::from_tts(tokens.into_iter().map(|t| TokenTree::Token(DUMMY_SP, t)).collect())
+ }
+
/// Manually change a TokenStream's span.
pub fn respan(self, span: Span) -> TokenStream {
match self.ts {
}
}
+impl fmt::Display for TokenStream {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.write_str(&pprust::tts_to_string(&self.to_tts()))
+ }
+}
+
// FIXME Reimplement this iterator to hold onto a slice iterator for a leaf, getting the
// next leaf's iterator when the current one is exhausted.
pub struct Iter<'a> {