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.
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.
11 //! The Rust parser and macro expander.
15 //! This API is completely unstable and subject to change.
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))))]
22 #![feature(crate_visibility_modifier)]
23 #![feature(macro_at_most_once_rep)]
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)]
33 #![recursion_limit="256"]
35 #[macro_use] extern crate bitflags;
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;
45 extern crate smallvec;
47 extern crate serialize as rustc_serialize; // used by deriving
49 use rustc_data_structures::sync::Lock;
50 use rustc_data_structures::bit_set::GrowableBitSet;
51 pub use rustc_data_structures::thin_vec::ThinVec;
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
58 // Exported for syntax_ext, not meant for general use.
60 macro_rules! panictry {
62 use std::result::Result::{Ok, Err};
63 use errors::FatalError;
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};
83 DiagnosticBuilder::new_diagnostic($handler, e).emit();
92 macro_rules! unwrap_or {
93 ($opt:expr, $default:expr) => {
102 used_attrs: Lock<GrowableBitSet<AttrId>>,
103 known_attrs: Lock<GrowableBitSet<AttrId>>,
104 syntax_pos_globals: syntax_pos::Globals,
108 fn new() -> 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(),
119 pub fn with_globals<F, R>(f: F) -> R
120 where F: FnOnce() -> R
122 let globals = Globals::new();
123 GLOBALS.set(&globals, || {
124 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
128 scoped_thread_local!(pub static GLOBALS: Globals);
131 pub mod diagnostics {
138 // NB: This module needs to be declared first so diagnostics are
139 // registered before they are used.
140 pub mod diagnostic_list;
143 pub mod lev_distance;
147 pub mod parser_testing;
151 pub use self::rc_slice::RcSlice;
154 pub use self::rc_vec::RcVec;
171 pub mod feature_gate;
178 pub use syntax_pos::edition;
179 pub use syntax_pos::symbol;
190 pub use syntax_pos::hygiene;
195 pub mod placeholders;
201 pub mod macro_parser;
207 pub mod early_buffered_lints;
212 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }