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)]
24 #![cfg_attr(not(stage0), feature(nll))]
25 #![feature(rustc_attrs)]
26 #![feature(rustc_diagnostic_macros)]
27 #![feature(slice_sort_by_cached_key)]
28 #![feature(str_escape)]
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 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::bitvec::BitVector;
50 pub use rustc_data_structures::small_vec::OneVector;
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;
75 macro_rules! unwrap_or {
76 ($opt:expr, $default:expr) => {
85 used_attrs: Lock<BitVector<AttrId>>,
86 known_attrs: Lock<BitVector<AttrId>>,
87 syntax_pos_globals: syntax_pos::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(BitVector::new()),
96 known_attrs: Lock::new(BitVector::new()),
97 syntax_pos_globals: syntax_pos::Globals::new(),
102 pub fn with_globals<F, R>(f: F) -> R
103 where F: FnOnce() -> R
105 let globals = Globals::new();
106 GLOBALS.set(&globals, || {
107 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
111 scoped_thread_local!(pub static GLOBALS: Globals);
114 pub mod diagnostics {
121 // NB: This module needs to be declared first so diagnostics are
122 // registered before they are used.
123 pub mod diagnostic_list;
126 pub mod lev_distance;
130 pub mod parser_testing;
134 pub use self::rc_slice::RcSlice;
137 pub use self::rc_vec::RcVec;
154 pub mod feature_gate;
161 pub use syntax_pos::edition;
162 pub use syntax_pos::symbol;
173 pub use syntax_pos::hygiene;
178 pub mod placeholders;
184 pub mod macro_parser;
190 pub mod early_buffered_lints;
195 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }