pub fn parse_rust_macro<F>(tts: &[TokenTree], f: &mut F) -> Vec<Spanned<String>>
        where F: FnMut(Span, &[TokenTree]) -> Vec<Spanned<String>> {
    let mut result = Vec::new();

    // Iterate over the tokens with 3 tokens of lookahead.
    let mut i = 0;
    loop {
        match (tts.get(i), tts.get(i+1), tts.get(i+2)) {
            (Some(&TokenTree::Token(_, token::Ident(ident))),
             Some(&TokenTree::Token(_, token::Not)),
             Some(&TokenTree::Delimited(span, ref contents)))
                    if ident.name.to_string() == "rust" => {
                i += 2;
                result.extend(f(span, &contents.tts));
            }

            (Some(&TokenTree::Delimited(_, ref contents)), _, _) => {
                // Recursively look into the token tree
                result.push(respan(contents.open_span, token_to_string(&contents.open_token())));
                result.extend(parse_rust_macro(&contents.tts, f));
                result.push(respan(contents.close_span, token_to_string(&contents.close_token())));
            }

            (Some(&TokenTree::Token(span, ref tok)), _, _) => {
                result.push(respan(span, token_to_string(tok)));
            }

            (Some(&TokenTree::Sequence(..)), _, _) => unimplemented!(),

            (None, _, _) => break,
        }

        i += 1;
    }

    result
}
/// Find and replace uses of rust![ .. ] in a token tree stream.
///
/// The callback is invoked for every use of the rust! macro and it's result is used to replace it.
Find and replace uses of rust![ .. ] in a token tree stream.
The callback is invoked for every use of the rust. macro and it's result is used to replace it.
Find and replace uses of rust! [ .. ] in a token tree stream . The callback is invoked for every use of the rust . macro and it ' s result is used to replace it .
pub fn parse_rust_macro<F>(tts: &[TokenTree], f: &mut F) -> Vec<Spanned<String>>
        where F: FnMut(Span, &[TokenTree]) -> Vec<Spanned<String>> {
    let mut result = Vec::new();
    // Iterate over the tokens with 3 tokens of lookahead.
    let mut i = 0;
    loop {
        match (tts.get(i), tts.get(i+1), tts.get(i+2)) {
            (Some(&TokenTree::Token(_, token::Ident(ident))),
             Some(&TokenTree::Token(_, token::Not)),
             Some(&TokenTree::Delimited(span, ref contents)))
                    if ident.name.to_string() == "rust" => {
                i += 2;
                result.extend(f(span, &contents.tts));
            }
            (Some(&TokenTree::Delimited(_, ref contents)), _, _) => {
                // Recursively look into the token tree
                result.push(respan(contents.open_span, token_to_string(&contents.open_token())));
                result.extend(parse_rust_macro(&contents.tts, f));
                result.push(respan(contents.close_span, token_to_string(&contents.close_token())));
            }
            (Some(&TokenTree::Token(span, ref tok)), _, _) => {
                result.push(respan(span, token_to_string(tok)));
            }
            (Some(&TokenTree::Sequence(..)), _, _) => unimplemented!(),
            (None, _, _) => break,
        }
        i += 1;
    }
    result
}
pub fn parse_rust_macro < F > ( tts : & [ TokenTree ] , f : & mut F ) -> Vec < Spanned < String > > where F : FnMut ( Span , & [ TokenTree ] ) -> Vec < Spanned < String > > { let mut result = Vec :: new ( ) ; // Iterate over the tokens with 3 tokens of lookahead. let mut i = 0 ; loop { match ( tts . get ( i ) , tts . get ( i + 1 ) , tts . get ( i + 2 ) ) { ( Some ( & TokenTree :: Token ( _ , token :: Ident ( ident ) ) ) , Some ( & TokenTree :: Token ( _ , token :: Not ) ) , Some ( & TokenTree :: Delimited ( span , ref contents ) ) ) if ident . name . to_string ( ) == " " => { i += 2 ; result . extend ( f ( span , & contents . tts ) ) ; } ( Some ( & TokenTree :: Delimited ( _ , ref contents ) ) , _ , _ ) => { // Recursively look into the token tree result . push ( respan ( contents . open_span , token_to_string ( & contents . open_token ( ) ) ) ) ; result . extend ( parse_rust_macro ( & contents . tts , f ) ) ; result . push ( respan ( contents . close_span , token_to_string ( & contents . close_token ( ) ) ) ) ; } ( Some ( & TokenTree :: Token ( span , ref tok ) ) , _ , _ ) => { result . push ( respan ( span , token_to_string ( tok ) ) ) ; } ( Some ( & TokenTree :: Sequence ( .. ) ) , _ , _ ) => unimplemented ! ( ) , ( None , _ , _ ) => break , } i += 1 ; } result }
Find and replace uses of rust!
Find and replace uses of rust!
tts
&[TokenTree]
f
&mut F
tts
&[TokenTree]
f
&mut F