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)]
24 #![feature(rustc_attrs)]
25 #![feature(rustc_diagnostic_macros)]
26 #![feature(slice_sort_by_cached_key)]
27 #![feature(str_escape)]
28 #![feature(step_trait)]
29 #![feature(try_trait)]
30 #![feature(unicode_internals)]
32 #![recursion_limit="256"]
34 #[macro_use] extern crate bitflags;
36 extern crate serialize;
37 #[macro_use] extern crate log;
38 pub extern crate rustc_errors as errors;
39 extern crate syntax_pos;
40 #[macro_use] extern crate rustc_data_structures;
41 extern crate rustc_target;
42 #[macro_use] extern crate scoped_tls;
44 extern crate smallvec;
46 extern crate serialize as rustc_serialize; // used by deriving
48 use rustc_data_structures::sync::Lock;
49 use rustc_data_structures::bit_set::GrowableBitSet;
50 pub use rustc_data_structures::thin_vec::ThinVec;
53 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
54 // way towards a non-panic!-prone parser. It should be used for fatal parsing
55 // errors; eventually we plan to convert all code using panictry to just use
57 // Exported for syntax_ext, not meant for general use.
59 macro_rules! panictry {
61 use std::result::Result::{Ok, Err};
62 use errors::FatalError;
73 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
74 macro_rules! panictry_buffer {
75 ($handler:expr, $e:expr) => ({
76 use std::result::Result::{Ok, Err};
77 use errors::{FatalError, DiagnosticBuilder};
82 DiagnosticBuilder::new_diagnostic($handler, e).emit();
91 macro_rules! unwrap_or {
92 ($opt:expr, $default:expr) => {
101 used_attrs: Lock<GrowableBitSet<AttrId>>,
102 known_attrs: Lock<GrowableBitSet<AttrId>>,
103 syntax_pos_globals: syntax_pos::Globals,
107 fn new() -> Globals {
109 // We have no idea how many attributes their will be, so just
110 // initiate the vectors with 0 bits. We'll grow them as necessary.
111 used_attrs: Lock::new(GrowableBitSet::new_empty()),
112 known_attrs: Lock::new(GrowableBitSet::new_empty()),
113 syntax_pos_globals: syntax_pos::Globals::new(),
118 pub fn with_globals<F, R>(f: F) -> R
119 where F: FnOnce() -> R
121 let globals = Globals::new();
122 GLOBALS.set(&globals, || {
123 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
127 scoped_thread_local!(pub static GLOBALS: Globals);
130 pub mod diagnostics {
137 // NB: This module needs to be declared first so diagnostics are
138 // registered before they are used.
139 pub mod diagnostic_list;
142 pub mod lev_distance;
146 pub mod parser_testing;
150 pub use self::rc_slice::RcSlice;
153 pub use self::rc_vec::RcVec;
170 pub mod feature_gate;
176 pub use syntax_pos::edition;
177 pub use syntax_pos::symbol;
188 pub use syntax_pos::hygiene;
193 pub mod placeholders;
199 pub mod macro_parser;
205 pub mod early_buffered_lints;
210 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }