|
| 1 | +#[cfg(test)] |
| 2 | +mod tests; |
| 3 | + |
| 4 | +pub mod state; |
| 5 | +pub use state::{print_crate, AnnNode, Comments, PpAnn, PrintState, State}; |
| 6 | + |
| 7 | +use rustc_ast as ast; |
| 8 | +use rustc_ast::token::{Nonterminal, Token, TokenKind}; |
| 9 | +use rustc_ast::tokenstream::{TokenStream, TokenTree}; |
| 10 | + |
| 11 | +pub fn nonterminal_to_string_no_extra_parens(nt: &Nonterminal) -> String { |
| 12 | + let state = State::without_insert_extra_parens(); |
| 13 | + state.nonterminal_to_string(nt) |
| 14 | +} |
| 15 | + |
| 16 | +pub fn nonterminal_to_string(nt: &Nonterminal) -> String { |
| 17 | + State::new().nonterminal_to_string(nt) |
| 18 | +} |
| 19 | + |
| 20 | +/// Print the token kind precisely, without converting `$crate` into its respective crate name. |
| 21 | +pub fn token_kind_to_string(tok: &TokenKind) -> String { |
| 22 | + State::new().token_kind_to_string(tok) |
| 23 | +} |
| 24 | + |
| 25 | +/// Print the token precisely, without converting `$crate` into its respective crate name. |
| 26 | +pub fn token_to_string(token: &Token) -> String { |
| 27 | + State::new().token_to_string(token) |
| 28 | +} |
| 29 | + |
| 30 | +pub fn token_to_string_ext(token: &Token, convert_dollar_crate: bool) -> String { |
| 31 | + State::new().token_to_string_ext(token, convert_dollar_crate) |
| 32 | +} |
| 33 | + |
| 34 | +pub fn ty_to_string(ty: &ast::Ty) -> String { |
| 35 | + State::new().ty_to_string(ty) |
| 36 | +} |
| 37 | + |
| 38 | +pub fn bounds_to_string(bounds: &[ast::GenericBound]) -> String { |
| 39 | + State::new().bounds_to_string(bounds) |
| 40 | +} |
| 41 | + |
| 42 | +pub fn pat_to_string(pat: &ast::Pat) -> String { |
| 43 | + State::new().pat_to_string(pat) |
| 44 | +} |
| 45 | + |
| 46 | +pub fn expr_to_string(e: &ast::Expr) -> String { |
| 47 | + State::new().expr_to_string(e) |
| 48 | +} |
| 49 | + |
| 50 | +pub fn tt_to_string(tt: &TokenTree) -> String { |
| 51 | + State::new().tt_to_string(tt) |
| 52 | +} |
| 53 | + |
| 54 | +pub fn tts_to_string(tokens: &TokenStream) -> String { |
| 55 | + State::new().tts_to_string(tokens) |
| 56 | +} |
| 57 | + |
| 58 | +pub fn stmt_to_string(stmt: &ast::Stmt) -> String { |
| 59 | + State::new().stmt_to_string(stmt) |
| 60 | +} |
| 61 | + |
| 62 | +pub fn item_to_string(i: &ast::Item) -> String { |
| 63 | + State::new().item_to_string(i) |
| 64 | +} |
| 65 | + |
| 66 | +pub fn generic_params_to_string(generic_params: &[ast::GenericParam]) -> String { |
| 67 | + State::new().generic_params_to_string(generic_params) |
| 68 | +} |
| 69 | + |
| 70 | +pub fn path_to_string(p: &ast::Path) -> String { |
| 71 | + State::new().path_to_string(p) |
| 72 | +} |
| 73 | + |
| 74 | +pub fn path_segment_to_string(p: &ast::PathSegment) -> String { |
| 75 | + State::new().path_segment_to_string(p) |
| 76 | +} |
| 77 | + |
| 78 | +pub fn vis_to_string(v: &ast::Visibility) -> String { |
| 79 | + State::new().vis_to_string(v) |
| 80 | +} |
| 81 | + |
| 82 | +pub fn block_to_string(blk: &ast::Block) -> String { |
| 83 | + State::new().block_to_string(blk) |
| 84 | +} |
| 85 | + |
| 86 | +pub fn meta_list_item_to_string(li: &ast::NestedMetaItem) -> String { |
| 87 | + State::new().meta_list_item_to_string(li) |
| 88 | +} |
| 89 | + |
| 90 | +pub fn attr_item_to_string(ai: &ast::AttrItem) -> String { |
| 91 | + State::new().attr_item_to_string(ai) |
| 92 | +} |
| 93 | + |
| 94 | +pub fn attribute_to_string(attr: &ast::Attribute) -> String { |
| 95 | + State::new().attribute_to_string(attr) |
| 96 | +} |
| 97 | + |
| 98 | +pub fn param_to_string(arg: &ast::Param) -> String { |
| 99 | + State::new().param_to_string(arg) |
| 100 | +} |
| 101 | + |
| 102 | +pub fn to_string(f: impl FnOnce(&mut State<'_>)) -> String { |
| 103 | + State::new().to_string(f) |
| 104 | +} |
0 commit comments