1 //! The Rust parser and macro expander.
5 //! This API is completely unstable and subject to change.
7 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
8 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
9 html_root_url = "https://doc.rust-lang.org/nightly/",
10 test(attr(deny(warnings))))]
12 #![feature(crate_visibility_modifier)]
13 #![feature(label_break_value)]
15 #![feature(rustc_attrs)]
16 #![feature(rustc_diagnostic_macros)]
17 #![feature(slice_sort_by_cached_key)]
18 #![feature(str_escape)]
19 #![feature(step_trait)]
20 #![feature(try_trait)]
21 #![feature(unicode_internals)]
23 #![recursion_limit="256"]
25 #[macro_use] extern crate bitflags;
27 extern crate serialize;
28 #[macro_use] extern crate log;
29 pub extern crate rustc_errors as errors;
30 extern crate syntax_pos;
31 #[macro_use] extern crate rustc_data_structures;
32 extern crate rustc_target;
33 #[macro_use] extern crate scoped_tls;
35 extern crate smallvec;
37 extern crate serialize as rustc_serialize; // used by deriving
39 use rustc_data_structures::sync::Lock;
40 use rustc_data_structures::bit_set::GrowableBitSet;
41 pub use rustc_data_structures::thin_vec::ThinVec;
44 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
45 // way towards a non-panic!-prone parser. It should be used for fatal parsing
46 // errors; eventually we plan to convert all code using panictry to just use
48 macro_rules! panictry {
50 use std::result::Result::{Ok, Err};
51 use errors::FatalError;
62 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
63 macro_rules! panictry_buffer {
64 ($handler:expr, $e:expr) => ({
65 use std::result::Result::{Ok, Err};
66 use errors::{FatalError, DiagnosticBuilder};
71 DiagnosticBuilder::new_diagnostic($handler, e).emit();
80 macro_rules! unwrap_or {
81 ($opt:expr, $default:expr) => {
90 used_attrs: Lock<GrowableBitSet<AttrId>>,
91 known_attrs: Lock<GrowableBitSet<AttrId>>,
92 syntax_pos_globals: syntax_pos::Globals,
98 // We have no idea how many attributes their will be, so just
99 // initiate the vectors with 0 bits. We'll grow them as necessary.
100 used_attrs: Lock::new(GrowableBitSet::new_empty()),
101 known_attrs: Lock::new(GrowableBitSet::new_empty()),
102 syntax_pos_globals: syntax_pos::Globals::new(),
107 pub fn with_globals<F, R>(f: F) -> R
108 where F: FnOnce() -> R
110 let globals = Globals::new();
111 GLOBALS.set(&globals, || {
112 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
116 scoped_thread_local!(pub static GLOBALS: Globals);
119 pub mod diagnostics {
126 // N.B., this module needs to be declared first so diagnostics are
127 // registered before they are used.
128 pub mod diagnostic_list;
131 pub mod lev_distance;
135 pub mod parser_testing;
153 pub mod feature_gate;
159 pub use syntax_pos::edition;
160 pub use syntax_pos::symbol;
171 pub use syntax_pos::hygiene;
176 pub mod placeholders;
181 pub mod macro_parser;
187 pub mod early_buffered_lints;
192 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }