rustc_parse: Move AST -> TokenStream conversion logic to rustc_ast
This commit is contained in:
parent
acfd327fd4
commit
8e8fb4f49e
14 changed files with 124 additions and 284 deletions
|
@ -4,42 +4,12 @@ mod tests;
|
|||
pub mod state;
|
||||
pub use state::{print_crate, AnnNode, Comments, PpAnn, PrintState, State};
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::token::{Nonterminal, Token, TokenKind};
|
||||
use rustc_ast::tokenstream::{TokenStream, TokenTree};
|
||||
use rustc_ast::{self as ast, AstDeref};
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
pub trait AstPrettyPrint {
|
||||
fn pretty_print(&self) -> String;
|
||||
}
|
||||
|
||||
impl<T: AstDeref<Target: AstPrettyPrint>> AstPrettyPrint for T {
|
||||
fn pretty_print(&self) -> String {
|
||||
self.ast_deref().pretty_print()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_ast_pretty_print {
|
||||
($($T:ty => $method:ident),+ $(,)?) => {
|
||||
$(
|
||||
impl AstPrettyPrint for $T {
|
||||
fn pretty_print(&self) -> String {
|
||||
State::new().$method(self)
|
||||
}
|
||||
}
|
||||
)+
|
||||
};
|
||||
}
|
||||
|
||||
impl_ast_pretty_print! {
|
||||
ast::Item => item_to_string,
|
||||
ast::AssocItem => assoc_item_to_string,
|
||||
ast::ForeignItem => foreign_item_to_string,
|
||||
ast::Expr => expr_to_string,
|
||||
ast::Stmt => stmt_to_string,
|
||||
}
|
||||
|
||||
pub fn nonterminal_to_string(nt: &Nonterminal) -> String {
|
||||
State::new().nonterminal_to_string(nt)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue