Skip to content

Commit a20ae89

Browse files
committed
Move pprust code to a 'state' submodule
1 parent bc74dd7 commit a20ae89

File tree

2 files changed

+299
-179
lines changed

2 files changed

+299
-179
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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(nt: &Nonterminal) -> String {
12+
State::new().nonterminal_to_string(nt)
13+
}
14+
15+
/// Print the token kind precisely, without converting `$crate` into its respective crate name.
16+
pub fn token_kind_to_string(tok: &TokenKind) -> String {
17+
State::new().token_kind_to_string(tok)
18+
}
19+
20+
/// Print the token precisely, without converting `$crate` into its respective crate name.
21+
pub fn token_to_string(token: &Token) -> String {
22+
State::new().token_to_string(token)
23+
}
24+
25+
pub fn token_to_string_ext(token: &Token, convert_dollar_crate: bool) -> String {
26+
State::new().token_to_string_ext(token, convert_dollar_crate)
27+
}
28+
29+
pub fn ty_to_string(ty: &ast::Ty) -> String {
30+
State::new().ty_to_string(ty)
31+
}
32+
33+
pub fn bounds_to_string(bounds: &[ast::GenericBound]) -> String {
34+
State::new().bounds_to_string(bounds)
35+
}
36+
37+
pub fn pat_to_string(pat: &ast::Pat) -> String {
38+
State::new().pat_to_string(pat)
39+
}
40+
41+
pub fn expr_to_string(e: &ast::Expr) -> String {
42+
State::new().expr_to_string(e)
43+
}
44+
45+
pub fn tt_to_string(tt: &TokenTree) -> String {
46+
State::new().tt_to_string(tt)
47+
}
48+
49+
pub fn tts_to_string(tokens: &TokenStream) -> String {
50+
State::new().tts_to_string(tokens)
51+
}
52+
53+
pub fn stmt_to_string(stmt: &ast::Stmt) -> String {
54+
State::new().stmt_to_string(stmt)
55+
}
56+
57+
pub fn item_to_string(i: &ast::Item) -> String {
58+
State::new().item_to_string(i)
59+
}
60+
61+
pub fn generic_params_to_string(generic_params: &[ast::GenericParam]) -> String {
62+
State::new().generic_params_to_string(generic_params)
63+
}
64+
65+
pub fn path_to_string(p: &ast::Path) -> String {
66+
State::new().path_to_string(p)
67+
}
68+
69+
pub fn path_segment_to_string(p: &ast::PathSegment) -> String {
70+
State::new().path_segment_to_string(p)
71+
}
72+
73+
pub fn vis_to_string(v: &ast::Visibility) -> String {
74+
State::new().vis_to_string(v)
75+
}
76+
77+
pub fn block_to_string(blk: &ast::Block) -> String {
78+
State::new().block_to_string(blk)
79+
}
80+
81+
pub fn meta_list_item_to_string(li: &ast::NestedMetaItem) -> String {
82+
State::new().meta_list_item_to_string(li)
83+
}
84+
85+
pub fn attr_item_to_string(ai: &ast::AttrItem) -> String {
86+
State::new().attr_item_to_string(ai)
87+
}
88+
89+
pub fn attribute_to_string(attr: &ast::Attribute) -> String {
90+
State::new().attribute_to_string(attr)
91+
}
92+
93+
pub fn param_to_string(arg: &ast::Param) -> String {
94+
State::new().param_to_string(arg)
95+
}
96+
97+
pub fn to_string(f: impl FnOnce(&mut State<'_>)) -> String {
98+
State::new().to_string(f)
99+
}

0 commit comments

Comments
 (0)