]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
Auto merge of #53256 - ollie27:writeln, r=KodrAus
[rust.git] / src / libsyntax / lib.rs
1 // Copyright 2012-2013 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 //! The Rust parser and macro expander.
12 //!
13 //! # Note
14 //!
15 //! This API is completely unstable and subject to change.
16
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        test(attr(deny(warnings))))]
21
22 #![feature(crate_visibility_modifier)]
23 #![feature(macro_at_most_once_rep)]
24 #![cfg_attr(not(stage0), feature(nll))]
25 #![feature(rustc_attrs)]
26 #![feature(rustc_diagnostic_macros)]
27 #![feature(slice_sort_by_cached_key)]
28 #![feature(str_escape)]
29 #![feature(unicode_internals)]
30 #![feature(catch_expr)]
31
32 #![recursion_limit="256"]
33
34 #[macro_use] extern crate bitflags;
35 extern crate core;
36 extern crate serialize;
37 #[macro_use] extern crate log;
38 pub extern crate rustc_errors as errors;
39 extern crate syntax_pos;
40 extern crate rustc_data_structures;
41 extern crate rustc_target;
42 #[macro_use] extern crate scoped_tls;
43
44 extern crate serialize as rustc_serialize; // used by deriving
45
46 use rustc_data_structures::sync::Lock;
47 use rustc_data_structures::bitvec::BitVector;
48 pub use rustc_data_structures::small_vec::OneVector;
49 pub use rustc_data_structures::thin_vec::ThinVec;
50 use ast::AttrId;
51
52 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
53 // way towards a non-panic!-prone parser. It should be used for fatal parsing
54 // errors; eventually we plan to convert all code using panictry to just use
55 // normal try.
56 // Exported for syntax_ext, not meant for general use.
57 #[macro_export]
58 macro_rules! panictry {
59     ($e:expr) => ({
60         use std::result::Result::{Ok, Err};
61         use errors::FatalError;
62         match $e {
63             Ok(e) => e,
64             Err(mut e) => {
65                 e.emit();
66                 FatalError.raise()
67             }
68         }
69     })
70 }
71
72 #[macro_export]
73 macro_rules! unwrap_or {
74     ($opt:expr, $default:expr) => {
75         match $opt {
76             Some(x) => x,
77             None => $default,
78         }
79     }
80 }
81
82 pub struct Globals {
83     used_attrs: Lock<BitVector<AttrId>>,
84     known_attrs: Lock<BitVector<AttrId>>,
85     syntax_pos_globals: syntax_pos::Globals,
86 }
87
88 impl Globals {
89     fn new() -> Globals {
90         Globals {
91             // We have no idea how many attributes their will be, so just
92             // initiate the vectors with 0 bits. We'll grow them as necessary.
93             used_attrs: Lock::new(BitVector::new()),
94             known_attrs: Lock::new(BitVector::new()),
95             syntax_pos_globals: syntax_pos::Globals::new(),
96         }
97     }
98 }
99
100 pub fn with_globals<F, R>(f: F) -> R
101     where F: FnOnce() -> R
102 {
103     let globals = Globals::new();
104     GLOBALS.set(&globals, || {
105         syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
106     })
107 }
108
109 scoped_thread_local!(pub static GLOBALS: Globals);
110
111 #[macro_use]
112 pub mod diagnostics {
113     #[macro_use]
114     pub mod macros;
115     pub mod plugin;
116     pub mod metadata;
117 }
118
119 // NB: This module needs to be declared first so diagnostics are
120 // registered before they are used.
121 pub mod diagnostic_list;
122
123 pub mod util {
124     pub mod lev_distance;
125     pub mod node_count;
126     pub mod parser;
127     #[cfg(test)]
128     pub mod parser_testing;
129     pub mod move_map;
130
131     mod rc_slice;
132     pub use self::rc_slice::RcSlice;
133 }
134
135 pub mod json;
136
137 pub mod syntax {
138     pub use ext;
139     pub use parse;
140     pub use ast;
141 }
142
143 pub mod ast;
144 pub mod attr;
145 pub mod codemap;
146 #[macro_use]
147 pub mod config;
148 pub mod entry;
149 pub mod feature_gate;
150 pub mod fold;
151 pub mod parse;
152 pub mod ptr;
153 pub mod show_span;
154 pub mod std_inject;
155 pub mod str;
156 pub use syntax_pos::edition;
157 pub use syntax_pos::symbol;
158 pub mod test;
159 pub mod tokenstream;
160 pub mod visit;
161
162 pub mod print {
163     pub mod pp;
164     pub mod pprust;
165 }
166
167 pub mod ext {
168     pub use syntax_pos::hygiene;
169     pub mod base;
170     pub mod build;
171     pub mod derive;
172     pub mod expand;
173     pub mod placeholders;
174     pub mod quote;
175     pub mod source_util;
176
177     pub mod tt {
178         pub mod transcribe;
179         pub mod macro_parser;
180         pub mod macro_rules;
181         pub mod quoted;
182     }
183 }
184
185 pub mod early_buffered_lints;
186
187 #[cfg(test)]
188 mod test_snippet;
189
190 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }