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/")]
20 #![unstable(feature = "rustc_private", issue = "27812")]
22 #![feature(rustc_private)]
23 #![feature(staged_api)]
26 extern crate fmt_macros;
29 use syntax::ext::base::{MacroExpanderFn, NormalTT};
30 use syntax::ext::base::{SyntaxEnv, SyntaxExtension};
31 use syntax::parse::token::intern;
33 // A variant of 'try!' that panics on Err(FatalError). This is used as a
34 // crutch on the way towards a non-panic!-prone parser. It should be used
35 // for fatal parsing errors; eventually we plan to convert all code using
36 // panictry to just use normal try
37 macro_rules! panictry {
39 use std::result::Result::{Ok, Err};
40 use syntax::errors::FatalError;
43 Err(FatalError) => panic!(FatalError)
60 pub fn register_builtins(env: &mut SyntaxEnv) {
61 // utility function to simplify creating NormalTT syntax extensions
62 fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
63 NormalTT(Box::new(f), None, false)
66 env.insert(intern("asm"),
67 builtin_normal_expander(asm::expand_asm));
68 env.insert(intern("cfg"),
69 builtin_normal_expander(cfg::expand_cfg));
70 env.insert(intern("concat"),
71 builtin_normal_expander(concat::expand_syntax_ext));
72 env.insert(intern("concat_idents"),
73 builtin_normal_expander(concat_idents::expand_syntax_ext));
74 env.insert(intern("env"),
75 builtin_normal_expander(env::expand_env));
76 env.insert(intern("option_env"),
77 builtin_normal_expander(env::expand_option_env));
78 env.insert(intern("format_args"),
79 // format_args uses `unstable` things internally.
80 NormalTT(Box::new(format::expand_format_args), None, true));
81 env.insert(intern("log_syntax"),
82 builtin_normal_expander(log_syntax::expand_syntax_ext));
83 env.insert(intern("trace_macros"),
84 builtin_normal_expander(trace_macros::expand_trace_macros));
86 deriving::register_all(env);