Alex Crichton | 1fd0e8a | 2018-02-04 21:29:13 -0800 | [diff] [blame] | 1 | //! A "shim crate" intended to multiplex the [`proc_macro`] API on to stable |
| 2 | //! Rust. |
Alex Crichton | babc99e | 2017-07-05 18:00:29 -0700 | [diff] [blame] | 3 | //! |
| 4 | //! Procedural macros in Rust operate over the upstream |
Alex Crichton | 1fd0e8a | 2018-02-04 21:29:13 -0800 | [diff] [blame] | 5 | //! [`proc_macro::TokenStream`][ts] type. This type currently is quite |
| 6 | //! conservative and exposed no internal implementation details. Nightly |
| 7 | //! compilers, however, contain a much richer interface. This richer interface |
| 8 | //! allows fine-grained inspection of the token stream which avoids |
| 9 | //! stringification/re-lexing and also preserves span information. |
Alex Crichton | babc99e | 2017-07-05 18:00:29 -0700 | [diff] [blame] | 10 | //! |
Alex Crichton | 1fd0e8a | 2018-02-04 21:29:13 -0800 | [diff] [blame] | 11 | //! The upcoming APIs added to [`proc_macro`] upstream are the foundation for |
Alex Crichton | babc99e | 2017-07-05 18:00:29 -0700 | [diff] [blame] | 12 | //! productive procedural macros in the ecosystem. To help prepare the ecosystem |
| 13 | //! for using them this crate serves to both compile on stable and nightly and |
| 14 | //! mirrors the API-to-be. The intention is that procedural macros which switch |
| 15 | //! to use this crate will be trivially able to switch to the upstream |
| 16 | //! `proc_macro` crate once its API stabilizes. |
| 17 | //! |
David Tolnay | d66ecf6 | 2018-01-02 20:05:42 -0800 | [diff] [blame] | 18 | //! In the meantime this crate also has a `nightly` Cargo feature which |
Alex Crichton | 1fd0e8a | 2018-02-04 21:29:13 -0800 | [diff] [blame] | 19 | //! enables it to reimplement itself with the unstable API of [`proc_macro`]. |
Alex Crichton | babc99e | 2017-07-05 18:00:29 -0700 | [diff] [blame] | 20 | //! This'll allow immediate usage of the beneficial upstream API, particularly |
| 21 | //! around preserving span information. |
Alex Crichton | 1fd0e8a | 2018-02-04 21:29:13 -0800 | [diff] [blame] | 22 | //! |
| 23 | //! [`proc_macro`]: https://doc.rust-lang.org/proc_macro/ |
| 24 | //! [ts]: https://doc.rust-lang.org/proc_macro/struct.TokenStream.html |
Alex Crichton | babc99e | 2017-07-05 18:00:29 -0700 | [diff] [blame] | 25 | |
David Tolnay | 15cc498 | 2018-01-08 08:03:27 -0800 | [diff] [blame] | 26 | // Proc-macro2 types in rustdoc of other crates get linked to here. |
David Tolnay | eca28d4 | 2018-01-21 21:17:28 -0800 | [diff] [blame] | 27 | #![doc(html_root_url = "https://docs.rs/proc-macro2/0.2.2")] |
David Tolnay | 15cc498 | 2018-01-08 08:03:27 -0800 | [diff] [blame] | 28 | |
David Tolnay | d66ecf6 | 2018-01-02 20:05:42 -0800 | [diff] [blame] | 29 | #![cfg_attr(feature = "nightly", feature(proc_macro))] |
Alex Crichton | cbec8ec | 2017-06-02 13:19:33 -0700 | [diff] [blame] | 30 | |
Alex Crichton | 0e8e7f4 | 2018-02-22 06:15:13 -0800 | [diff] [blame^] | 31 | #[cfg(feature = "proc-macro")] |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 32 | extern crate proc_macro; |
| 33 | |
David Tolnay | d66ecf6 | 2018-01-02 20:05:42 -0800 | [diff] [blame] | 34 | #[cfg(not(feature = "nightly"))] |
David Tolnay | b103266 | 2017-05-31 15:52:28 -0700 | [diff] [blame] | 35 | extern crate unicode_xid; |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 36 | |
| 37 | use std::fmt; |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 38 | use std::str::FromStr; |
| 39 | use std::iter::FromIterator; |
| 40 | |
David Tolnay | b103266 | 2017-05-31 15:52:28 -0700 | [diff] [blame] | 41 | #[macro_use] |
David Tolnay | d66ecf6 | 2018-01-02 20:05:42 -0800 | [diff] [blame] | 42 | #[cfg(not(feature = "nightly"))] |
David Tolnay | b103266 | 2017-05-31 15:52:28 -0700 | [diff] [blame] | 43 | mod strnom; |
| 44 | |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 45 | #[path = "stable.rs"] |
David Tolnay | d66ecf6 | 2018-01-02 20:05:42 -0800 | [diff] [blame] | 46 | #[cfg(not(feature = "nightly"))] |
Alex Crichton | b15c635 | 2017-05-19 19:36:36 -0700 | [diff] [blame] | 47 | mod imp; |
| 48 | #[path = "unstable.rs"] |
David Tolnay | d66ecf6 | 2018-01-02 20:05:42 -0800 | [diff] [blame] | 49 | #[cfg(feature = "nightly")] |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 50 | mod imp; |
| 51 | |
David Tolnay | cb1b85f | 2017-06-03 16:40:35 -0700 | [diff] [blame] | 52 | #[macro_use] |
| 53 | mod macros; |
| 54 | |
| 55 | #[derive(Clone)] |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 56 | pub struct TokenStream(imp::TokenStream); |
| 57 | |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 58 | pub struct LexError(imp::LexError); |
| 59 | |
| 60 | impl FromStr for TokenStream { |
| 61 | type Err = LexError; |
| 62 | |
| 63 | fn from_str(src: &str) -> Result<TokenStream, LexError> { |
| 64 | match src.parse() { |
| 65 | Ok(e) => Ok(TokenStream(e)), |
| 66 | Err(e) => Err(LexError(e)), |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
Alex Crichton | 0e8e7f4 | 2018-02-22 06:15:13 -0800 | [diff] [blame^] | 71 | #[cfg(feature = "proc-macro")] |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 72 | impl From<proc_macro::TokenStream> for TokenStream { |
| 73 | fn from(inner: proc_macro::TokenStream) -> TokenStream { |
| 74 | TokenStream(inner.into()) |
| 75 | } |
| 76 | } |
| 77 | |
Alex Crichton | 0e8e7f4 | 2018-02-22 06:15:13 -0800 | [diff] [blame^] | 78 | #[cfg(feature = "proc-macro")] |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 79 | impl From<TokenStream> for proc_macro::TokenStream { |
| 80 | fn from(inner: TokenStream) -> proc_macro::TokenStream { |
| 81 | inner.0.into() |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | impl From<TokenTree> for TokenStream { |
| 86 | fn from(tree: TokenTree) -> TokenStream { |
| 87 | TokenStream(tree.into()) |
| 88 | } |
| 89 | } |
| 90 | |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 91 | impl<T: Into<TokenStream>> FromIterator<T> for TokenStream { |
| 92 | fn from_iter<I: IntoIterator<Item = T>>(streams: I) -> Self { |
| 93 | TokenStream(streams.into_iter().map(|t| t.into().0).collect()) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | impl IntoIterator for TokenStream { |
| 98 | type Item = TokenTree; |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 99 | type IntoIter = TokenTreeIter; |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 100 | |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 101 | fn into_iter(self) -> TokenTreeIter { |
| 102 | TokenTreeIter(self.0.into_iter()) |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | impl TokenStream { |
| 107 | pub fn empty() -> TokenStream { |
| 108 | TokenStream(imp::TokenStream::empty()) |
| 109 | } |
| 110 | |
| 111 | pub fn is_empty(&self) -> bool { |
| 112 | self.0.is_empty() |
| 113 | } |
| 114 | } |
| 115 | |
Nika Layzell | b35a9a3 | 2017-12-30 14:34:35 -0500 | [diff] [blame] | 116 | // Returned by reference, so we can't easily wrap it. |
David Tolnay | 1ebe397 | 2018-01-02 20:14:20 -0800 | [diff] [blame] | 117 | #[cfg(procmacro2_semver_exempt)] |
Nika Layzell | b35a9a3 | 2017-12-30 14:34:35 -0500 | [diff] [blame] | 118 | pub use imp::FileName; |
| 119 | |
David Tolnay | 1ebe397 | 2018-01-02 20:14:20 -0800 | [diff] [blame] | 120 | #[cfg(procmacro2_semver_exempt)] |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 121 | #[derive(Clone, PartialEq, Eq)] |
| 122 | pub struct SourceFile(imp::SourceFile); |
| 123 | |
David Tolnay | 1ebe397 | 2018-01-02 20:14:20 -0800 | [diff] [blame] | 124 | #[cfg(procmacro2_semver_exempt)] |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 125 | impl SourceFile { |
| 126 | /// Get the path to this source file as a string. |
Nika Layzell | b35a9a3 | 2017-12-30 14:34:35 -0500 | [diff] [blame] | 127 | pub fn path(&self) -> &FileName { |
| 128 | self.0.path() |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | pub fn is_real(&self) -> bool { |
| 132 | self.0.is_real() |
| 133 | } |
| 134 | } |
| 135 | |
David Tolnay | 1ebe397 | 2018-01-02 20:14:20 -0800 | [diff] [blame] | 136 | #[cfg(procmacro2_semver_exempt)] |
Nika Layzell | b35a9a3 | 2017-12-30 14:34:35 -0500 | [diff] [blame] | 137 | impl AsRef<FileName> for SourceFile { |
| 138 | fn as_ref(&self) -> &FileName { |
| 139 | self.0.path() |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
David Tolnay | 1ebe397 | 2018-01-02 20:14:20 -0800 | [diff] [blame] | 143 | #[cfg(procmacro2_semver_exempt)] |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 144 | impl fmt::Debug for SourceFile { |
| 145 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 146 | self.0.fmt(f) |
| 147 | } |
| 148 | } |
| 149 | |
David Tolnay | 1ebe397 | 2018-01-02 20:14:20 -0800 | [diff] [blame] | 150 | #[cfg(procmacro2_semver_exempt)] |
Nika Layzell | 1ecb6ce | 2017-12-30 14:34:05 -0500 | [diff] [blame] | 151 | pub struct LineColumn { |
| 152 | pub line: usize, |
| 153 | pub column: usize, |
| 154 | } |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 155 | |
David Tolnay | cb1b85f | 2017-06-03 16:40:35 -0700 | [diff] [blame] | 156 | #[derive(Copy, Clone)] |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 157 | pub struct Span(imp::Span); |
| 158 | |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 159 | impl Span { |
| 160 | pub fn call_site() -> Span { |
| 161 | Span(imp::Span::call_site()) |
| 162 | } |
Alex Crichton | e6085b7 | 2017-11-21 07:24:25 -0800 | [diff] [blame] | 163 | |
| 164 | pub fn def_site() -> Span { |
| 165 | Span(imp::Span::def_site()) |
| 166 | } |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 167 | |
David Tolnay | 4e8e397 | 2018-01-05 18:10:22 -0800 | [diff] [blame] | 168 | /// Creates a new span with the same line/column information as `self` but |
| 169 | /// that resolves symbols as though it were at `other`. |
| 170 | pub fn resolved_at(&self, other: Span) -> Span { |
| 171 | Span(self.0.resolved_at(other.0)) |
| 172 | } |
| 173 | |
| 174 | /// Creates a new span with the same name resolution behavior as `self` but |
| 175 | /// with the line/column information of `other`. |
| 176 | pub fn located_at(&self, other: Span) -> Span { |
| 177 | Span(self.0.located_at(other.0)) |
| 178 | } |
| 179 | |
David Tolnay | d66ecf6 | 2018-01-02 20:05:42 -0800 | [diff] [blame] | 180 | /// This method is only available when the `"nightly"` feature is enabled. |
Alex Crichton | 0e8e7f4 | 2018-02-22 06:15:13 -0800 | [diff] [blame^] | 181 | #[cfg(all(feature = "nightly", feature = "proc-macro"))] |
David Tolnay | 16a1720 | 2017-12-31 10:47:24 -0500 | [diff] [blame] | 182 | pub fn unstable(self) -> proc_macro::Span { |
| 183 | self.0.unstable() |
| 184 | } |
| 185 | |
David Tolnay | 1ebe397 | 2018-01-02 20:14:20 -0800 | [diff] [blame] | 186 | #[cfg(procmacro2_semver_exempt)] |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 187 | pub fn source_file(&self) -> SourceFile { |
| 188 | SourceFile(self.0.source_file()) |
| 189 | } |
| 190 | |
David Tolnay | 1ebe397 | 2018-01-02 20:14:20 -0800 | [diff] [blame] | 191 | #[cfg(procmacro2_semver_exempt)] |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 192 | pub fn start(&self) -> LineColumn { |
Nika Layzell | 1ecb6ce | 2017-12-30 14:34:05 -0500 | [diff] [blame] | 193 | let imp::LineColumn{ line, column } = self.0.start(); |
David Tolnay | 79105e5 | 2017-12-31 11:03:04 -0500 | [diff] [blame] | 194 | LineColumn { line: line, column: column } |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 195 | } |
| 196 | |
David Tolnay | 1ebe397 | 2018-01-02 20:14:20 -0800 | [diff] [blame] | 197 | #[cfg(procmacro2_semver_exempt)] |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 198 | pub fn end(&self) -> LineColumn { |
Nika Layzell | 1ecb6ce | 2017-12-30 14:34:05 -0500 | [diff] [blame] | 199 | let imp::LineColumn{ line, column } = self.0.end(); |
David Tolnay | 79105e5 | 2017-12-31 11:03:04 -0500 | [diff] [blame] | 200 | LineColumn { line: line, column: column } |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 201 | } |
| 202 | |
David Tolnay | 1ebe397 | 2018-01-02 20:14:20 -0800 | [diff] [blame] | 203 | #[cfg(procmacro2_semver_exempt)] |
Nika Layzell | f8d5f21 | 2017-12-11 14:07:02 -0500 | [diff] [blame] | 204 | pub fn join(&self, other: Span) -> Option<Span> { |
| 205 | self.0.join(other.0).map(Span) |
| 206 | } |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 207 | } |
| 208 | |
David Tolnay | 977f828 | 2017-05-31 17:41:33 -0700 | [diff] [blame] | 209 | #[derive(Clone, Debug)] |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 210 | pub struct TokenTree { |
| 211 | pub span: Span, |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 212 | pub kind: TokenNode, |
| 213 | } |
| 214 | |
| 215 | impl From<TokenNode> for TokenTree { |
| 216 | fn from(kind: TokenNode) -> TokenTree { |
David Tolnay | 1ce3a79 | 2018-01-07 12:21:03 -0800 | [diff] [blame] | 217 | TokenTree { span: Span::def_site(), kind: kind } |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 218 | } |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 221 | impl fmt::Display for TokenTree { |
| 222 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 223 | TokenStream::from(self.clone()).fmt(f) |
| 224 | } |
| 225 | } |
| 226 | |
David Tolnay | 977f828 | 2017-05-31 17:41:33 -0700 | [diff] [blame] | 227 | #[derive(Clone, Debug)] |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 228 | pub enum TokenNode { |
| 229 | Group(Delimiter, TokenStream), |
| 230 | Term(Term), |
| 231 | Op(char, Spacing), |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 232 | Literal(Literal), |
| 233 | } |
| 234 | |
Michael Layzell | 5372f4b | 2017-06-02 10:29:31 -0400 | [diff] [blame] | 235 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 236 | pub enum Delimiter { |
| 237 | Parenthesis, |
| 238 | Brace, |
| 239 | Bracket, |
| 240 | None, |
| 241 | } |
| 242 | |
David Tolnay | cb1b85f | 2017-06-03 16:40:35 -0700 | [diff] [blame] | 243 | #[derive(Copy, Clone)] |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 244 | pub struct Term(imp::Term); |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 245 | |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 246 | impl Term { |
| 247 | pub fn intern(string: &str) -> Term { |
David Tolnay | 10effeb | 2018-01-06 11:07:49 -0800 | [diff] [blame] | 248 | Term(imp::Term::intern(string)) |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 249 | } |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 250 | |
Alex Crichton | 4388125 | 2017-05-26 08:51:06 -0700 | [diff] [blame] | 251 | pub fn as_str(&self) -> &str { |
David Tolnay | 10effeb | 2018-01-06 11:07:49 -0800 | [diff] [blame] | 252 | self.0.as_str() |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
Lukas Kalbertodt | eb3f930 | 2017-08-20 18:58:41 +0200 | [diff] [blame] | 256 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 257 | pub enum Spacing { |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 258 | Alone, |
| 259 | Joint, |
| 260 | } |
| 261 | |
David Tolnay | cb1b85f | 2017-06-03 16:40:35 -0700 | [diff] [blame] | 262 | #[derive(Clone)] |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 263 | pub struct Literal(imp::Literal); |
| 264 | |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 265 | macro_rules! int_literals { |
| 266 | ($($kind:ident,)*) => ($( |
| 267 | pub fn $kind(n: $kind) -> Literal { |
| 268 | Literal(n.into()) |
| 269 | } |
| 270 | )*) |
| 271 | } |
| 272 | |
Alex Crichton | 852d53d | 2017-05-19 19:25:08 -0700 | [diff] [blame] | 273 | impl Literal { |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 274 | pub fn integer(s: i64) -> Literal { |
| 275 | Literal(imp::Literal::integer(s)) |
| 276 | } |
| 277 | |
| 278 | int_literals! { |
Alex Crichton | 1a16c78 | 2017-07-05 18:06:36 -0700 | [diff] [blame] | 279 | u8, u16, u32, u64, usize, |
| 280 | i8, i16, i32, i64, isize, |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | pub fn float(f: f64) -> Literal { |
| 284 | Literal(imp::Literal::float(f)) |
| 285 | } |
| 286 | |
| 287 | pub fn f64(f: f64) -> Literal { |
| 288 | Literal(f.into()) |
| 289 | } |
| 290 | |
| 291 | pub fn f32(f: f32) -> Literal { |
| 292 | Literal(f.into()) |
| 293 | } |
| 294 | |
| 295 | pub fn string(string: &str) -> Literal { |
| 296 | Literal(string.into()) |
| 297 | } |
| 298 | |
| 299 | pub fn character(ch: char) -> Literal { |
| 300 | Literal(ch.into()) |
Alex Crichton | 76a5cc8 | 2017-05-23 07:01:44 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Alex Crichton | 9c2fb0a | 2017-05-26 08:49:31 -0700 | [diff] [blame] | 303 | pub fn byte_string(s: &[u8]) -> Literal { |
| 304 | Literal(imp::Literal::byte_string(s)) |
Alex Crichton | 852d53d | 2017-05-19 19:25:08 -0700 | [diff] [blame] | 305 | } |
Alex Crichton | 76a5cc8 | 2017-05-23 07:01:44 -0700 | [diff] [blame] | 306 | |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 307 | // ======================================================================= |
| 308 | // Not present upstream in proc_macro yet |
| 309 | |
| 310 | pub fn byte_char(b: u8) -> Literal { |
| 311 | Literal(imp::Literal::byte_char(b)) |
| 312 | } |
| 313 | |
Alex Crichton | 76a5cc8 | 2017-05-23 07:01:44 -0700 | [diff] [blame] | 314 | pub fn doccomment(s: &str) -> Literal { |
| 315 | Literal(imp::Literal::doccomment(s)) |
| 316 | } |
Alex Crichton | 9c2fb0a | 2017-05-26 08:49:31 -0700 | [diff] [blame] | 317 | |
Alex Crichton | 3131662 | 2017-05-26 12:54:47 -0700 | [diff] [blame] | 318 | pub fn raw_string(s: &str, pounds: usize) -> Literal { |
| 319 | Literal(imp::Literal::raw_string(s, pounds)) |
| 320 | } |
| 321 | |
| 322 | pub fn raw_byte_string(s: &str, pounds: usize) -> Literal { |
| 323 | Literal(imp::Literal::raw_byte_string(s, pounds)) |
| 324 | } |
Alex Crichton | 852d53d | 2017-05-19 19:25:08 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 327 | pub struct TokenTreeIter(imp::TokenTreeIter); |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 328 | |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 329 | impl Iterator for TokenTreeIter { |
Alex Crichton | 44bffbc | 2017-05-19 17:51:59 -0700 | [diff] [blame] | 330 | type Item = TokenTree; |
| 331 | |
| 332 | fn next(&mut self) -> Option<TokenTree> { |
| 333 | self.0.next() |
| 334 | } |
| 335 | } |
David Tolnay | cb1b85f | 2017-06-03 16:40:35 -0700 | [diff] [blame] | 336 | |
| 337 | forward_fmt!(Debug for LexError); |
| 338 | forward_fmt!(Debug for Literal); |
| 339 | forward_fmt!(Debug for Span); |
Alex Crichton | 1a7f762 | 2017-07-05 17:47:15 -0700 | [diff] [blame] | 340 | forward_fmt!(Debug for Term); |
| 341 | forward_fmt!(Debug for TokenTreeIter); |
David Tolnay | cb1b85f | 2017-06-03 16:40:35 -0700 | [diff] [blame] | 342 | forward_fmt!(Debug for TokenStream); |
| 343 | forward_fmt!(Display for Literal); |
| 344 | forward_fmt!(Display for TokenStream); |