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 #![deny(rust_2018_idioms)]
13 #![feature(crate_visibility_modifier)]
14 #![feature(label_break_value)]
16 #![feature(rustc_attrs)]
17 #![feature(rustc_diagnostic_macros)]
18 #![feature(step_trait)]
19 #![feature(try_trait)]
20 #![feature(unicode_internals)]
22 #![recursion_limit="256"]
24 #[allow(unused_extern_crates)]
25 extern crate serialize as rustc_serialize; // used by deriving
28 use rustc_data_structures::sync::Lock;
29 use rustc_data_structures::bit_set::GrowableBitSet;
30 pub use rustc_data_structures::thin_vec::ThinVec;
32 use syntax_pos::edition::Edition;
34 const MACRO_ARGUMENTS: Option<&'static str> = Some("macro arguments");
36 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
37 // way towards a non-panic!-prone parser. It should be used for fatal parsing
38 // errors; eventually we plan to convert all code using panictry to just use
40 macro_rules! panictry {
42 use std::result::Result::{Ok, Err};
43 use errors::FatalError;
54 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
55 macro_rules! panictry_buffer {
56 ($handler:expr, $e:expr) => ({
57 use std::result::Result::{Ok, Err};
58 use errors::{FatalError, DiagnosticBuilder};
63 DiagnosticBuilder::new_diagnostic($handler, e).emit();
72 macro_rules! unwrap_or {
73 ($opt:expr, $default:expr) => {
82 used_attrs: Lock<GrowableBitSet<AttrId>>,
83 known_attrs: Lock<GrowableBitSet<AttrId>>,
84 syntax_pos_globals: syntax_pos::Globals,
88 fn new(edition: Edition) -> Globals {
90 // We have no idea how many attributes their will be, so just
91 // initiate the vectors with 0 bits. We'll grow them as necessary.
92 used_attrs: Lock::new(GrowableBitSet::new_empty()),
93 known_attrs: Lock::new(GrowableBitSet::new_empty()),
94 syntax_pos_globals: syntax_pos::Globals::new(edition),
99 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
100 where F: FnOnce() -> R
102 let globals = Globals::new(edition);
103 GLOBALS.set(&globals, || {
104 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
108 pub fn with_default_globals<F, R>(f: F) -> R
109 where F: FnOnce() -> R
111 with_globals(edition::DEFAULT_EDITION, f)
114 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
117 pub mod diagnostics {
124 // N.B., this module needs to be declared first so diagnostics are
125 // registered before they are used.
129 pub mod lev_distance;
133 pub mod parser_testing;
134 pub mod map_in_place;
141 pub use crate::parse;
151 pub mod feature_gate;
157 pub use syntax_pos::edition;
158 pub use syntax_pos::symbol;
169 pub use syntax_pos::hygiene;
174 pub mod placeholders;
179 pub mod macro_parser;
185 pub mod early_buffered_lints;
190 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }