fn convert_complex_tts<'cx>(cx: &'cx mut ExtCtxt, tts: Vec<QTT>) -> (Bindings, TokenStream) {
    let mut pushes: Vec<TokenStream> = Vec::new();
    let mut bindings: Bindings = Vec::new();

    let mut iter = tts.into_iter();

    loop {
        let next = iter.next();
        if next.is_none() {
            break;
        }
        let next = next.unwrap();
        match next {
            QTT::TT(TokenTree::Token(_, t)) => {
                let token_out = emit_token(t);
                pushes.push(token_out);
            }
            // FIXME handle sequence repetition tokens
            QTT::QDL(qdl) => {
                debug!("  QDL: {:?} ", qdl.tts);
                let new_id = gensym_ident("qdl_tmp");
                let mut cct_rec = convert_complex_tts(cx, qdl.tts);
                bindings.append(&mut cct_rec.0);
                bindings.push((new_id, cct_rec.1));

                let sep = build_delim_tok(qdl.delim);

                pushes.push(build_mod_call(vec![str_to_ident("proc_macro_tokens"),
                                               str_to_ident("build"),
                                               str_to_ident("build_delimited")],
                                          concat(from_tokens(vec![Token::Ident(new_id)]),
                                                 concat(lex(","), sep))));
            }
            QTT::QIdent(t) => {
                pushes.push(TokenStream::from_tts(vec![t]));
                pushes.push(TokenStream::mk_empty());
            }
            _ => panic!("Unhandled case!"),
        }

    }

    (bindings, unravel_concats(pushes))
}
/// This converts the vector of QTTs into a seet of Bindings for construction and the main
/// body as a TokenStream.
This converts the vector of QTTs into a seet of Bindings for construction and the main
body as a TokenStream.
This converts the vector of QTTs into a seet of Bindings for construction and the main body as a TokenStream .
fn convert_complex_tts<'cx>(cx: &'cx mut ExtCtxt, tts: Vec<QTT>) -> (Bindings, TokenStream) {
    let mut pushes: Vec<TokenStream> = Vec::new();
    let mut bindings: Bindings = Vec::new();
    let mut iter = tts.into_iter();
    loop {
        let next = iter.next();
        if next.is_none() {
            break;
        }
        let next = next.unwrap();
        match next {
            QTT::TT(TokenTree::Token(_, t)) => {
                let token_out = emit_token(t);
                pushes.push(token_out);
            }
            // FIXME handle sequence repetition tokens
            QTT::QDL(qdl) => {
                debug!("  QDL: {:?} ", qdl.tts);
                let new_id = gensym_ident("qdl_tmp");
                let mut cct_rec = convert_complex_tts(cx, qdl.tts);
                bindings.append(&mut cct_rec.0);
                bindings.push((new_id, cct_rec.1));
                let sep = build_delim_tok(qdl.delim);
                pushes.push(build_mod_call(vec![str_to_ident("proc_macro_tokens"),
                                               str_to_ident("build"),
                                               str_to_ident("build_delimited")],
                                          concat(from_tokens(vec![Token::Ident(new_id)]),
                                                 concat(lex(","), sep))));
            }
            QTT::QIdent(t) => {
                pushes.push(TokenStream::from_tts(vec![t]));
                pushes.push(TokenStream::mk_empty());
            }
            _ => panic!("Unhandled case!"),
        }
    }
    (bindings, unravel_concats(pushes))
}
fn convert_complex_tts < ' cx > ( cx : & ' cx mut ExtCtxt , tts : Vec < QTT > ) -> ( Bindings , TokenStream ) { let mut pushes : Vec < TokenStream > = Vec :: new ( ) ; let mut bindings : Bindings = Vec :: new ( ) ; let mut iter = tts . into_iter ( ) ; loop { let next = iter . next ( ) ; if next . is_none ( ) { break ; } let next = next . unwrap ( ) ; match next { QTT :: TT ( TokenTree :: Token ( _ , t ) ) => { let token_out = emit_token ( t ) ; pushes . push ( token_out ) ; } // FIXME handle sequence repetition tokens QTT :: QDL ( qdl ) => { debug ! ( " " qdl tts ) ; let new_id = gensym_ident ( " " ) ; let mut cct_rec = convert_complex_tts ( cx , qdl . tts ) ; bindings . append ( & mut cct_rec . 0 ) ; bindings . push ( ( new_id , cct_rec . 1 ) ) ; let sep = build_delim_tok ( qdl . delim ) ; pushes . push ( build_mod_call ( vec ! [ str_to_ident ( " " ) str_to_ident ( " " ) str_to_ident ( " " ) ] , concat ( from_tokens ( vec ! [ Token Ident ( new_id ) ] ) , concat ( lex ( " " ) , sep ) ) ) ) ; } QTT :: QIdent ( t ) => { pushes . push ( TokenStream :: from_tts ( vec ! [ t ] ) ) ; pushes . push ( TokenStream :: mk_empty ( ) ) ; } _ => panic ! ( " " ) , } } ( bindings , unravel_concats ( pushes ) ) }
This converts the vector of QTTs into a seet of Bindings for construction and the main
body as a TokenStream.
This converts the vector of QTTs into a seet of Bindings for construction and the main body as a TokenStream .
cx
&'cx mut ExtCtxt
tts
Vec<QTT>
cx
&'cx mut ExtCtxt
tts
Vec<QTT>