quasi_macros 0.1.3

A quasi-quoting macro system
b0VIM 7.4U��T��UB�ericktErick-Tryzelaar-MBP.local~erickt/projects/rust/rust-quasi/quasi_macros/src/lib.rsutf-8
3210#"! Utpfmhb�f7\�(�adef��]Z��R.-�
�
�
�
�
�
�
�
c
L
/



����g$�����rV6�
�
�
�
~
]
.
�	�	�	�	�	T	,	��mJHG���XW/����dc@>=
��s+���O�����N����qL��                           tts: &                               tts: &[ast::TokenTree])                           sp: Span,pub fn expand_quote_method(cx: &mut ExtCtxt,}    base::MacEager::expr(expanded)    let expanded = expand_parse_call(cx, sp, "parse_block", Vec::new(), tts);                              -> Box<base::MacResult+'cx> {                              tts: &[ast::TokenTree])                              sp: Span,pub fn expand_quote_block<'cx>(cx: &'cx mut ExtCtxt,}    base::MacEager::expr(expanded)    let expanded = expand_parse_call(cx, sp, "parse_arm", vec!(), tts);                        -> Box<base::MacResult+'static> {                        tts: &[ast::TokenTree])                        sp: Span,pub fn expand_quote_arm(cx: &mut ExtCtxt,}    base::MacEager::expr(expanded)    let expanded = expand_parse_call(cx, sp, "parse_pat", vec!(), tts);                             -> Box<base::MacResult+'cx> {                             tts: &[ast::TokenTree])                             sp: Span,pub fn expand_quote_pat<'cx>(cx: &'cx mut ExtCtxt,}    base::MacEager::expr(expanded)                                    vec!(e_attrs), tts);    let expanded = expand_parse_call(cx, sp, "parse_stmt",        .build();        .path().global().ids(&["std", "vec", "Vec", "new"]).build()    let e_attrs = builder.expr().call()    let builder = aster::AstBuilder::new().span(sp);                         -> Box<base::MacResult+'static> {                         tts: &[ast::TokenTree])                         sp: Span,pub fn expand_quote_stmt(cx: &mut ExtCtxt,}    base::MacEager::expr(expanded)    let expanded = expand_parse_call(cx, sp, "parse_expr", Vec::new(), tts);                              -> Box<base::MacResult+'cx> {                              tts: &[ast::TokenTree])                              sp: Span,pub fn expand_quote_expr<'cx>(cx: &'cx mut ExtCtxt,}    base::MacEager::expr(expanded)    let expanded = expand_parse_call(cx, sp, "parse_ty", vec!(), tts);                       -> Box<base::MacResult+'static> {                       tts: &[ast::TokenTree])                       sp: Span,pub fn expand_quote_ty(cx: &mut ExtCtxt,}    base::MacEager::expr(expanded)    let expanded = expand_wrapper(sp, cx_expr, expr);    let (cx_expr, expr) = expand_tts(cx, sp, tts);) -> Box<base::MacResult+'cx> {    tts: &[ast::TokenTree],    sp: Span,    cx: &'cx mut ExtCtxt,pub fn expand_quote_tokens<'cx>(///  as antiquotes (splices).///  construction of the same token tree, with token::SubstNt interpreted///  that lifts its argument token-tree to an AST representing the///  This is registered as a set of expression syntax extension called quote!//////  Quasiquoting works via token trees.use rustc::plugin::Registry;use syntax::ptr::P;use syntax::parse::token;use syntax::parse::token::*;use syntax::ext::base;use syntax::ext::base::ExtCtxt;use syntax::codemap::Span;use syntax::ast;extern crate aster;extern crate rustc;extern crate syntax;#![feature(plugin_registrar, unboxed_closures, rustc_private)]// except according to those terms.// option. This file may not be copied, modified, or distributed// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or//// http://rust-lang.org/COPYRIGHT.// file at the top-level directory of this distribution and at// Copyright 2012 The Rust Project Developers. See the COPYRIGHTadC
�
(����]G54�����uR6�
�
�

~
X
V
U
A
2

��Y ��w:�
�
}}}}}   }    reg.register_macro("quote_item", expand_quote_item);    reg.register_macro("quote_method", expand_quote_method);    reg.register_macro("quote_block", expand_quote_block);    reg.register_macro("quote_arm", expand_quote_arm);    reg.register_macro("quote_pat", expand_quote_pat);    reg.register_macro("quote_stmt", expand_quote_stmt);    reg.register_macro("quote_expr", expand_quote_expr);    reg.register_macro("quote_ty", expand_quote_ty);    reg.register_macro("quote_tokens", expand_quote_tokens);pub fn plugin_registrar(reg: &mut Registry) {#[doc(hidden)]#[plugin_registrar]}    expand_wrapper(sp, cx_expr, expr)        .build();        .with_args(arg_exprs)        .build(new_parser_call)    let expr = builder.expr().method_call(parse_method)        .build();        .with_arg(tts_expr)        .with_arg(cfg_call)        .with_arg(parse_sess_call)        .id("new_parser_from_tts")    let new_parser_call = builder.expr().call()        .build();        .id("ext_cx")    let parse_sess_call = builder.expr().method_call("parse_sess")        .build();        .id("ext_cx")    let cfg_call = builder.expr().method_call("cfg")    let (cx_expr, tts_expr) = expand_tts(cx, sp, tts);    let builder = aster::AstBuilder::new().span(sp);adN�b����a$�����e<21�
�
�
�
b
-

����WML����tWB�
�
�
�
f
\
[
!

�	�	�	�	y	x	P	*	����~F������L�����o<#��a"��k*��m0��q2��                            token::Colon        => mk_token_path(builder, "Colon"),        token::Semi         => mk_token_path(builder, "Semi"),        token::Comma        => mk_token_path(builder, "Comma"),        token::DotDot       => mk_token_path(builder, "DotDot"),        token::Dot          => mk_token_path(builder, "Dot"),        token::At           => mk_token_path(builder, "At"),        token::Tilde        => mk_token_path(builder, "Tilde"),        token::Not          => mk_token_path(builder, "Not"),        token::OrOr         => mk_token_path(builder, "OrOr"),        token::AndAnd       => mk_token_path(builder, "AndAnd"),        token::Gt           => mk_token_path(builder, "Gt"),        token::Ge           => mk_token_path(builder, "Ge"),        token::Ne           => mk_token_path(builder, "Ne"),        token::EqEq         => mk_token_path(builder, "EqEq"),        token::Le           => mk_token_path(builder, "Le"),        token::Lt           => mk_token_path(builder, "Lt"),        token::Eq           => mk_token_path(builder, "Eq"),        }                .build()                .with_arg(mk_name(builder, ident))                .build(mk_token_path(builder, "DocComment"))            builder.expr().call()        token::DocComment(ident) => {        }                .build()                .with_arg(mk_ident(builder, ident))                .build(mk_token_path(builder, "Lifetime"))            builder.expr().call()        token::Lifetime(ident) => {        }                .build()                .with_arg(style)                .with_arg(mk_ident(builder, ident))                .build(mk_token_path(builder, "Ident"))            builder.expr().call()            };                Plain   => mk_token_path(builder, "Plain"),                ModName => mk_token_path(builder, "ModName"),            let style = match style {        token::Ident(ident, style) => {        }                builder.expr().usize(n))                mk_name(builder, ident.ident()),                suf,                "StrRaw",            mk_lit!(        token::Literal(token::StrRaw(ident, n), suf) => {        }            mk_lit!("Str_", suf, mk_name(builder, ident.ident()))        token::Literal(token::Str_(ident), suf) => {        }                builder.expr().usize(n))                mk_name(builder, ident.ident()),                suf,                "BinaryRaw",            mk_lit!(        token::Literal(token::BinaryRaw(ident, n), suf) => {        }            mk_lit!("Binary", suf, mk_name(builder, ident.ident()))        token::Literal(token::Binary(ident), suf) => {        }            mk_lit!("Float", suf, e_fident)            let e_fident = mk_name(builder, fident.ident());        token::Literal(token::Float(fident), suf) => {        }            mk_lit!("Integer", suf, e_int)            let e_int = mk_name(builder, i.ident());        token::Literal(token::Integer(i), suf) => {        }            mk_lit!("Char", suf, e_char)            let e_char = mk_name(builder, i.ident());        token::Literal(token::Char(i), suf) => {        }            mk_lit!("Byte", suf, e_byte)            let e_byte = mk_name(builder, i.ident());        token::Literal(token::Byte(i), suf) => {        }                .build()                .with_arg(mk_delim(builder, delim))                .build(mk_token_path(builder, "CloseDelim"))            builder.expr().call()        token::CloseDelim(delim) => {        }                .build()                .with_arg(mk_delim(builder, delim))adXf�~=��y4�
�
o
*
����lN5+*
���wmged/�
�
�
�
M
L

�	�	�	�	j	H	.	-	�����aW$�����['&���kQP�����Q>�qVK���oib`_!��[��    // under quote_depth > 0. Thi        /    /    /    // under quote_depth > 0. This is silly and should go away; the _guess_ is    // $foo as a TtNonterminal during the main parse, so we have to re-parse    // NB: It appears that the main parser loses its mind if we consider              -> (P<ast::Expr>, P<ast::Expr>) {fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree])}    ss    }        ss.extend(mk_tt(tt).into_iter());    for tt in tts {    let mut ss = Vec::new();fn mk_tts(tts: &[ast::TokenTree]) -> Vec<P<ast::Stmt>> {}    }        ast::TtSequence(..) => panic!("TtSequence in quote!"),        },                .collect()                .chain(mk_tt(&delimed.close_tt()).into_iter())                .chain(delimed.tts.iter().flat_map(|tt| mk_tt(tt).into_iter()))            ).into_iter()                &delimed.open_tt(),            mk_tt(        ast::TtDelimited(_, ref delimed) => {        },            vec![builder.stmt().build_expr(e_push)]                .build();                .with_arg(e_tok)                .id("tt")            let e_push = builder.expr().method_call("push")                .build();                .with_arg(mk_token(&builder, tok))                .arg().id("_sp")                .build(mk_ast_path(&builder, "TtToken"))            let e_tok = builder.expr().call()            let builder = builder.clone().span(sp);        ast::TtToken(sp, ref tok) => {        }            mk_tts(&seq[..])            }                seq.push(tt.get_tt(i));            for i in 0..tt.len() {            let mut seq = vec![];        ref tt @ ast::TtToken(_, MatchNt(..)) => {        }            vec![builder.stmt().build_expr(e_push)]                .build();                .with_arg(e_to_toks)                .id("tt")            let e_push = builder.expr().method_call("extend")                .build();                .build(e_to_toks)            let e_to_toks = builder.expr().method_call("into_iter")                .build();                .arg().id("ext_cx")                .id(ident)            let e_to_toks = builder.expr().method_call("to_tokens")            let builder = builder.clone().span(sp);            // tt.extend($ident.to_tokens(ext_cx).into_iter())        ast::TtToken(sp, SubstNt(ident, _)) => {    match *tt {    let builder = aster::AstBuilder::new();fn mk_tt(tt: &ast::TokenTree) -> Vec<P<ast::Stmt>> {}    }        }            panic!("quote! with {:?} token", tok)        | token::SpecialVarNt(..) => {        | token::SubstNt(..)        | token::MatchNt(..)        token::Interpolated(..)        }                .build()                .arg().str(s)                .build(mk_token_path(builder, "Shebang"))            builder.expr().call()        token::Shebang(s) => {        token::Comment      => mk_token_path(builder, "Comment"),        token::Whitespace   => mk_token_path(builder, "Whitespace"),        token::Question     => mk_token_path(builder, "Question"),        token::DotDotDot    => mk_token_path(builder, "DotDotDot"),        token::Eof          => mk_token_path(builder, "Eof"),        token::Underscore   => mk_token_path(builder, "Underscore"),        token::Dollar       => mk_token_path(builder, "Dollar"),        token::Pound        => mk_token_path(builder, "Pound"),        token::FatArrow     => mk_token_path(builder, "FatArrow"),        token::LArrow       => mk_token_path(builder, "LArrow"),        token::RArrow       => mk_token_path(builder, "RArrow"),        token::ModSep       => mk_token_path(builder, "ModSep"),ad�/\�}|O76�������F?�
�
^

��~7��d�
�
@
�	�	Q		�r'
����xwR.-���~W7�������}E��{z@ ������tN*
���n/���    let ctx = aster::Ctx::new();    let ctx = aster::Ctx::new();                             tts: &[ast::                               tts: &[ast::TokenTree]) -> P<ast::Expr> {                     arg_exprs: Vec<P<ast::Expr>> ,                     parse_method: &str,                     sp: Span,fn expand_parse_call(cx: &ExtCtxt,}        .build_expr(expr)        .with_stmt(stmt_let_ext_cx)        .stmt().build_item(use_quote)    builder.expr().block()        .build();        .id("quasi")        .use_glob()        .attr().build_allow(&["unused_imports"])    let use_quote = builder.item()        .build(cx_expr_borrow);    let stmt_let_ext_cx = builder.stmt().let_id("ext_cx")        .addr_of().build_deref(cx_expr);    let cx_expr_borrow = builder.expr()    // Explicitly borrow to avoid moving from the invoker (#16992)    let builder = aster::AstBuilder::new().span(sp);                  expr: P<ast::Expr>) -> P<ast::Expr> {                  cx_expr: P<ast::Expr>,fn expand_wrapper(sp: Span,}    (cx_expr, block)        .expr().id("tt");        .with_stmts(mk_tts(&tts))        .with_stmt(stmt_let_tt)        .with_stmt(stmt_let_sp)    let block = builder.expr().block()            .build();            .path().global().ids(&["std", "vec", "Vec", "new"]).build()        .expr().call()    let stmt_let_tt = builder.stmt().let_().mut_id("tt")        .let_id("_sp").build(e_sp);    let stmt_let_sp = builder.stmt()        .build();        .id("ext_cx")    let e_sp = builder.expr().method_call("call_site")    let builder = aster::AstBuilder::new().span(sp);    // worth the hassle.    // of quotes, for example) but at this point it seems not likely to be    // (pushing fake FileMaps onto the parser to account for original sites    // by recreating some of the original qq machinery in the tt regime    // just makes quotes "hard to attribute". Possibly this could be fixed    // they happen to have a compiler on hand). Over all, the phase distinction    // file in libsyntax, which the user might not even have source to (unless    // using macro_rules! for example, will be attributed to the macro_rules.rs    // error in a quote from the protocol compiler, invoked in user code    // _other_ than the one the user has control over. For example, an    // the site the string literal occurred, which was in a source file    // resulting from a parse of the resulting quote is still attributed to    // pushed the problem a very small step further back: an error    // compiler (which we don't really want to do) and, in any case, only    // relied on feeding the source string of the quote back into the    // file locations from which quotes originated; unfortunately this    // The old quasiquoter had an elaborate mechanism for denoting input    //    // source code for (eg. in libsyntax, which they're just _using_).    // was not even parsed by this compilation run, that the user has no    // better since the source of the quote may well be in a library that    // call site of the extension using the quote. We can't really do much    // This causes every span in a token-tree quote to be attributed to the    //    // We also bind a single value, sp, to ext_cx.call_site()    p.abort_if_errors();    let tts = p.parse_all_token_trees();    }        p.fatal("expected token `,`");    if !p.eat(&token::Comma) {    let cx_expr = p.parse_expr();    p.quote_depth += 1;    let mut p = cx.new_parser_from_tts(tts);    // try removing it when enough of them are gone.    // it has to do with transition away from supporting old-style macros, soad8m�p=���M�
�
�
�
�
i

�����~:
�����_E3�
�
�
�
�
�
N
=
;
:
�	�	�	�	b	>		����ngFDC����`Y865��n@
����N���pWLFE4���lb?�����fD�                .build_e                .build(mk_token_path(builder, "OpenDelim"))            builder.expr().call()        token::OpenDelim(delim) => {        }                .build()                .with_arg(mk_binop(builder, binop))                .build(mk_token_path(builder, "BinOpEq"))            builder.expr().call()        token::BinOpEq(binop) => {        }                .build()                .with_arg(mk_binop(builder, binop))                .build(mk_token_path(builder, "BinOp"))            builder.expr().call()        token::BinOp(binop) => {    match *tok {    }        }}                .build()                .with_arg(suffix)                .with_arg(inner)                .build(mk_token_path(builder, "Literal"))            builder.expr().call()            };                None => builder.expr().none(),                Some(name) => builder.expr().some().build(mk_name(builder, name)),            let suffix = match $suffix {                .build();                $(.with_arg($args))+                .build(mk_token_path(builder, $name))            let inner = builder.expr().call()        ($name: expr, $suffix: expr, $($args: expr),+) => {{    macro_rules! mk_lit {fn mk_token(builder: &aster::AstBuilder, tok: &token::Token) -> P<ast::Expr> {#[allow(non_upper_case_globals)]}    mk_token_path(builder, name)    };        token::Brace     => "Brace",        token::Bracket   => "Bracket",        token::Paren     => "Paren",    let name = match delim {fn mk_delim(builder: &aster::AstBuilder, delim: token::DelimToken) -> P<ast::Expr> {}    mk_token_path(builder, name)    };        token::Shr      => "Shr"        token::Shl      => "Shl",        token::Or       => "Or",        token::And      => "And",        token::Caret    => "Caret",        token::Percent  => "Percent",        token::Slash    => "Slash",        token::Star     => "Star",        token::Minus    => "Minus",        token::Plus     => "Plus",    let name = match bop {fn mk_binop(builder: &aster::AstBuilder, bop: token::BinOpToken) -> P<ast::Expr> {}        .build()        .ids(&["syntax", "parse", "token", name])        .global()    builder.expr().path()fn mk_token_path(builder: &aster::AstBuilder, name: &str) -> P<ast::Expr> {}        .build()        .ids(&["syntax", "ast", name])        .global()    builder.expr().path()fn mk_ast_path(builder: &aster::AstBuilder, name: &str) -> P<ast::Expr> {}        .build()        .arg().str(name)    builder.expr().method_call("name_of").id("ext_cx"){    where T: aster::str::ToInternedString,fn mk_name<T>(builder: &aster::AstBuilder, name: T) -> P<ast::Expr>// Lift a name to the expr that evaluates to that name}        .build()        .arg().str(ident)    builder.expr().method_call("ident_of").id("ext_cx")fn mk_ident(builder: &aster::AstBuilder, ident: ast::Ident) -> P<ast::Expr> {// Lift an ident to the expr that evaluates to that ident.}    base::MacEager::expr(expanded)                                    vec!(), tts);    let expanded = expand_parse_call(cx, sp, "parse_item_with_outer_attributes",                              -> Box<base::MacResult+'cx> {                              tts: &[ast::TokenTree])                              sp: Span,pub fn expand_quote_item<'cx>(cx: &mut ExtCtxt,}    base::MacEager::expr(expanded)                                     vec!(), tts);    let expanded = expand_parse_call(cx, sp, "parse_method_with_outer_attributes",                           -> Box<base::MacResult+'static> {