2013-02-28 07:15:32 -06:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-06-09 15:12:30 -05:00
|
|
|
//! The Rust parser and macro expander.
|
|
|
|
//!
|
|
|
|
//! # Note
|
|
|
|
//!
|
|
|
|
//! This API is completely unstable and subject to change.
|
2013-03-29 14:51:10 -05:00
|
|
|
|
2015-08-09 16:15:05 -05:00
|
|
|
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
2015-05-15 18:04:01 -05:00
|
|
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
2015-11-03 10:34:11 -06:00
|
|
|
html_root_url = "https://doc.rust-lang.org/nightly/",
|
|
|
|
test(attr(deny(warnings))))]
|
2014-03-21 20:05:05 -05:00
|
|
|
|
2018-04-06 07:23:00 -05:00
|
|
|
#![feature(unicode_internals)]
|
2016-06-28 12:40:40 -05:00
|
|
|
#![feature(rustc_diagnostic_macros)]
|
2018-03-30 04:54:14 -05:00
|
|
|
#![feature(slice_sort_by_cached_key)]
|
2017-12-03 07:03:28 -06:00
|
|
|
#![feature(const_atomic_usize_new)]
|
2018-01-24 00:20:30 -06:00
|
|
|
#![feature(rustc_attrs)]
|
2018-05-01 20:50:21 -05:00
|
|
|
#![feature(str_escape)]
|
2018-05-31 17:53:30 -05:00
|
|
|
#![feature(crate_visibility_modifier)]
|
2014-01-09 07:05:33 -06:00
|
|
|
|
2018-03-02 23:24:49 -06:00
|
|
|
#![recursion_limit="256"]
|
|
|
|
|
2017-09-08 14:08:01 -05:00
|
|
|
#[macro_use] extern crate bitflags;
|
2018-04-05 10:20:08 -05:00
|
|
|
extern crate core;
|
2014-07-01 11:39:41 -05:00
|
|
|
extern crate serialize;
|
2015-01-06 11:24:46 -06:00
|
|
|
#[macro_use] extern crate log;
|
2016-06-24 18:10:15 -05:00
|
|
|
pub extern crate rustc_errors as errors;
|
2016-06-21 17:08:13 -05:00
|
|
|
extern crate syntax_pos;
|
2016-11-02 23:33:35 -05:00
|
|
|
extern crate rustc_data_structures;
|
2018-04-25 11:30:39 -05:00
|
|
|
extern crate rustc_target;
|
2018-03-06 19:44:10 -06:00
|
|
|
#[macro_use] extern crate scoped_tls;
|
2014-12-31 22:43:46 -06:00
|
|
|
|
2016-08-22 19:56:52 -05:00
|
|
|
extern crate serialize as rustc_serialize; // used by deriving
|
2016-06-24 18:10:15 -05:00
|
|
|
|
2018-03-06 19:44:10 -06:00
|
|
|
use rustc_data_structures::sync::Lock;
|
|
|
|
|
2015-12-20 15:00:43 -06:00
|
|
|
// A variant of 'try!' that panics on an Err. This is used as a crutch on the
|
|
|
|
// way towards a non-panic!-prone parser. It should be used for fatal parsing
|
|
|
|
// errors; eventually we plan to convert all code using panictry to just use
|
|
|
|
// normal try.
|
|
|
|
// Exported for syntax_ext, not meant for general use.
|
|
|
|
#[macro_export]
|
2015-03-28 16:58:51 -05:00
|
|
|
macro_rules! panictry {
|
|
|
|
($e:expr) => ({
|
|
|
|
use std::result::Result::{Ok, Err};
|
2016-06-21 17:08:13 -05:00
|
|
|
use errors::FatalError;
|
2015-03-28 16:58:51 -05:00
|
|
|
match $e {
|
|
|
|
Ok(e) => e,
|
2015-12-20 15:00:43 -06:00
|
|
|
Err(mut e) => {
|
|
|
|
e.emit();
|
2018-01-21 05:47:58 -06:00
|
|
|
FatalError.raise()
|
2015-12-20 15:00:43 -06:00
|
|
|
}
|
2015-03-28 16:58:51 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-03 03:23:59 -06:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! unwrap_or {
|
|
|
|
($opt:expr, $default:expr) => {
|
|
|
|
match $opt {
|
|
|
|
Some(x) => x,
|
|
|
|
None => $default,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 17:49:52 -05:00
|
|
|
pub struct Globals {
|
2018-03-06 19:44:10 -06:00
|
|
|
used_attrs: Lock<Vec<u64>>,
|
|
|
|
known_attrs: Lock<Vec<u64>>,
|
|
|
|
syntax_pos_globals: syntax_pos::Globals,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Globals {
|
|
|
|
fn new() -> Globals {
|
|
|
|
Globals {
|
|
|
|
used_attrs: Lock::new(Vec::new()),
|
|
|
|
known_attrs: Lock::new(Vec::new()),
|
|
|
|
syntax_pos_globals: syntax_pos::Globals::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_globals<F, R>(f: F) -> R
|
|
|
|
where F: FnOnce() -> R
|
|
|
|
{
|
|
|
|
let globals = Globals::new();
|
|
|
|
GLOBALS.set(&globals, || {
|
|
|
|
syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-25 17:49:52 -05:00
|
|
|
scoped_thread_local!(pub static GLOBALS: Globals);
|
2018-03-06 19:44:10 -06:00
|
|
|
|
2016-06-28 12:40:40 -05:00
|
|
|
#[macro_use]
|
|
|
|
pub mod diagnostics {
|
|
|
|
#[macro_use]
|
|
|
|
pub mod macros;
|
|
|
|
pub mod plugin;
|
|
|
|
pub mod metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: This module needs to be declared first so diagnostics are
|
|
|
|
// registered before they are used.
|
|
|
|
pub mod diagnostic_list;
|
|
|
|
|
2013-04-03 11:41:40 -05:00
|
|
|
pub mod util {
|
2015-11-25 17:21:38 -06:00
|
|
|
pub mod lev_distance;
|
2015-11-10 23:26:14 -06:00
|
|
|
pub mod node_count;
|
|
|
|
pub mod parser;
|
2013-05-16 19:41:47 -05:00
|
|
|
#[cfg(test)]
|
|
|
|
pub mod parser_testing;
|
2013-11-24 23:18:21 -06:00
|
|
|
pub mod small_vector;
|
2015-11-15 14:19:53 -06:00
|
|
|
pub mod move_map;
|
2016-06-17 23:01:57 -05:00
|
|
|
|
|
|
|
mod thin_vec;
|
|
|
|
pub use self::thin_vec::ThinVec;
|
2017-01-17 21:27:09 -06:00
|
|
|
|
|
|
|
mod rc_slice;
|
|
|
|
pub use self::rc_slice::RcSlice;
|
2013-04-03 11:41:40 -05:00
|
|
|
}
|
|
|
|
|
2016-06-21 17:08:13 -05:00
|
|
|
pub mod json;
|
2015-12-13 16:17:55 -06:00
|
|
|
|
2012-12-13 15:05:22 -06:00
|
|
|
pub mod syntax {
|
|
|
|
pub use ext;
|
|
|
|
pub use parse;
|
2014-05-28 22:19:05 -05:00
|
|
|
pub use ast;
|
2012-12-13 15:05:22 -06:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub mod ast;
|
2014-07-01 11:39:41 -05:00
|
|
|
pub mod attr;
|
|
|
|
pub mod codemap;
|
2016-09-07 17:24:01 -05:00
|
|
|
#[macro_use]
|
2014-07-24 21:44:24 -05:00
|
|
|
pub mod config;
|
2015-08-23 13:12:39 -05:00
|
|
|
pub mod entry;
|
2014-09-10 19:55:42 -05:00
|
|
|
pub mod feature_gate;
|
2013-01-29 16:41:40 -06:00
|
|
|
pub mod fold;
|
|
|
|
pub mod parse;
|
2014-05-17 16:46:40 -05:00
|
|
|
pub mod ptr;
|
2014-07-24 21:44:24 -05:00
|
|
|
pub mod show_span;
|
2014-09-10 17:35:21 -05:00
|
|
|
pub mod std_inject;
|
2015-04-21 12:19:53 -05:00
|
|
|
pub mod str;
|
2018-04-22 17:44:19 -05:00
|
|
|
pub use syntax_pos::edition;
|
2017-03-16 23:04:41 -05:00
|
|
|
pub use syntax_pos::symbol;
|
2014-07-24 21:44:24 -05:00
|
|
|
pub mod test;
|
2016-06-20 10:49:33 -05:00
|
|
|
pub mod tokenstream;
|
2014-07-01 11:39:41 -05:00
|
|
|
pub mod visit;
|
2013-01-29 16:41:40 -06:00
|
|
|
|
|
|
|
pub mod print {
|
|
|
|
pub mod pp;
|
|
|
|
pub mod pprust;
|
2012-03-29 15:48:05 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub mod ext {
|
2017-03-16 05:23:33 -05:00
|
|
|
pub use syntax_pos::hygiene;
|
2013-01-29 16:41:40 -06:00
|
|
|
pub mod base;
|
2014-07-01 11:39:41 -05:00
|
|
|
pub mod build;
|
2017-02-01 04:33:09 -06:00
|
|
|
pub mod derive;
|
2013-01-29 16:41:40 -06:00
|
|
|
pub mod expand;
|
2016-08-29 00:32:41 -05:00
|
|
|
pub mod placeholders;
|
2013-01-29 16:41:40 -06:00
|
|
|
pub mod quote;
|
2014-07-01 11:39:41 -05:00
|
|
|
pub mod source_util;
|
2013-01-29 16:41:40 -06:00
|
|
|
|
|
|
|
pub mod tt {
|
|
|
|
pub mod transcribe;
|
|
|
|
pub mod macro_parser;
|
|
|
|
pub mod macro_rules;
|
2017-01-29 02:38:44 -06:00
|
|
|
pub mod quoted;
|
2012-06-27 17:29:35 -05:00
|
|
|
}
|
2012-03-29 15:48:05 -05:00
|
|
|
}
|
2016-06-28 12:40:40 -05:00
|
|
|
|
2016-10-23 19:22:06 -05:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test_snippet;
|
|
|
|
|
2017-07-31 01:22:09 -05:00
|
|
|
__build_diagnostic_array! { libsyntax, DIAGNOSTICS }
|