@@ -227,6 +227,53 @@ impl Subtree {
227227 }
228228}
229229
230+ impl Subtree {
231+ /// A simple line string used for debugging
232+ pub fn as_debug_string ( & self ) -> String {
233+ let delim = match self . delimiter_kind ( ) {
234+ Some ( DelimiterKind :: Brace ) => ( "{" , "}" ) ,
235+ Some ( DelimiterKind :: Bracket ) => ( "[" , "]" ) ,
236+ Some ( DelimiterKind :: Parenthesis ) => ( "(" , ")" ) ,
237+ None => ( " " , " " ) ,
238+ } ;
239+
240+ let mut res = String :: new ( ) ;
241+ res. push_str ( delim. 0 ) ;
242+ let mut iter = self . token_trees . iter ( ) ;
243+ let mut last = None ;
244+ while let Some ( child) = iter. next ( ) {
245+ let s = match child {
246+ TokenTree :: Leaf ( it) => {
247+ let s = match it {
248+ Leaf :: Literal ( it) => it. text . to_string ( ) ,
249+ Leaf :: Punct ( it) => it. char . to_string ( ) ,
250+ Leaf :: Ident ( it) => it. text . to_string ( ) ,
251+ } ;
252+ match ( it, last) {
253+ ( Leaf :: Ident ( _) , Some ( & TokenTree :: Leaf ( Leaf :: Ident ( _) ) ) ) => {
254+ " " . to_string ( ) + & s
255+ }
256+ ( Leaf :: Punct ( _) , Some ( & TokenTree :: Leaf ( Leaf :: Punct ( punct) ) ) ) => {
257+ if punct. spacing == Spacing :: Alone {
258+ " " . to_string ( ) + & s
259+ } else {
260+ s
261+ }
262+ }
263+ _ => s,
264+ }
265+ }
266+ TokenTree :: Subtree ( it) => it. as_debug_string ( ) ,
267+ } ;
268+ res. push_str ( & s) ;
269+ last = Some ( child) ;
270+ }
271+
272+ res. push_str ( delim. 1 ) ;
273+ res
274+ }
275+ }
276+
230277pub mod buffer;
231278
232279#[ derive( Debug , PartialEq , Eq , Clone ) ]
0 commit comments