]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_ext/lib.rs
Auto merge of #38569 - chris-morgan:rustdoc-highlight-kw-2, r=steveklabnik
[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 #![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 #![deny(warnings)]
21
22 #![feature(proc_macro_internals)]
23 #![feature(rustc_private)]
24 #![feature(staged_api)]
25
26 extern crate fmt_macros;
27 #[macro_use]
28 extern crate log;
29 #[macro_use]
30 extern crate syntax;
31 extern crate syntax_pos;
32 extern crate proc_macro;
33 extern crate rustc_errors as errors;
34
35 mod asm;
36 mod cfg;
37 mod concat;
38 mod concat_idents;
39 mod env;
40 mod format;
41 mod format_foreign;
42 mod log_syntax;
43 mod trace_macros;
44
45 pub mod proc_macro_registrar;
46
47 // for custom_derive
48 pub mod deriving;
49
50 use std::rc::Rc;
51 use syntax::ast;
52 use syntax::ext::base::{MacroExpanderFn, NormalTT, MultiModifier, NamedSyntaxExtension};
53 use syntax::symbol::Symbol;
54
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));
60     };
61
62     macro_rules! register {
63         ($( $name:ident: $f:expr, )*) => { $(
64             register(Symbol::intern(stringify!($name)),
65                      NormalTT(Box::new($f as MacroExpanderFn), None, false));
66         )* }
67     }
68
69     if enable_quotes {
70         use syntax::ext::quote::*;
71         register! {
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,
85         }
86     }
87
88     use syntax::ext::source_util::*;
89     register! {
90         line: expand_line,
91         column: expand_column,
92         file: expand_file,
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,
98
99         asm: asm::expand_asm,
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,
107     }
108
109     // format_args uses `unstable` things internally.
110     register(Symbol::intern("format_args"),
111              NormalTT(Box::new(format::expand_format_args), None, true));
112
113     register(Symbol::intern("derive"), MultiModifier(Box::new(deriving::expand_derive)));
114
115     for (name, ext) in user_exts {
116         register(name, ext);
117     }
118 }