]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
Move ParseSess to librustc_session
[rust.git] / src / libsyntax / lib.rs
1 //! The Rust parser and macro expander.
2 //!
3 //! # Note
4 //!
5 //! This API is completely unstable and subject to change.
6
7 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
8        test(attr(deny(warnings))))]
9
10 #![feature(box_syntax)]
11 #![feature(const_fn)]
12 #![feature(const_transmute)]
13 #![feature(crate_visibility_modifier)]
14 #![feature(label_break_value)]
15 #![feature(matches_macro)]
16 #![feature(nll)]
17 #![feature(try_trait)]
18 #![feature(slice_patterns)]
19 #![feature(unicode_internals)]
20
21 #![recursion_limit="256"]
22
23 pub use errors;
24 use rustc_data_structures::sync::Lock;
25 use rustc_index::bit_set::GrowableBitSet;
26 pub use rustc_data_structures::thin_vec::ThinVec;
27 use ast::AttrId;
28 use syntax_pos::edition::Edition;
29
30 #[macro_export]
31 macro_rules! unwrap_or {
32     ($opt:expr, $default:expr) => {
33         match $opt {
34             Some(x) => x,
35             None => $default,
36         }
37     }
38 }
39
40 pub struct Globals {
41     used_attrs: Lock<GrowableBitSet<AttrId>>,
42     known_attrs: Lock<GrowableBitSet<AttrId>>,
43     syntax_pos_globals: syntax_pos::Globals,
44 }
45
46 impl Globals {
47     fn new(edition: Edition) -> Globals {
48         Globals {
49             // We have no idea how many attributes there will be, so just
50             // initiate the vectors with 0 bits. We'll grow them as necessary.
51             used_attrs: Lock::new(GrowableBitSet::new_empty()),
52             known_attrs: Lock::new(GrowableBitSet::new_empty()),
53             syntax_pos_globals: syntax_pos::Globals::new(edition),
54         }
55     }
56 }
57
58 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
59     where F: FnOnce() -> R
60 {
61     let globals = Globals::new(edition);
62     GLOBALS.set(&globals, || {
63         syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
64     })
65 }
66
67 pub fn with_default_globals<F, R>(f: F) -> R
68     where F: FnOnce() -> R
69 {
70     with_globals(edition::DEFAULT_EDITION, f)
71 }
72
73 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
74
75 #[macro_use]
76 pub mod diagnostics {
77     #[macro_use]
78     pub mod macros;
79 }
80
81 pub mod util {
82     pub mod classify;
83     pub mod comments;
84     pub mod lev_distance;
85     pub mod literal;
86     pub mod node_count;
87     pub mod parser;
88     pub mod map_in_place;
89 }
90
91 pub mod ast;
92 pub mod attr;
93 pub mod expand;
94 pub use syntax_pos::source_map;
95 pub mod entry;
96 pub mod feature_gate {
97     mod check;
98     pub use check::{check_crate, check_attribute, get_features, feature_err, feature_err_issue};
99 }
100 pub mod mut_visit;
101 pub mod ptr;
102 pub mod show_span;
103 pub use syntax_pos::edition;
104 pub use syntax_pos::symbol;
105 pub use rustc_session::parse as sess;
106 pub mod token;
107 pub mod tokenstream;
108 pub mod visit;
109
110 pub mod print {
111     pub mod pp;
112     pub mod pprust;
113     mod helpers;
114 }
115
116 pub mod early_buffered_lints;
117
118 /// Requirements for a `StableHashingContext` to be used in this crate.
119 /// This is a hack to allow using the `HashStable_Generic` derive macro
120 /// instead of implementing everything in librustc.
121 pub trait HashStableContext: syntax_pos::HashStableContext {}