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