1 //! The Rust parser and macro expander.
5 //! This API is completely unstable and subject to change.
7 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
8 test(attr(deny(warnings))))]
10 #![feature(bind_by_move_pattern_guards)]
11 #![feature(box_syntax)]
13 #![feature(const_transmute)]
14 #![feature(crate_visibility_modifier)]
15 #![feature(label_break_value)]
18 #![feature(proc_macro_diagnostic)]
19 #![feature(proc_macro_internals)]
20 #![feature(proc_macro_span)]
21 #![feature(rustc_diagnostic_macros)]
22 #![feature(try_trait)]
23 #![feature(unicode_internals)]
25 #![recursion_limit="256"]
27 extern crate proc_macro;
30 use rustc_data_structures::sync::Lock;
31 use rustc_data_structures::bit_set::GrowableBitSet;
32 pub use rustc_data_structures::thin_vec::ThinVec;
34 use syntax_pos::edition::Edition;
36 const MACRO_ARGUMENTS: Option<&'static str> = Some("macro arguments");
38 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
39 // way towards a non-panic!-prone parser. It should be used for fatal parsing
40 // errors; eventually we plan to convert all code using panictry to just use
43 macro_rules! panictry {
45 use std::result::Result::{Ok, Err};
46 use errors::FatalError;
57 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
58 macro_rules! panictry_buffer {
59 ($handler:expr, $e:expr) => ({
60 use std::result::Result::{Ok, Err};
61 use errors::{FatalError, DiagnosticBuilder};
66 DiagnosticBuilder::new_diagnostic($handler, e).emit();
75 macro_rules! unwrap_or {
76 ($opt:expr, $default:expr) => {
85 used_attrs: Lock<GrowableBitSet<AttrId>>,
86 known_attrs: Lock<GrowableBitSet<AttrId>>,
87 syntax_pos_globals: syntax_pos::Globals,
91 fn new(edition: Edition) -> Globals {
93 // We have no idea how many attributes their will be, so just
94 // initiate the vectors with 0 bits. We'll grow them as necessary.
95 used_attrs: Lock::new(GrowableBitSet::new_empty()),
96 known_attrs: Lock::new(GrowableBitSet::new_empty()),
97 syntax_pos_globals: syntax_pos::Globals::new(edition),
102 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
103 where F: FnOnce() -> R
105 let globals = Globals::new(edition);
106 GLOBALS.set(&globals, || {
107 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
111 pub fn with_default_globals<F, R>(f: F) -> R
112 where F: FnOnce() -> R
114 with_globals(edition::DEFAULT_EDITION, f)
117 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
120 pub mod diagnostics {
127 // N.B., this module needs to be declared first so diagnostics are
128 // registered before they are used.
132 pub mod lev_distance;
136 pub mod parser_testing;
137 pub mod map_in_place;
148 pub mod feature_gate;
153 pub use syntax_pos::edition;
154 pub use syntax_pos::symbol;
166 mod proc_macro_server;
168 pub use syntax_pos::hygiene;
178 pub mod macro_parser;
184 pub mod early_buffered_lints;
189 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }