]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_ext/lib.rs
Fix invalid associated type rendering in rustdoc
[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 extern crate log;
28 #[macro_use]
29 extern crate syntax;
30 extern crate syntax_pos;
31 extern crate proc_macro;
32 extern crate rustc_errors as errors;
33
34 mod asm;
35 mod cfg;
36 mod concat;
37 mod concat_idents;
38 mod env;
39 mod format;
40 mod format_foreign;
41 mod log_syntax;
42 mod trace_macros;
43
44 pub mod proc_macro_registrar;
45
46 // for custom_derive
47 pub mod deriving;
48
49 pub mod proc_macro_impl;
50
51 use std::rc::Rc;
52 use syntax::ast;
53 use syntax::ext::base::{MacroExpanderFn, NormalTT, NamedSyntaxExtension};
54 use syntax::symbol::Symbol;
55
56 pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver,
57                          user_exts: Vec<NamedSyntaxExtension>,
58                          enable_quotes: bool) {
59     deriving::register_builtin_derives(resolver);
60
61     let mut register = |name, ext| {
62         resolver.add_builtin(ast::Ident::with_empty_ctxt(name), Rc::new(ext));
63     };
64
65     macro_rules! register {
66         ($( $name:ident: $f:expr, )*) => { $(
67             register(Symbol::intern(stringify!($name)),
68                      NormalTT(Box::new($f as MacroExpanderFn), None, false));
69         )* }
70     }
71
72     if enable_quotes {
73         use syntax::ext::quote::*;
74         register! {
75             quote_tokens: expand_quote_tokens,
76             quote_expr: expand_quote_expr,
77             quote_ty: expand_quote_ty,
78             quote_item: expand_quote_item,
79             quote_pat: expand_quote_pat,
80             quote_arm: expand_quote_arm,
81             quote_stmt: expand_quote_stmt,
82             quote_attr: expand_quote_attr,
83             quote_arg: expand_quote_arg,
84             quote_block: expand_quote_block,
85             quote_meta_item: expand_quote_meta_item,
86             quote_path: expand_quote_path,
87         }
88     }
89
90     use syntax::ext::source_util::*;
91     register! {
92         line: expand_line,
93         column: expand_column,
94         file: expand_file,
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,
100
101         asm: asm::expand_asm,
102         cfg: cfg::expand_cfg,
103         concat: concat::expand_syntax_ext,
104         concat_idents: concat_idents::expand_syntax_ext,
105         env: env::expand_env,
106         option_env: env::expand_option_env,
107         log_syntax: log_syntax::expand_syntax_ext,
108         trace_macros: trace_macros::expand_trace_macros,
109     }
110
111     // format_args uses `unstable` things internally.
112     register(Symbol::intern("format_args"),
113              NormalTT(Box::new(format::expand_format_args), None, true));
114
115     for (name, ext) in user_exts {
116         register(name, ext);
117     }
118 }