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(const_atomic_usize_new)]
23 #![feature(crate_visibility_modifier)]
24 #![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(unicode_internals)]
31 #![recursion_limit="256"]
33 #[macro_use] extern crate bitflags;
35 extern crate serialize;
36 #[macro_use] extern crate log;
37 pub extern crate rustc_errors as errors;
38 extern crate syntax_pos;
39 extern crate rustc_data_structures;
40 extern crate rustc_target;
41 #[macro_use] extern crate scoped_tls;
43 extern crate serialize as rustc_serialize; // used by deriving
45 use rustc_data_structures::sync::Lock;
47 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
48 // way towards a non-panic!-prone parser. It should be used for fatal parsing
49 // errors; eventually we plan to convert all code using panictry to just use
51 // Exported for syntax_ext, not meant for general use.
53 macro_rules! panictry {
55 use std::result::Result::{Ok, Err};
56 use errors::FatalError;
68 macro_rules! unwrap_or {
69 ($opt:expr, $default:expr) => {
78 used_attrs: Lock<Vec<u64>>,
79 known_attrs: Lock<Vec<u64>>,
80 syntax_pos_globals: syntax_pos::Globals,
86 used_attrs: Lock::new(Vec::new()),
87 known_attrs: Lock::new(Vec::new()),
88 syntax_pos_globals: syntax_pos::Globals::new(),
93 pub fn with_globals<F, R>(f: F) -> R
94 where F: FnOnce() -> R
96 let globals = Globals::new();
97 GLOBALS.set(&globals, || {
98 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
102 scoped_thread_local!(pub static GLOBALS: Globals);
105 pub mod diagnostics {
112 // NB: This module needs to be declared first so diagnostics are
113 // registered before they are used.
114 pub mod diagnostic_list;
117 pub mod lev_distance;
121 pub mod parser_testing;
122 pub mod small_vector;
126 pub use self::thin_vec::ThinVec;
129 pub use self::rc_slice::RcSlice;
146 pub mod feature_gate;
153 pub use syntax_pos::edition;
154 pub use syntax_pos::symbol;
165 pub use syntax_pos::hygiene;
170 pub mod placeholders;
176 pub mod macro_parser;
182 pub mod early_buffered_lints;
187 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }