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 #![crate_type = "dylib"]
15 #![crate_type = "rlib"]
16 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
17 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
18 html_root_url = "https://doc.rust-lang.org/nightly/")]
21 #![feature(proc_macro_internals)]
23 extern crate fmt_macros;
27 extern crate syntax_pos;
28 extern crate proc_macro;
29 extern crate rustc_errors as errors;
43 pub mod proc_macro_registrar;
48 pub mod proc_macro_impl;
52 use syntax::ext::base::{MacroExpanderFn, NormalTT, 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 deriving::register_builtin_derives(resolver);
60 let mut register = |name, ext| {
61 resolver.add_builtin(ast::Ident::with_empty_ctxt(name), Rc::new(ext));
64 macro_rules! register {
65 ($( $name:ident: $f:expr, )*) => { $(
66 register(Symbol::intern(stringify!($name)),
67 NormalTT(Box::new($f as MacroExpanderFn), None, false));
72 use syntax::ext::quote::*;
74 quote_tokens: expand_quote_tokens,
75 quote_expr: expand_quote_expr,
76 quote_ty: expand_quote_ty,
77 quote_item: expand_quote_item,
78 quote_pat: expand_quote_pat,
79 quote_arm: expand_quote_arm,
80 quote_stmt: expand_quote_stmt,
81 quote_attr: expand_quote_attr,
82 quote_arg: expand_quote_arg,
83 quote_block: expand_quote_block,
84 quote_meta_item: expand_quote_meta_item,
85 quote_path: expand_quote_path,
89 use syntax::ext::source_util::*;
92 __rust_unstable_column: expand_column_gated,
93 column: expand_column,
95 stringify: expand_stringify,
96 include: expand_include,
97 include_str: expand_include_str,
98 include_bytes: expand_include_bytes,
99 module_path: expand_mod,
101 asm: asm::expand_asm,
102 global_asm: global_asm::expand_global_asm,
103 cfg: cfg::expand_cfg,
104 concat: concat::expand_syntax_ext,
105 concat_idents: concat_idents::expand_syntax_ext,
106 env: env::expand_env,
107 option_env: env::expand_option_env,
108 log_syntax: log_syntax::expand_syntax_ext,
109 trace_macros: trace_macros::expand_trace_macros,
110 compile_error: compile_error::expand_compile_error,
113 // format_args uses `unstable` things internally.
114 register(Symbol::intern("format_args"),
115 NormalTT(Box::new(format::expand_format_args), None, true));
117 for (name, ext) in user_exts {