]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_ext/lib.rs
Auto merge of #30401 - DiamondLovesYou:pnacl-target, r=alexcrichton
[rust.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 #![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/")]
19
20 #![cfg_attr(stage0, feature(custom_attribute))]
21 #![cfg_attr(stage0, staged_api)]
22 #![unstable(feature = "rustc_private", issue = "27812")]
23
24 #![feature(rustc_private)]
25 #![feature(staged_api)]
26 #![feature(str_char)]
27
28 extern crate fmt_macros;
29 extern crate syntax;
30
31 use syntax::ext::base::{MacroExpanderFn, NormalTT};
32 use syntax::ext::base::{SyntaxEnv, SyntaxExtension};
33 use syntax::parse::token::intern;
34
35 // A variant of 'try!' that panics on Err(FatalError). This is used as a
36 // crutch on the way towards a non-panic!-prone parser. It should be used
37 // for fatal parsing errors; eventually we plan to convert all code using
38 // panictry to just use normal try
39 macro_rules! panictry {
40     ($e:expr) => ({
41         use std::result::Result::{Ok, Err};
42         use syntax::errors::FatalError;
43         match $e {
44             Ok(e) => e,
45             Err(FatalError) => panic!(FatalError)
46         }
47     })
48 }
49
50 mod asm;
51 mod cfg;
52 mod concat;
53 mod concat_idents;
54 mod env;
55 mod format;
56 mod log_syntax;
57 mod trace_macros;
58
59 // for custom_derive
60 pub mod deriving;
61
62 pub fn register_builtins(env: &mut SyntaxEnv) {
63     // utility function to simplify creating NormalTT syntax extensions
64     fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
65         NormalTT(Box::new(f), None, false)
66     }
67
68     env.insert(intern("asm"),
69                builtin_normal_expander(asm::expand_asm));
70     env.insert(intern("cfg"),
71                builtin_normal_expander(cfg::expand_cfg));
72     env.insert(intern("concat"),
73                builtin_normal_expander(concat::expand_syntax_ext));
74     env.insert(intern("concat_idents"),
75                builtin_normal_expander(concat_idents::expand_syntax_ext));
76     env.insert(intern("env"),
77                builtin_normal_expander(env::expand_env));
78     env.insert(intern("option_env"),
79                builtin_normal_expander(env::expand_option_env));
80     env.insert(intern("format_args"),
81                // format_args uses `unstable` things internally.
82                NormalTT(Box::new(format::expand_format_args), None, true));
83     env.insert(intern("log_syntax"),
84                builtin_normal_expander(log_syntax::expand_syntax_ext));
85     env.insert(intern("trace_macros"),
86                builtin_normal_expander(trace_macros::expand_trace_macros));
87
88     deriving::register_all(env);
89 }