1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Syntax extensions in the Rust compiler.
13 #![crate_name = "syntax_ext"]
14 #![unstable(feature = "rustc_private", issue = "27812")]
15 #![crate_type = "dylib"]
16 #![crate_type = "rlib"]
17 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
18 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
19 html_root_url = "https://doc.rust-lang.org/nightly/")]
22 #![feature(proc_macro_internals)]
23 #![feature(rustc_private)]
24 #![feature(staged_api)]
26 extern crate fmt_macros;
31 extern crate syntax_pos;
32 extern crate proc_macro;
33 extern crate rustc_errors as errors;
45 pub mod proc_macro_registrar;
52 use syntax::ext::base::{MacroExpanderFn, NormalTT, MultiModifier, NamedSyntaxExtension};
53 use syntax::symbol::Symbol;
55 pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver,
56 user_exts: Vec<NamedSyntaxExtension>,
57 enable_quotes: bool) {
58 let mut register = |name, ext| {
59 resolver.add_ext(ast::Ident::with_empty_ctxt(name), Rc::new(ext));
62 macro_rules! register {
63 ($( $name:ident: $f:expr, )*) => { $(
64 register(Symbol::intern(stringify!($name)),
65 NormalTT(Box::new($f as MacroExpanderFn), None, false));
70 use syntax::ext::quote::*;
72 quote_tokens: expand_quote_tokens,
73 quote_expr: expand_quote_expr,
74 quote_ty: expand_quote_ty,
75 quote_item: expand_quote_item,
76 quote_pat: expand_quote_pat,
77 quote_arm: expand_quote_arm,
78 quote_stmt: expand_quote_stmt,
79 quote_matcher: expand_quote_matcher,
80 quote_attr: expand_quote_attr,
81 quote_arg: expand_quote_arg,
82 quote_block: expand_quote_block,
83 quote_meta_item: expand_quote_meta_item,
84 quote_path: expand_quote_path,
88 use syntax::ext::source_util::*;
91 column: expand_column,
93 stringify: expand_stringify,
94 include: expand_include,
95 include_str: expand_include_str,
96 include_bytes: expand_include_bytes,
97 module_path: expand_mod,
100 cfg: cfg::expand_cfg,
101 concat: concat::expand_syntax_ext,
102 concat_idents: concat_idents::expand_syntax_ext,
103 env: env::expand_env,
104 option_env: env::expand_option_env,
105 log_syntax: log_syntax::expand_syntax_ext,
106 trace_macros: trace_macros::expand_trace_macros,
109 // format_args uses `unstable` things internally.
110 register(Symbol::intern("format_args"),
111 NormalTT(Box::new(format::expand_format_args), None, true));
113 register(Symbol::intern("derive"), MultiModifier(Box::new(deriving::expand_derive)));
115 for (name, ext) in user_exts {