]> git.proxmox.com Git - rustc.git/blob - src/libsyntax_ext/lib.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / libsyntax_ext / lib.rs
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.
4 //
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.
10
11 //! Syntax extensions in the Rust compiler.
12
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/")]
20 #![cfg_attr(not(stage0), deny(warnings))]
21
22 #![feature(rustc_private)]
23 #![feature(staged_api)]
24
25 extern crate fmt_macros;
26 #[macro_use] extern crate log;
27 #[macro_use]
28 extern crate syntax;
29
30 use syntax::ext::base::{MacroExpanderFn, NormalTT};
31 use syntax::ext::base::{SyntaxEnv, SyntaxExtension};
32 use syntax::parse::token::intern;
33
34
35 mod asm;
36 mod cfg;
37 mod concat;
38 mod concat_idents;
39 mod env;
40 mod format;
41 mod log_syntax;
42 mod trace_macros;
43
44 // for custom_derive
45 pub mod deriving;
46
47 pub fn register_builtins(env: &mut SyntaxEnv) {
48 // utility function to simplify creating NormalTT syntax extensions
49 fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
50 NormalTT(Box::new(f), None, false)
51 }
52
53 env.insert(intern("asm"),
54 builtin_normal_expander(asm::expand_asm));
55 env.insert(intern("cfg"),
56 builtin_normal_expander(cfg::expand_cfg));
57 env.insert(intern("concat"),
58 builtin_normal_expander(concat::expand_syntax_ext));
59 env.insert(intern("concat_idents"),
60 builtin_normal_expander(concat_idents::expand_syntax_ext));
61 env.insert(intern("env"),
62 builtin_normal_expander(env::expand_env));
63 env.insert(intern("option_env"),
64 builtin_normal_expander(env::expand_option_env));
65 env.insert(intern("format_args"),
66 // format_args uses `unstable` things internally.
67 NormalTT(Box::new(format::expand_format_args), None, true));
68 env.insert(intern("log_syntax"),
69 builtin_normal_expander(log_syntax::expand_syntax_ext));
70 env.insert(intern("trace_macros"),
71 builtin_normal_expander(trace_macros::expand_trace_macros));
72
73 deriving::register_all(env);
74 }