blob: f49318ce7adf3e532e9eb855f9b5ed078b5a569e [file] [log] [blame]
David Tolnay3b1f7d22019-01-28 12:22:11 -08001#[cfg(span_locations)]
Alex Crichton44bffbc2017-05-19 17:51:59 -07002use std::cell::RefCell;
David Tolnay1ebe3972018-01-02 20:14:20 -08003#[cfg(procmacro2_semver_exempt)]
Nika Layzellf8d5f212017-12-11 14:07:02 -05004use std::cmp;
Alex Crichton44bffbc2017-05-19 17:51:59 -07005use std::fmt;
6use std::iter;
David Tolnay9cd3b4c2018-11-11 16:47:32 -08007#[cfg(procmacro2_semver_exempt)]
8use std::path::Path;
9use std::path::PathBuf;
Alex Crichton44bffbc2017-05-19 17:51:59 -070010use std::str::FromStr;
11use std::vec;
12
David Tolnay0f884b12019-07-19 11:59:20 -070013use crate::strnom::{block_comment, skip_whitespace, whitespace, word_break, Cursor, PResult};
14use crate::{Delimiter, Punct, Spacing, TokenTree};
David Tolnayb1032662017-05-31 15:52:28 -070015use unicode_xid::UnicodeXID;
Alex Crichton44bffbc2017-05-19 17:51:59 -070016
David Tolnay034205f2018-04-22 16:45:28 -070017#[derive(Clone)]
Alex Crichton44bffbc2017-05-19 17:51:59 -070018pub struct TokenStream {
19 inner: Vec<TokenTree>,
20}
21
22#[derive(Debug)]
23pub struct LexError;
24
25impl TokenStream {
David Tolnayc3bb4592018-05-28 20:09:44 -070026 pub fn new() -> TokenStream {
Alex Crichton44bffbc2017-05-19 17:51:59 -070027 TokenStream { inner: Vec::new() }
28 }
29
30 pub fn is_empty(&self) -> bool {
31 self.inner.len() == 0
32 }
33}
34
David Tolnay3b1f7d22019-01-28 12:22:11 -080035#[cfg(span_locations)]
Nika Layzella9dbc182017-12-30 14:50:13 -050036fn get_cursor(src: &str) -> Cursor {
David Tolnay6c3b0702019-04-22 16:48:34 -070037 // Create a dummy file & add it to the source map
38 SOURCE_MAP.with(|cm| {
Nika Layzella9dbc182017-12-30 14:50:13 -050039 let mut cm = cm.borrow_mut();
40 let name = format!("<parsed string {}>", cm.files.len());
41 let span = cm.add_file(&name, src);
42 Cursor {
43 rest: src,
44 off: span.lo,
45 }
46 })
47}
48
David Tolnay3b1f7d22019-01-28 12:22:11 -080049#[cfg(not(span_locations))]
Nika Layzella9dbc182017-12-30 14:50:13 -050050fn get_cursor(src: &str) -> Cursor {
David Tolnayb28f38a2018-03-31 22:02:29 +020051 Cursor { rest: src }
Nika Layzella9dbc182017-12-30 14:50:13 -050052}
53
Alex Crichton44bffbc2017-05-19 17:51:59 -070054impl FromStr for TokenStream {
55 type Err = LexError;
56
57 fn from_str(src: &str) -> Result<TokenStream, LexError> {
David Tolnay6c3b0702019-04-22 16:48:34 -070058 // Create a dummy file & add it to the source map
Nika Layzella9dbc182017-12-30 14:50:13 -050059 let cursor = get_cursor(src);
Nika Layzellf8d5f212017-12-11 14:07:02 -050060
61 match token_stream(cursor) {
David Tolnay1218e122017-06-01 11:13:45 -070062 Ok((input, output)) => {
Alex Crichton44bffbc2017-05-19 17:51:59 -070063 if skip_whitespace(input).len() != 0 {
64 Err(LexError)
65 } else {
Alex Crichton30a4e9e2018-04-27 17:02:19 -070066 Ok(output)
Alex Crichton44bffbc2017-05-19 17:51:59 -070067 }
68 }
David Tolnay1218e122017-06-01 11:13:45 -070069 Err(LexError) => Err(LexError),
Alex Crichton44bffbc2017-05-19 17:51:59 -070070 }
71 }
72}
73
74impl fmt::Display for TokenStream {
75 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
76 let mut joint = false;
77 for (i, tt) in self.inner.iter().enumerate() {
78 if i != 0 && !joint {
79 write!(f, " ")?;
80 }
81 joint = false;
Alex Crichtonaf5bad42018-03-27 14:45:10 -070082 match *tt {
83 TokenTree::Group(ref tt) => {
84 let (start, end) = match tt.delimiter() {
Alex Crichton44bffbc2017-05-19 17:51:59 -070085 Delimiter::Parenthesis => ("(", ")"),
86 Delimiter::Brace => ("{", "}"),
87 Delimiter::Bracket => ("[", "]"),
88 Delimiter::None => ("", ""),
89 };
Alex Crichton30a4e9e2018-04-27 17:02:19 -070090 if tt.stream().into_iter().next().is_none() {
Alex Crichton852d53d2017-05-19 19:25:08 -070091 write!(f, "{} {}", start, end)?
92 } else {
Alex Crichtonaf5bad42018-03-27 14:45:10 -070093 write!(f, "{} {} {}", start, tt.stream(), end)?
Alex Crichton852d53d2017-05-19 19:25:08 -070094 }
Alex Crichton44bffbc2017-05-19 17:51:59 -070095 }
Alex Crichtonf3888432018-05-16 09:11:05 -070096 TokenTree::Ident(ref tt) => write!(f, "{}", tt)?,
97 TokenTree::Punct(ref tt) => {
98 write!(f, "{}", tt.as_char())?;
Alex Crichtonaf5bad42018-03-27 14:45:10 -070099 match tt.spacing() {
Alex Crichton1a7f7622017-07-05 17:47:15 -0700100 Spacing::Alone => {}
101 Spacing::Joint => joint = true,
Alex Crichton44bffbc2017-05-19 17:51:59 -0700102 }
103 }
Alex Crichtonb2c94622018-04-04 07:36:41 -0700104 TokenTree::Literal(ref tt) => write!(f, "{}", tt)?,
Alex Crichton44bffbc2017-05-19 17:51:59 -0700105 }
106 }
107
108 Ok(())
109 }
110}
111
David Tolnay034205f2018-04-22 16:45:28 -0700112impl fmt::Debug for TokenStream {
113 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
114 f.write_str("TokenStream ")?;
115 f.debug_list().entries(self.clone()).finish()
116 }
117}
118
Alex Crichton53548482018-08-11 21:54:05 -0700119#[cfg(use_proc_macro)]
David Tolnay0f884b12019-07-19 11:59:20 -0700120impl From<proc_macro::TokenStream> for TokenStream {
121 fn from(inner: proc_macro::TokenStream) -> TokenStream {
David Tolnayb28f38a2018-03-31 22:02:29 +0200122 inner
123 .to_string()
124 .parse()
125 .expect("compiler token stream parse failed")
Alex Crichton44bffbc2017-05-19 17:51:59 -0700126 }
127}
128
Alex Crichton53548482018-08-11 21:54:05 -0700129#[cfg(use_proc_macro)]
David Tolnay0f884b12019-07-19 11:59:20 -0700130impl From<TokenStream> for proc_macro::TokenStream {
131 fn from(inner: TokenStream) -> proc_macro::TokenStream {
David Tolnayb28f38a2018-03-31 22:02:29 +0200132 inner
133 .to_string()
134 .parse()
135 .expect("failed to parse to compiler tokens")
Alex Crichton44bffbc2017-05-19 17:51:59 -0700136 }
137}
138
Alex Crichton44bffbc2017-05-19 17:51:59 -0700139impl From<TokenTree> for TokenStream {
140 fn from(tree: TokenTree) -> TokenStream {
141 TokenStream { inner: vec![tree] }
142 }
143}
144
Alex Crichtonaf5bad42018-03-27 14:45:10 -0700145impl iter::FromIterator<TokenTree> for TokenStream {
David Tolnayb28f38a2018-03-31 22:02:29 +0200146 fn from_iter<I: IntoIterator<Item = TokenTree>>(streams: I) -> Self {
Alex Crichton44bffbc2017-05-19 17:51:59 -0700147 let mut v = Vec::new();
148
Alex Crichtonaf5bad42018-03-27 14:45:10 -0700149 for token in streams.into_iter() {
150 v.push(token);
Alex Crichton44bffbc2017-05-19 17:51:59 -0700151 }
152
153 TokenStream { inner: v }
154 }
155}
156
Alex Crichton53b00672018-09-06 17:16:10 -0700157impl iter::FromIterator<TokenStream> for TokenStream {
158 fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self {
159 let mut v = Vec::new();
160
161 for stream in streams.into_iter() {
162 v.extend(stream.inner);
163 }
164
165 TokenStream { inner: v }
166 }
167}
168
Alex Crichtonf3888432018-05-16 09:11:05 -0700169impl Extend<TokenTree> for TokenStream {
170 fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, streams: I) {
171 self.inner.extend(streams);
172 }
173}
174
David Tolnay5c58c532018-08-13 11:33:51 -0700175impl Extend<TokenStream> for TokenStream {
176 fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I) {
177 self.inner
178 .extend(streams.into_iter().flat_map(|stream| stream));
179 }
180}
181
Alex Crichton1a7f7622017-07-05 17:47:15 -0700182pub type TokenTreeIter = vec::IntoIter<TokenTree>;
Alex Crichton44bffbc2017-05-19 17:51:59 -0700183
184impl IntoIterator for TokenStream {
185 type Item = TokenTree;
Alex Crichton1a7f7622017-07-05 17:47:15 -0700186 type IntoIter = TokenTreeIter;
Alex Crichton44bffbc2017-05-19 17:51:59 -0700187
Alex Crichton1a7f7622017-07-05 17:47:15 -0700188 fn into_iter(self) -> TokenTreeIter {
Alex Crichton44bffbc2017-05-19 17:51:59 -0700189 self.inner.into_iter()
190 }
191}
192
Nika Layzellf8d5f212017-12-11 14:07:02 -0500193#[derive(Clone, PartialEq, Eq)]
194pub struct SourceFile {
David Tolnay9cd3b4c2018-11-11 16:47:32 -0800195 path: PathBuf,
Nika Layzellf8d5f212017-12-11 14:07:02 -0500196}
197
198impl SourceFile {
199 /// Get the path to this source file as a string.
David Tolnay9cd3b4c2018-11-11 16:47:32 -0800200 pub fn path(&self) -> PathBuf {
201 self.path.clone()
Nika Layzellf8d5f212017-12-11 14:07:02 -0500202 }
203
204 pub fn is_real(&self) -> bool {
205 // XXX(nika): Support real files in the future?
206 false
207 }
208}
209
Nika Layzellf8d5f212017-12-11 14:07:02 -0500210impl fmt::Debug for SourceFile {
211 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
212 f.debug_struct("SourceFile")
Nika Layzellb35a9a32017-12-30 14:34:35 -0500213 .field("path", &self.path())
Nika Layzellf8d5f212017-12-11 14:07:02 -0500214 .field("is_real", &self.is_real())
215 .finish()
216 }
217}
218
219#[derive(Clone, Copy, Debug, PartialEq, Eq)]
220pub struct LineColumn {
221 pub line: usize,
222 pub column: usize,
223}
224
David Tolnay3b1f7d22019-01-28 12:22:11 -0800225#[cfg(span_locations)]
Nika Layzellf8d5f212017-12-11 14:07:02 -0500226thread_local! {
David Tolnay6c3b0702019-04-22 16:48:34 -0700227 static SOURCE_MAP: RefCell<SourceMap> = RefCell::new(SourceMap {
Nika Layzellf8d5f212017-12-11 14:07:02 -0500228 // NOTE: We start with a single dummy file which all call_site() and
229 // def_site() spans reference.
David Tolnay3b1f7d22019-01-28 12:22:11 -0800230 files: vec![{
231 #[cfg(procmacro2_semver_exempt)]
232 {
233 FileInfo {
234 name: "<unspecified>".to_owned(),
235 span: Span { lo: 0, hi: 0 },
236 lines: vec![0],
237 }
238 }
239
240 #[cfg(not(procmacro2_semver_exempt))]
241 {
242 FileInfo {
243 span: Span { lo: 0, hi: 0 },
244 lines: vec![0],
245 }
246 }
Nika Layzellf8d5f212017-12-11 14:07:02 -0500247 }],
248 });
249}
250
David Tolnay3b1f7d22019-01-28 12:22:11 -0800251#[cfg(span_locations)]
Nika Layzellf8d5f212017-12-11 14:07:02 -0500252struct FileInfo {
David Tolnay3b1f7d22019-01-28 12:22:11 -0800253 #[cfg(procmacro2_semver_exempt)]
Nika Layzellf8d5f212017-12-11 14:07:02 -0500254 name: String,
255 span: Span,
256 lines: Vec<usize>,
257}
258
David Tolnay3b1f7d22019-01-28 12:22:11 -0800259#[cfg(span_locations)]
Nika Layzellf8d5f212017-12-11 14:07:02 -0500260impl FileInfo {
261 fn offset_line_column(&self, offset: usize) -> LineColumn {
David Tolnayb28f38a2018-03-31 22:02:29 +0200262 assert!(self.span_within(Span {
263 lo: offset as u32,
264 hi: offset as u32
265 }));
Nika Layzellf8d5f212017-12-11 14:07:02 -0500266 let offset = offset - self.span.lo as usize;
267 match self.lines.binary_search(&offset) {
268 Ok(found) => LineColumn {
269 line: found + 1,
David Tolnayb28f38a2018-03-31 22:02:29 +0200270 column: 0,
Nika Layzellf8d5f212017-12-11 14:07:02 -0500271 },
272 Err(idx) => LineColumn {
273 line: idx,
David Tolnayb28f38a2018-03-31 22:02:29 +0200274 column: offset - self.lines[idx - 1],
Nika Layzellf8d5f212017-12-11 14:07:02 -0500275 },
276 }
277 }
278
279 fn span_within(&self, span: Span) -> bool {
280 span.lo >= self.span.lo && span.hi <= self.span.hi
281 }
282}
283
Alex Crichtona914a612018-04-04 07:48:44 -0700284/// Computesthe offsets of each line in the given source string.
David Tolnay3b1f7d22019-01-28 12:22:11 -0800285#[cfg(span_locations)]
Nika Layzella0a7c3d2017-12-30 14:52:39 -0500286fn lines_offsets(s: &str) -> Vec<usize> {
Nika Layzellf8d5f212017-12-11 14:07:02 -0500287 let mut lines = vec![0];
288 let mut prev = 0;
Nika Layzella0a7c3d2017-12-30 14:52:39 -0500289 while let Some(len) = s[prev..].find('\n') {
Nika Layzellf8d5f212017-12-11 14:07:02 -0500290 prev += len + 1;
291 lines.push(prev);
292 }
293 lines
294}
295
David Tolnay3b1f7d22019-01-28 12:22:11 -0800296#[cfg(span_locations)]
David Tolnay6c3b0702019-04-22 16:48:34 -0700297struct SourceMap {
Nika Layzellf8d5f212017-12-11 14:07:02 -0500298 files: Vec<FileInfo>,
299}
300
David Tolnay3b1f7d22019-01-28 12:22:11 -0800301#[cfg(span_locations)]
David Tolnay6c3b0702019-04-22 16:48:34 -0700302impl SourceMap {
Nika Layzellf8d5f212017-12-11 14:07:02 -0500303 fn next_start_pos(&self) -> u32 {
304 // Add 1 so there's always space between files.
305 //
306 // We'll always have at least 1 file, as we initialize our files list
307 // with a dummy file.
308 self.files.last().unwrap().span.hi + 1
309 }
310
311 fn add_file(&mut self, name: &str, src: &str) -> Span {
Nika Layzella0a7c3d2017-12-30 14:52:39 -0500312 let lines = lines_offsets(src);
Nika Layzellf8d5f212017-12-11 14:07:02 -0500313 let lo = self.next_start_pos();
314 // XXX(nika): Shouild we bother doing a checked cast or checked add here?
David Tolnayb28f38a2018-03-31 22:02:29 +0200315 let span = Span {
David Tolnayf0814122019-07-19 11:53:55 -0700316 lo,
David Tolnayb28f38a2018-03-31 22:02:29 +0200317 hi: lo + (src.len() as u32),
318 };
Nika Layzellf8d5f212017-12-11 14:07:02 -0500319
David Tolnay3b1f7d22019-01-28 12:22:11 -0800320 #[cfg(procmacro2_semver_exempt)]
Nika Layzellf8d5f212017-12-11 14:07:02 -0500321 self.files.push(FileInfo {
322 name: name.to_owned(),
David Tolnayf0814122019-07-19 11:53:55 -0700323 span,
324 lines,
Nika Layzellf8d5f212017-12-11 14:07:02 -0500325 });
326
David Tolnay3b1f7d22019-01-28 12:22:11 -0800327 #[cfg(not(procmacro2_semver_exempt))]
David Tolnayf0814122019-07-19 11:53:55 -0700328 self.files.push(FileInfo { span, lines });
David Tolnay3b1f7d22019-01-28 12:22:11 -0800329 let _ = name;
330
Nika Layzellf8d5f212017-12-11 14:07:02 -0500331 span
332 }
333
334 fn fileinfo(&self, span: Span) -> &FileInfo {
335 for file in &self.files {
336 if file.span_within(span) {
337 return file;
338 }
339 }
340 panic!("Invalid span with no related FileInfo!");
341 }
342}
343
David Tolnay034205f2018-04-22 16:45:28 -0700344#[derive(Clone, Copy, PartialEq, Eq)]
David Tolnayddfca052017-12-31 10:41:24 -0500345pub struct Span {
David Tolnay3b1f7d22019-01-28 12:22:11 -0800346 #[cfg(span_locations)]
David Tolnayddfca052017-12-31 10:41:24 -0500347 lo: u32,
David Tolnay3b1f7d22019-01-28 12:22:11 -0800348 #[cfg(span_locations)]
David Tolnayddfca052017-12-31 10:41:24 -0500349 hi: u32,
350}
Alex Crichton44bffbc2017-05-19 17:51:59 -0700351
352impl Span {
David Tolnay3b1f7d22019-01-28 12:22:11 -0800353 #[cfg(not(span_locations))]
Alex Crichton44bffbc2017-05-19 17:51:59 -0700354 pub fn call_site() -> Span {
David Tolnay79105e52017-12-31 11:03:04 -0500355 Span {}
356 }
357
David Tolnay3b1f7d22019-01-28 12:22:11 -0800358 #[cfg(span_locations)]
David Tolnay79105e52017-12-31 11:03:04 -0500359 pub fn call_site() -> Span {
360 Span { lo: 0, hi: 0 }
Alex Crichton44bffbc2017-05-19 17:51:59 -0700361 }
Alex Crichtone6085b72017-11-21 07:24:25 -0800362
David Tolnay3b1f7d22019-01-28 12:22:11 -0800363 #[cfg(procmacro2_semver_exempt)]
Alex Crichtone6085b72017-11-21 07:24:25 -0800364 pub fn def_site() -> Span {
David Tolnay79105e52017-12-31 11:03:04 -0500365 Span::call_site()
Nika Layzellf8d5f212017-12-11 14:07:02 -0500366 }
367
David Tolnay3b1f7d22019-01-28 12:22:11 -0800368 #[cfg(procmacro2_semver_exempt)]
David Tolnay4e8e3972018-01-05 18:10:22 -0800369 pub fn resolved_at(&self, _other: Span) -> Span {
370 // Stable spans consist only of line/column information, so
371 // `resolved_at` and `located_at` only select which span the
372 // caller wants line/column information from.
373 *self
374 }
375
David Tolnay3b1f7d22019-01-28 12:22:11 -0800376 #[cfg(procmacro2_semver_exempt)]
David Tolnay4e8e3972018-01-05 18:10:22 -0800377 pub fn located_at(&self, other: Span) -> Span {
378 other
379 }
380
David Tolnay1ebe3972018-01-02 20:14:20 -0800381 #[cfg(procmacro2_semver_exempt)]
Nika Layzellf8d5f212017-12-11 14:07:02 -0500382 pub fn source_file(&self) -> SourceFile {
David Tolnay6c3b0702019-04-22 16:48:34 -0700383 SOURCE_MAP.with(|cm| {
Nika Layzellf8d5f212017-12-11 14:07:02 -0500384 let cm = cm.borrow();
385 let fi = cm.fileinfo(*self);
386 SourceFile {
David Tolnay9cd3b4c2018-11-11 16:47:32 -0800387 path: Path::new(&fi.name).to_owned(),
Nika Layzellf8d5f212017-12-11 14:07:02 -0500388 }
389 })
390 }
391
David Tolnay3b1f7d22019-01-28 12:22:11 -0800392 #[cfg(span_locations)]
Nika Layzellf8d5f212017-12-11 14:07:02 -0500393 pub fn start(&self) -> LineColumn {
David Tolnay6c3b0702019-04-22 16:48:34 -0700394 SOURCE_MAP.with(|cm| {
Nika Layzellf8d5f212017-12-11 14:07:02 -0500395 let cm = cm.borrow();
396 let fi = cm.fileinfo(*self);
397 fi.offset_line_column(self.lo as usize)
398 })
399 }
400
David Tolnay3b1f7d22019-01-28 12:22:11 -0800401 #[cfg(span_locations)]
Nika Layzellf8d5f212017-12-11 14:07:02 -0500402 pub fn end(&self) -> LineColumn {
David Tolnay6c3b0702019-04-22 16:48:34 -0700403 SOURCE_MAP.with(|cm| {
Nika Layzellf8d5f212017-12-11 14:07:02 -0500404 let cm = cm.borrow();
405 let fi = cm.fileinfo(*self);
406 fi.offset_line_column(self.hi as usize)
407 })
408 }
409
David Tolnay1ebe3972018-01-02 20:14:20 -0800410 #[cfg(procmacro2_semver_exempt)]
Nika Layzellf8d5f212017-12-11 14:07:02 -0500411 pub fn join(&self, other: Span) -> Option<Span> {
David Tolnay6c3b0702019-04-22 16:48:34 -0700412 SOURCE_MAP.with(|cm| {
Nika Layzellf8d5f212017-12-11 14:07:02 -0500413 let cm = cm.borrow();
414 // If `other` is not within the same FileInfo as us, return None.
415 if !cm.fileinfo(*self).span_within(other) {
416 return None;
417 }
418 Some(Span {
419 lo: cmp::min(self.lo, other.lo),
420 hi: cmp::max(self.hi, other.hi),
421 })
422 })
Alex Crichtone6085b72017-11-21 07:24:25 -0800423 }
Alex Crichton44bffbc2017-05-19 17:51:59 -0700424}
425
David Tolnay034205f2018-04-22 16:45:28 -0700426impl fmt::Debug for Span {
427 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
428 #[cfg(procmacro2_semver_exempt)]
429 return write!(f, "bytes({}..{})", self.lo, self.hi);
430
431 #[cfg(not(procmacro2_semver_exempt))]
432 write!(f, "Span")
433 }
434}
435
David Tolnayfd8cdc82019-01-19 19:23:59 -0800436pub fn debug_span_field_if_nontrivial(debug: &mut fmt::DebugStruct, span: Span) {
437 if cfg!(procmacro2_semver_exempt) {
438 debug.field("span", &span);
439 }
440}
441
Alex Crichtonf3888432018-05-16 09:11:05 -0700442#[derive(Clone)]
David Tolnayf14813f2018-09-08 17:14:07 -0700443pub struct Group {
444 delimiter: Delimiter,
445 stream: TokenStream,
446 span: Span,
447}
448
449impl Group {
450 pub fn new(delimiter: Delimiter, stream: TokenStream) -> Group {
451 Group {
David Tolnayf0814122019-07-19 11:53:55 -0700452 delimiter,
453 stream,
David Tolnayf14813f2018-09-08 17:14:07 -0700454 span: Span::call_site(),
455 }
456 }
457
458 pub fn delimiter(&self) -> Delimiter {
459 self.delimiter
460 }
461
462 pub fn stream(&self) -> TokenStream {
463 self.stream.clone()
464 }
465
466 pub fn span(&self) -> Span {
467 self.span
468 }
469
David Tolnay3b1f7d22019-01-28 12:22:11 -0800470 #[cfg(procmacro2_semver_exempt)]
David Tolnayf14813f2018-09-08 17:14:07 -0700471 pub fn span_open(&self) -> Span {
472 self.span
473 }
474
David Tolnay3b1f7d22019-01-28 12:22:11 -0800475 #[cfg(procmacro2_semver_exempt)]
David Tolnayf14813f2018-09-08 17:14:07 -0700476 pub fn span_close(&self) -> Span {
477 self.span
478 }
479
480 pub fn set_span(&mut self, span: Span) {
481 self.span = span;
482 }
483}
484
485impl fmt::Display for Group {
486 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
487 let (left, right) = match self.delimiter {
488 Delimiter::Parenthesis => ("(", ")"),
489 Delimiter::Brace => ("{", "}"),
490 Delimiter::Bracket => ("[", "]"),
491 Delimiter::None => ("", ""),
492 };
493
494 f.write_str(left)?;
495 self.stream.fmt(f)?;
496 f.write_str(right)?;
497
498 Ok(())
499 }
500}
501
502impl fmt::Debug for Group {
503 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
504 let mut debug = fmt.debug_struct("Group");
505 debug.field("delimiter", &self.delimiter);
506 debug.field("stream", &self.stream);
507 #[cfg(procmacro2_semver_exempt)]
508 debug.field("span", &self.span);
509 debug.finish()
510 }
511}
512
513#[derive(Clone)]
Alex Crichtonf3888432018-05-16 09:11:05 -0700514pub struct Ident {
David Tolnayc2309ca2018-06-02 15:47:57 -0700515 sym: String,
Alex Crichtonb2c94622018-04-04 07:36:41 -0700516 span: Span,
Alex Crichtonf3888432018-05-16 09:11:05 -0700517 raw: bool,
David Tolnay041bcd42017-06-03 09:18:04 -0700518}
Alex Crichton44bffbc2017-05-19 17:51:59 -0700519
Alex Crichtonf3888432018-05-16 09:11:05 -0700520impl Ident {
521 fn _new(string: &str, raw: bool, span: Span) -> Ident {
David Tolnay637eef42019-04-20 13:36:18 -0700522 validate_ident(string);
David Tolnay489c6422018-04-07 08:37:28 -0700523
Alex Crichtonf3888432018-05-16 09:11:05 -0700524 Ident {
David Tolnayc2309ca2018-06-02 15:47:57 -0700525 sym: string.to_owned(),
David Tolnayf0814122019-07-19 11:53:55 -0700526 span,
527 raw,
David Tolnay041bcd42017-06-03 09:18:04 -0700528 }
Alex Crichton44bffbc2017-05-19 17:51:59 -0700529 }
Alex Crichton44bffbc2017-05-19 17:51:59 -0700530
Alex Crichtonf3888432018-05-16 09:11:05 -0700531 pub fn new(string: &str, span: Span) -> Ident {
532 Ident::_new(string, false, span)
533 }
534
535 pub fn new_raw(string: &str, span: Span) -> Ident {
536 Ident::_new(string, true, span)
537 }
538
Alex Crichtonb2c94622018-04-04 07:36:41 -0700539 pub fn span(&self) -> Span {
540 self.span
541 }
542
543 pub fn set_span(&mut self, span: Span) {
544 self.span = span;
545 }
Alex Crichton44bffbc2017-05-19 17:51:59 -0700546}
547
Nicholas Nethercotee3cb3532018-05-28 20:11:58 +1000548#[inline]
549fn is_ident_start(c: char) -> bool {
David Tolnay03b43da2018-06-02 15:25:57 -0700550 ('a' <= c && c <= 'z')
551 || ('A' <= c && c <= 'Z')
552 || c == '_'
553 || (c > '\x7f' && UnicodeXID::is_xid_start(c))
Nicholas Nethercotee3cb3532018-05-28 20:11:58 +1000554}
555
556#[inline]
557fn is_ident_continue(c: char) -> bool {
David Tolnay03b43da2018-06-02 15:25:57 -0700558 ('a' <= c && c <= 'z')
559 || ('A' <= c && c <= 'Z')
560 || c == '_'
561 || ('0' <= c && c <= '9')
562 || (c > '\x7f' && UnicodeXID::is_xid_continue(c))
Nicholas Nethercotee3cb3532018-05-28 20:11:58 +1000563}
564
David Tolnay637eef42019-04-20 13:36:18 -0700565fn validate_ident(string: &str) {
Alex Crichtonf3888432018-05-16 09:11:05 -0700566 let validate = string;
David Tolnay489c6422018-04-07 08:37:28 -0700567 if validate.is_empty() {
Alex Crichtonf3888432018-05-16 09:11:05 -0700568 panic!("Ident is not allowed to be empty; use Option<Ident>");
David Tolnay489c6422018-04-07 08:37:28 -0700569 }
570
571 if validate.bytes().all(|digit| digit >= b'0' && digit <= b'9') {
Alex Crichtonf3888432018-05-16 09:11:05 -0700572 panic!("Ident cannot be a number; use Literal instead");
David Tolnay489c6422018-04-07 08:37:28 -0700573 }
574
Nicholas Nethercotee3cb3532018-05-28 20:11:58 +1000575 fn ident_ok(string: &str) -> bool {
David Tolnay489c6422018-04-07 08:37:28 -0700576 let mut chars = string.chars();
577 let first = chars.next().unwrap();
Nicholas Nethercotee3cb3532018-05-28 20:11:58 +1000578 if !is_ident_start(first) {
David Tolnay489c6422018-04-07 08:37:28 -0700579 return false;
580 }
581 for ch in chars {
Nicholas Nethercotee3cb3532018-05-28 20:11:58 +1000582 if !is_ident_continue(ch) {
David Tolnay489c6422018-04-07 08:37:28 -0700583 return false;
584 }
585 }
586 true
587 }
588
Nicholas Nethercotee3cb3532018-05-28 20:11:58 +1000589 if !ident_ok(validate) {
Alex Crichtonf3888432018-05-16 09:11:05 -0700590 panic!("{:?} is not a valid Ident", string);
David Tolnay489c6422018-04-07 08:37:28 -0700591 }
592}
593
David Tolnayc0b0f2e2018-09-02 17:56:08 -0700594impl PartialEq for Ident {
595 fn eq(&self, other: &Ident) -> bool {
596 self.sym == other.sym && self.raw == other.raw
597 }
598}
599
600impl<T> PartialEq<T> for Ident
601where
602 T: ?Sized + AsRef<str>,
603{
604 fn eq(&self, other: &T) -> bool {
605 let other = other.as_ref();
606 if self.raw {
607 other.starts_with("r#") && self.sym == other[2..]
608 } else {
609 self.sym == other
610 }
611 }
612}
613
Alex Crichtonf3888432018-05-16 09:11:05 -0700614impl fmt::Display for Ident {
David Tolnay8ad3e3e2017-06-03 16:45:00 -0700615 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Alex Crichtonf3888432018-05-16 09:11:05 -0700616 if self.raw {
617 "r#".fmt(f)?;
618 }
David Tolnayc2309ca2018-06-02 15:47:57 -0700619 self.sym.fmt(f)
Alex Crichtonf3888432018-05-16 09:11:05 -0700620 }
621}
622
623impl fmt::Debug for Ident {
David Tolnayd8fcdb82018-06-02 15:43:53 -0700624 // Ident(proc_macro), Ident(r#union)
625 #[cfg(not(procmacro2_semver_exempt))]
626 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
627 let mut debug = f.debug_tuple("Ident");
628 debug.field(&format_args!("{}", self));
629 debug.finish()
630 }
631
632 // Ident {
633 // sym: proc_macro,
634 // span: bytes(128..138)
635 // }
636 #[cfg(procmacro2_semver_exempt)]
Alex Crichtonf3888432018-05-16 09:11:05 -0700637 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
638 let mut debug = f.debug_struct("Ident");
David Tolnayd8fcdb82018-06-02 15:43:53 -0700639 debug.field("sym", &format_args!("{}", self));
David Tolnay034205f2018-04-22 16:45:28 -0700640 debug.field("span", &self.span);
641 debug.finish()
David Tolnay8ad3e3e2017-06-03 16:45:00 -0700642 }
643}
644
David Tolnay034205f2018-04-22 16:45:28 -0700645#[derive(Clone)]
Alex Crichtonb2c94622018-04-04 07:36:41 -0700646pub struct Literal {
647 text: String,
648 span: Span,
649}
Alex Crichton44bffbc2017-05-19 17:51:59 -0700650
Alex Crichtona914a612018-04-04 07:48:44 -0700651macro_rules! suffixed_numbers {
652 ($($name:ident => $kind:ident,)*) => ($(
653 pub fn $name(n: $kind) -> Literal {
654 Literal::_new(format!(concat!("{}", stringify!($kind)), n))
655 }
656 )*)
657}
658
659macro_rules! unsuffixed_numbers {
660 ($($name:ident => $kind:ident,)*) => ($(
661 pub fn $name(n: $kind) -> Literal {
662 Literal::_new(n.to_string())
663 }
664 )*)
665}
666
Alex Crichton852d53d2017-05-19 19:25:08 -0700667impl Literal {
Alex Crichtonb2c94622018-04-04 07:36:41 -0700668 fn _new(text: String) -> Literal {
669 Literal {
David Tolnayf0814122019-07-19 11:53:55 -0700670 text,
Alex Crichtonb2c94622018-04-04 07:36:41 -0700671 span: Span::call_site(),
672 }
673 }
674
Alex Crichtona914a612018-04-04 07:48:44 -0700675 suffixed_numbers! {
676 u8_suffixed => u8,
677 u16_suffixed => u16,
678 u32_suffixed => u32,
679 u64_suffixed => u64,
David Tolnay1596a8c2019-07-19 11:45:26 -0700680 u128_suffixed => u128,
Alex Crichtona914a612018-04-04 07:48:44 -0700681 usize_suffixed => usize,
682 i8_suffixed => i8,
683 i16_suffixed => i16,
684 i32_suffixed => i32,
685 i64_suffixed => i64,
David Tolnay1596a8c2019-07-19 11:45:26 -0700686 i128_suffixed => i128,
Alex Crichtona914a612018-04-04 07:48:44 -0700687 isize_suffixed => isize,
688
689 f32_suffixed => f32,
690 f64_suffixed => f64,
691 }
692
693 unsuffixed_numbers! {
694 u8_unsuffixed => u8,
695 u16_unsuffixed => u16,
696 u32_unsuffixed => u32,
697 u64_unsuffixed => u64,
David Tolnay1596a8c2019-07-19 11:45:26 -0700698 u128_unsuffixed => u128,
Alex Crichtona914a612018-04-04 07:48:44 -0700699 usize_unsuffixed => usize,
700 i8_unsuffixed => i8,
701 i16_unsuffixed => i16,
702 i32_unsuffixed => i32,
703 i64_unsuffixed => i64,
Alex Crichton69385662018-11-08 06:30:04 -0800704 i128_unsuffixed => i128,
David Tolnay1596a8c2019-07-19 11:45:26 -0700705 isize_unsuffixed => isize,
Alex Crichton69385662018-11-08 06:30:04 -0800706 }
707
Alex Crichtona914a612018-04-04 07:48:44 -0700708 pub fn f32_unsuffixed(f: f32) -> Literal {
709 let mut s = f.to_string();
710 if !s.contains(".") {
711 s.push_str(".0");
Alex Crichton76a5cc82017-05-23 07:01:44 -0700712 }
Alex Crichtona914a612018-04-04 07:48:44 -0700713 Literal::_new(s)
714 }
715
716 pub fn f64_unsuffixed(f: f64) -> Literal {
717 let mut s = f.to_string();
718 if !s.contains(".") {
719 s.push_str(".0");
720 }
721 Literal::_new(s)
722 }
723
724 pub fn string(t: &str) -> Literal {
David Tolnaye4482f42019-04-22 16:15:14 -0700725 let mut text = String::with_capacity(t.len() + 2);
726 text.push('"');
727 for c in t.chars() {
728 if c == '\'' {
729 // escape_default turns this into "\'" which is unnecessary.
730 text.push(c);
731 } else {
732 text.extend(c.escape_default());
733 }
734 }
735 text.push('"');
736 Literal::_new(text)
Alex Crichtona914a612018-04-04 07:48:44 -0700737 }
738
739 pub fn character(t: char) -> Literal {
David Tolnaye4482f42019-04-22 16:15:14 -0700740 let mut text = String::new();
741 text.push('\'');
742 if t == '"' {
743 // escape_default turns this into '\"' which is unnecessary.
744 text.push(t);
745 } else {
746 text.extend(t.escape_default());
747 }
748 text.push('\'');
749 Literal::_new(text)
Alex Crichton76a5cc82017-05-23 07:01:44 -0700750 }
751
Alex Crichton9c2fb0a2017-05-26 08:49:31 -0700752 pub fn byte_string(bytes: &[u8]) -> Literal {
Alex Crichton852d53d2017-05-19 19:25:08 -0700753 let mut escaped = "b\"".to_string();
754 for b in bytes {
755 match *b {
756 b'\0' => escaped.push_str(r"\0"),
757 b'\t' => escaped.push_str(r"\t"),
758 b'\n' => escaped.push_str(r"\n"),
759 b'\r' => escaped.push_str(r"\r"),
760 b'"' => escaped.push_str("\\\""),
761 b'\\' => escaped.push_str("\\\\"),
David Tolnayaf1e8bb2019-07-19 11:56:13 -0700762 b'\x20'..=b'\x7E' => escaped.push(*b as char),
Alex Crichton852d53d2017-05-19 19:25:08 -0700763 _ => escaped.push_str(&format!("\\x{:02X}", b)),
764 }
765 }
766 escaped.push('"');
Alex Crichtonb2c94622018-04-04 07:36:41 -0700767 Literal::_new(escaped)
Alex Crichton76a5cc82017-05-23 07:01:44 -0700768 }
Alex Crichton9c2fb0a2017-05-26 08:49:31 -0700769
Alex Crichtonb2c94622018-04-04 07:36:41 -0700770 pub fn span(&self) -> Span {
771 self.span
Alex Crichton31316622017-05-26 12:54:47 -0700772 }
773
Alex Crichtonb2c94622018-04-04 07:36:41 -0700774 pub fn set_span(&mut self, span: Span) {
775 self.span = span;
Alex Crichton31316622017-05-26 12:54:47 -0700776 }
Alex Crichton852d53d2017-05-19 19:25:08 -0700777}
778
Alex Crichton44bffbc2017-05-19 17:51:59 -0700779impl fmt::Display for Literal {
780 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Alex Crichtonb2c94622018-04-04 07:36:41 -0700781 self.text.fmt(f)
Alex Crichton44bffbc2017-05-19 17:51:59 -0700782 }
783}
784
David Tolnay034205f2018-04-22 16:45:28 -0700785impl fmt::Debug for Literal {
786 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
787 let mut debug = fmt.debug_struct("Literal");
788 debug.field("lit", &format_args!("{}", self.text));
789 #[cfg(procmacro2_semver_exempt)]
790 debug.field("span", &self.span);
791 debug.finish()
792 }
793}
794
Alex Crichton30a4e9e2018-04-27 17:02:19 -0700795fn token_stream(mut input: Cursor) -> PResult<TokenStream> {
Alex Crichton1eb96a02018-04-04 13:07:35 -0700796 let mut trees = Vec::new();
797 loop {
798 let input_no_ws = skip_whitespace(input);
799 if input_no_ws.rest.len() == 0 {
David Tolnay48ea5042018-04-23 19:17:35 -0700800 break;
Alex Crichton1eb96a02018-04-04 13:07:35 -0700801 }
802 if let Ok((a, tokens)) = doc_comment(input_no_ws) {
803 input = a;
804 trees.extend(tokens);
David Tolnay48ea5042018-04-23 19:17:35 -0700805 continue;
Alex Crichton1eb96a02018-04-04 13:07:35 -0700806 }
807
808 let (a, tt) = match token_tree(input_no_ws) {
809 Ok(p) => p,
810 Err(_) => break,
811 };
812 trees.push(tt);
813 input = a;
814 }
Alex Crichton30a4e9e2018-04-27 17:02:19 -0700815 Ok((input, TokenStream { inner: trees }))
Alex Crichton1eb96a02018-04-04 13:07:35 -0700816}
Alex Crichton44bffbc2017-05-19 17:51:59 -0700817
David Tolnay3b1f7d22019-01-28 12:22:11 -0800818#[cfg(not(span_locations))]
Alex Crichton1eb96a02018-04-04 13:07:35 -0700819fn spanned<'a, T>(
820 input: Cursor<'a>,
821 f: fn(Cursor<'a>) -> PResult<'a, T>,
David Tolnay0f884b12019-07-19 11:59:20 -0700822) -> PResult<'a, (T, crate::Span)> {
Alex Crichton1eb96a02018-04-04 13:07:35 -0700823 let (a, b) = f(skip_whitespace(input))?;
David Tolnay0f884b12019-07-19 11:59:20 -0700824 Ok((a, ((b, crate::Span::_new_stable(Span::call_site())))))
David Tolnayddfca052017-12-31 10:41:24 -0500825}
826
David Tolnay3b1f7d22019-01-28 12:22:11 -0800827#[cfg(span_locations)]
Alex Crichton1eb96a02018-04-04 13:07:35 -0700828fn spanned<'a, T>(
829 input: Cursor<'a>,
830 f: fn(Cursor<'a>) -> PResult<'a, T>,
David Tolnay0f884b12019-07-19 11:59:20 -0700831) -> PResult<'a, (T, crate::Span)> {
Nika Layzellf8d5f212017-12-11 14:07:02 -0500832 let input = skip_whitespace(input);
833 let lo = input.off;
Alex Crichton1eb96a02018-04-04 13:07:35 -0700834 let (a, b) = f(input)?;
835 let hi = a.off;
David Tolnay0f884b12019-07-19 11:59:20 -0700836 let span = crate::Span::_new_stable(Span { lo, hi });
Alex Crichton1eb96a02018-04-04 13:07:35 -0700837 Ok((a, (b, span)))
838}
839
840fn token_tree(input: Cursor) -> PResult<TokenTree> {
841 let (rest, (mut tt, span)) = spanned(input, token_kind)?;
842 tt.set_span(span);
843 Ok((rest, tt))
Nika Layzellf8d5f212017-12-11 14:07:02 -0500844}
Alex Crichton44bffbc2017-05-19 17:51:59 -0700845
Alex Crichtonaf5bad42018-03-27 14:45:10 -0700846named!(token_kind -> TokenTree, alt!(
David Tolnay0f884b12019-07-19 11:59:20 -0700847 map!(group, |g| TokenTree::Group(crate::Group::_new_stable(g)))
Alex Crichton44bffbc2017-05-19 17:51:59 -0700848 |
David Tolnay0f884b12019-07-19 11:59:20 -0700849 map!(literal, |l| TokenTree::Literal(crate::Literal::_new_stable(l))) // must be before symbol
Alex Crichton44bffbc2017-05-19 17:51:59 -0700850 |
Alex Crichtonf3888432018-05-16 09:11:05 -0700851 map!(op, TokenTree::Punct)
Alex Crichton44bffbc2017-05-19 17:51:59 -0700852 |
Alex Crichtonf3888432018-05-16 09:11:05 -0700853 symbol_leading_ws
Alex Crichton44bffbc2017-05-19 17:51:59 -0700854));
855
Alex Crichtonaf5bad42018-03-27 14:45:10 -0700856named!(group -> Group, alt!(
Alex Crichton44bffbc2017-05-19 17:51:59 -0700857 delimited!(
858 punct!("("),
859 token_stream,
860 punct!(")")
David Tolnayf14813f2018-09-08 17:14:07 -0700861 ) => { |ts| Group::new(Delimiter::Parenthesis, ts) }
Alex Crichton44bffbc2017-05-19 17:51:59 -0700862 |
863 delimited!(
864 punct!("["),
865 token_stream,
866 punct!("]")
David Tolnayf14813f2018-09-08 17:14:07 -0700867 ) => { |ts| Group::new(Delimiter::Bracket, ts) }
Alex Crichton44bffbc2017-05-19 17:51:59 -0700868 |
869 delimited!(
870 punct!("{"),
871 token_stream,
872 punct!("}")
David Tolnayf14813f2018-09-08 17:14:07 -0700873 ) => { |ts| Group::new(Delimiter::Brace, ts) }
Alex Crichton44bffbc2017-05-19 17:51:59 -0700874));
875
Alex Crichtonf3888432018-05-16 09:11:05 -0700876fn symbol_leading_ws(input: Cursor) -> PResult<TokenTree> {
877 symbol(skip_whitespace(input))
878}
Alex Crichton44bffbc2017-05-19 17:51:59 -0700879
Alex Crichtonf3888432018-05-16 09:11:05 -0700880fn symbol(input: Cursor) -> PResult<TokenTree> {
Alex Crichton44bffbc2017-05-19 17:51:59 -0700881 let mut chars = input.char_indices();
David Tolnaya202d502017-06-01 12:26:55 -0700882
Alex Crichtonf3888432018-05-16 09:11:05 -0700883 let raw = input.starts_with("r#");
David Tolnaya13d1422018-03-31 21:27:48 +0200884 if raw {
885 chars.next();
886 chars.next();
887 }
888
Alex Crichton44bffbc2017-05-19 17:51:59 -0700889 match chars.next() {
Nicholas Nethercotee3cb3532018-05-28 20:11:58 +1000890 Some((_, ch)) if is_ident_start(ch) => {}
David Tolnay1218e122017-06-01 11:13:45 -0700891 _ => return Err(LexError),
Alex Crichton44bffbc2017-05-19 17:51:59 -0700892 }
893
David Tolnay214c94c2017-06-01 12:42:56 -0700894 let mut end = input.len();
Alex Crichton44bffbc2017-05-19 17:51:59 -0700895 for (i, ch) in chars {
Nicholas Nethercotee3cb3532018-05-28 20:11:58 +1000896 if !is_ident_continue(ch) {
David Tolnay214c94c2017-06-01 12:42:56 -0700897 end = i;
898 break;
Alex Crichton44bffbc2017-05-19 17:51:59 -0700899 }
900 }
901
David Tolnaya13d1422018-03-31 21:27:48 +0200902 let a = &input.rest[..end];
Alex Crichtonf3888432018-05-16 09:11:05 -0700903 if a == "r#_" {
David Tolnay214c94c2017-06-01 12:42:56 -0700904 Err(LexError)
905 } else {
Alex Crichtonf3888432018-05-16 09:11:05 -0700906 let ident = if raw {
David Tolnay0f884b12019-07-19 11:59:20 -0700907 crate::Ident::_new_raw(&a[2..], crate::Span::call_site())
Alex Crichtonf3888432018-05-16 09:11:05 -0700908 } else {
David Tolnay0f884b12019-07-19 11:59:20 -0700909 crate::Ident::new(a, crate::Span::call_site())
Alex Crichtonf3888432018-05-16 09:11:05 -0700910 };
911 Ok((input.advance(end), ident.into()))
David Tolnay214c94c2017-06-01 12:42:56 -0700912 }
Alex Crichton44bffbc2017-05-19 17:51:59 -0700913}
914
Alex Crichton30a4e9e2018-04-27 17:02:19 -0700915fn literal(input: Cursor) -> PResult<Literal> {
Alex Crichton44bffbc2017-05-19 17:51:59 -0700916 let input_no_ws = skip_whitespace(input);
917
918 match literal_nocapture(input_no_ws) {
David Tolnay1218e122017-06-01 11:13:45 -0700919 Ok((a, ())) => {
Alex Crichton44bffbc2017-05-19 17:51:59 -0700920 let start = input.len() - input_no_ws.len();
921 let len = input_no_ws.len() - a.len();
922 let end = start + len;
David Tolnay3d9d6ad2018-05-18 10:51:55 -0700923 Ok((a, Literal::_new(input.rest[start..end].to_string())))
Alex Crichton44bffbc2017-05-19 17:51:59 -0700924 }
David Tolnay1218e122017-06-01 11:13:45 -0700925 Err(LexError) => Err(LexError),
Alex Crichton44bffbc2017-05-19 17:51:59 -0700926 }
927}
928
929named!(literal_nocapture -> (), alt!(
930 string
931 |
932 byte_string
933 |
934 byte
935 |
936 character
937 |
938 float
939 |
940 int
Alex Crichton44bffbc2017-05-19 17:51:59 -0700941));
942
943named!(string -> (), alt!(
944 quoted_string
945 |
946 preceded!(
947 punct!("r"),
948 raw_string
949 ) => { |_| () }
950));
951
952named!(quoted_string -> (), delimited!(
953 punct!("\""),
954 cooked_string,
955 tag!("\"")
956));
957
Nika Layzellf8d5f212017-12-11 14:07:02 -0500958fn cooked_string(input: Cursor) -> PResult<()> {
Alex Crichton44bffbc2017-05-19 17:51:59 -0700959 let mut chars = input.char_indices().peekable();
960 while let Some((byte_offset, ch)) = chars.next() {
961 match ch {
962 '"' => {
Nika Layzellf8d5f212017-12-11 14:07:02 -0500963 return Ok((input.advance(byte_offset), ()));
Alex Crichton44bffbc2017-05-19 17:51:59 -0700964 }
965 '\r' => {
966 if let Some((_, '\n')) = chars.next() {
967 // ...
968 } else {
969 break;
970 }
971 }
David Tolnayb28f38a2018-03-31 22:02:29 +0200972 '\\' => match chars.next() {
973 Some((_, 'x')) => {
974 if !backslash_x_char(&mut chars) {
975 break;
Alex Crichton44bffbc2017-05-19 17:51:59 -0700976 }
Alex Crichton44bffbc2017-05-19 17:51:59 -0700977 }
David Tolnayb28f38a2018-03-31 22:02:29 +0200978 Some((_, 'n')) | Some((_, 'r')) | Some((_, 't')) | Some((_, '\\'))
979 | Some((_, '\'')) | Some((_, '"')) | Some((_, '0')) => {}
980 Some((_, 'u')) => {
981 if !backslash_u(&mut chars) {
982 break;
983 }
984 }
985 Some((_, '\n')) | Some((_, '\r')) => {
986 while let Some(&(_, ch)) = chars.peek() {
987 if ch.is_whitespace() {
988 chars.next();
989 } else {
990 break;
991 }
992 }
993 }
994 _ => break,
995 },
Alex Crichton44bffbc2017-05-19 17:51:59 -0700996 _ch => {}
997 }
998 }
David Tolnay1218e122017-06-01 11:13:45 -0700999 Err(LexError)
Alex Crichton44bffbc2017-05-19 17:51:59 -07001000}
1001
1002named!(byte_string -> (), alt!(
1003 delimited!(
1004 punct!("b\""),
1005 cooked_byte_string,
1006 tag!("\"")
1007 ) => { |_| () }
1008 |
1009 preceded!(
1010 punct!("br"),
1011 raw_string
1012 ) => { |_| () }
1013));
1014
Nika Layzellf8d5f212017-12-11 14:07:02 -05001015fn cooked_byte_string(mut input: Cursor) -> PResult<()> {
Alex Crichton44bffbc2017-05-19 17:51:59 -07001016 let mut bytes = input.bytes().enumerate();
1017 'outer: while let Some((offset, b)) = bytes.next() {
1018 match b {
1019 b'"' => {
Nika Layzellf8d5f212017-12-11 14:07:02 -05001020 return Ok((input.advance(offset), ()));
Alex Crichton44bffbc2017-05-19 17:51:59 -07001021 }
1022 b'\r' => {
1023 if let Some((_, b'\n')) = bytes.next() {
1024 // ...
1025 } else {
1026 break;
1027 }
1028 }
David Tolnayb28f38a2018-03-31 22:02:29 +02001029 b'\\' => match bytes.next() {
1030 Some((_, b'x')) => {
1031 if !backslash_x_byte(&mut bytes) {
Alex Crichton44bffbc2017-05-19 17:51:59 -07001032 break;
1033 }
Alex Crichton44bffbc2017-05-19 17:51:59 -07001034 }
David Tolnayb28f38a2018-03-31 22:02:29 +02001035 Some((_, b'n')) | Some((_, b'r')) | Some((_, b't')) | Some((_, b'\\'))
1036 | Some((_, b'0')) | Some((_, b'\'')) | Some((_, b'"')) => {}
1037 Some((newline, b'\n')) | Some((newline, b'\r')) => {
1038 let rest = input.advance(newline + 1);
1039 for (offset, ch) in rest.char_indices() {
1040 if !ch.is_whitespace() {
1041 input = rest.advance(offset);
1042 bytes = input.bytes().enumerate();
1043 continue 'outer;
1044 }
1045 }
1046 break;
1047 }
1048 _ => break,
1049 },
Alex Crichton44bffbc2017-05-19 17:51:59 -07001050 b if b < 0x80 => {}
1051 _ => break,
1052 }
1053 }
David Tolnay1218e122017-06-01 11:13:45 -07001054 Err(LexError)
Alex Crichton44bffbc2017-05-19 17:51:59 -07001055}
1056
Nika Layzellf8d5f212017-12-11 14:07:02 -05001057fn raw_string(input: Cursor) -> PResult<()> {
Alex Crichton44bffbc2017-05-19 17:51:59 -07001058 let mut chars = input.char_indices();
1059 let mut n = 0;
1060 while let Some((byte_offset, ch)) = chars.next() {
1061 match ch {
1062 '"' => {
1063 n = byte_offset;
1064 break;
1065 }
1066 '#' => {}
David Tolnay1218e122017-06-01 11:13:45 -07001067 _ => return Err(LexError),
Alex Crichton44bffbc2017-05-19 17:51:59 -07001068 }
1069 }
1070 for (byte_offset, ch) in chars {
1071 match ch {
Nika Layzellf8d5f212017-12-11 14:07:02 -05001072 '"' if input.advance(byte_offset + 1).starts_with(&input.rest[..n]) => {
1073 let rest = input.advance(byte_offset + 1 + n);
David Tolnayb28f38a2018-03-31 22:02:29 +02001074 return Ok((rest, ()));
Alex Crichton44bffbc2017-05-19 17:51:59 -07001075 }
1076 '\r' => {}
1077 _ => {}
1078 }
1079 }
David Tolnay1218e122017-06-01 11:13:45 -07001080 Err(LexError)
Alex Crichton44bffbc2017-05-19 17:51:59 -07001081}
1082
1083named!(byte -> (), do_parse!(
1084 punct!("b") >>
1085 tag!("'") >>
1086 cooked_byte >>
1087 tag!("'") >>
1088 (())
1089));
1090
Nika Layzellf8d5f212017-12-11 14:07:02 -05001091fn cooked_byte(input: Cursor) -> PResult<()> {
Alex Crichton44bffbc2017-05-19 17:51:59 -07001092 let mut bytes = input.bytes().enumerate();
1093 let ok = match bytes.next().map(|(_, b)| b) {
David Tolnayb28f38a2018-03-31 22:02:29 +02001094 Some(b'\\') => match bytes.next().map(|(_, b)| b) {
1095 Some(b'x') => backslash_x_byte(&mut bytes),
1096 Some(b'n') | Some(b'r') | Some(b't') | Some(b'\\') | Some(b'0') | Some(b'\'')
1097 | Some(b'"') => true,
1098 _ => false,
1099 },
Alex Crichton44bffbc2017-05-19 17:51:59 -07001100 b => b.is_some(),
1101 };
1102 if ok {
1103 match bytes.next() {
Alex Crichton8c030332018-01-16 08:07:36 -08001104 Some((offset, _)) => {
1105 if input.chars().as_str().is_char_boundary(offset) {
1106 Ok((input.advance(offset), ()))
1107 } else {
1108 Err(LexError)
1109 }
1110 }
Nika Layzellf8d5f212017-12-11 14:07:02 -05001111 None => Ok((input.advance(input.len()), ())),
Alex Crichton44bffbc2017-05-19 17:51:59 -07001112 }
1113 } else {
David Tolnay1218e122017-06-01 11:13:45 -07001114 Err(LexError)
Alex Crichton44bffbc2017-05-19 17:51:59 -07001115 }
1116}
1117
1118named!(character -> (), do_parse!(
1119 punct!("'") >>
1120 cooked_char >>
1121 tag!("'") >>
1122 (())
1123));
1124
Nika Layzellf8d5f212017-12-11 14:07:02 -05001125fn cooked_char(input: Cursor) -> PResult<()> {
Alex Crichton44bffbc2017-05-19 17:51:59 -07001126 let mut chars = input.char_indices();
1127 let ok = match chars.next().map(|(_, ch)| ch) {
David Tolnayb28f38a2018-03-31 22:02:29 +02001128 Some('\\') => match chars.next().map(|(_, ch)| ch) {
1129 Some('x') => backslash_x_char(&mut chars),
1130 Some('u') => backslash_u(&mut chars),
1131 Some('n') | Some('r') | Some('t') | Some('\\') | Some('0') | Some('\'') | Some('"') => {
1132 true
Alex Crichton44bffbc2017-05-19 17:51:59 -07001133 }
David Tolnayb28f38a2018-03-31 22:02:29 +02001134 _ => false,
1135 },
Alex Crichton44bffbc2017-05-19 17:51:59 -07001136 ch => ch.is_some(),
1137 };
1138 if ok {
Nika Layzellf8d5f212017-12-11 14:07:02 -05001139 match chars.next() {
1140 Some((idx, _)) => Ok((input.advance(idx), ())),
1141 None => Ok((input.advance(input.len()), ())),
1142 }
Alex Crichton44bffbc2017-05-19 17:51:59 -07001143 } else {
David Tolnay1218e122017-06-01 11:13:45 -07001144 Err(LexError)
Alex Crichton44bffbc2017-05-19 17:51:59 -07001145 }
1146}
1147
1148macro_rules! next_ch {
1149 ($chars:ident @ $pat:pat $(| $rest:pat)*) => {
1150 match $chars.next() {
1151 Some((_, ch)) => match ch {
1152 $pat $(| $rest)* => ch,
1153 _ => return false,
1154 },
1155 None => return false
1156 }
1157 };
1158}
1159
1160fn backslash_x_char<I>(chars: &mut I) -> bool
David Tolnayb28f38a2018-03-31 22:02:29 +02001161where
1162 I: Iterator<Item = (usize, char)>,
Alex Crichton44bffbc2017-05-19 17:51:59 -07001163{
David Tolnayaf1e8bb2019-07-19 11:56:13 -07001164 next_ch!(chars @ '0'..='7');
1165 next_ch!(chars @ '0'..='9' | 'a'..='f' | 'A'..='F');
Alex Crichton44bffbc2017-05-19 17:51:59 -07001166 true
1167}
1168
1169fn backslash_x_byte<I>(chars: &mut I) -> bool
David Tolnayb28f38a2018-03-31 22:02:29 +02001170where
1171 I: Iterator<Item = (usize, u8)>,
Alex Crichton44bffbc2017-05-19 17:51:59 -07001172{
David Tolnayaf1e8bb2019-07-19 11:56:13 -07001173 next_ch!(chars @ b'0'..=b'9' | b'a'..=b'f' | b'A'..=b'F');
1174 next_ch!(chars @ b'0'..=b'9' | b'a'..=b'f' | b'A'..=b'F');
Alex Crichton44bffbc2017-05-19 17:51:59 -07001175 true
1176}
1177
1178fn backslash_u<I>(chars: &mut I) -> bool
David Tolnayb28f38a2018-03-31 22:02:29 +02001179where
1180 I: Iterator<Item = (usize, char)>,
Alex Crichton44bffbc2017-05-19 17:51:59 -07001181{
1182 next_ch!(chars @ '{');
David Tolnayaf1e8bb2019-07-19 11:56:13 -07001183 next_ch!(chars @ '0'..='9' | 'a'..='f' | 'A'..='F');
David Tolnay8d109342017-12-25 18:24:45 -05001184 loop {
David Tolnayaf1e8bb2019-07-19 11:56:13 -07001185 let c = next_ch!(chars @ '0'..='9' | 'a'..='f' | 'A'..='F' | '_' | '}');
David Tolnay8d109342017-12-25 18:24:45 -05001186 if c == '}' {
1187 return true;
1188 }
Alex Crichton44bffbc2017-05-19 17:51:59 -07001189 }
Alex Crichton44bffbc2017-05-19 17:51:59 -07001190}
1191
Nika Layzellf8d5f212017-12-11 14:07:02 -05001192fn float(input: Cursor) -> PResult<()> {
David Tolnay744a6b82017-06-01 11:34:29 -07001193 let (rest, ()) = float_digits(input)?;
1194 for suffix in &["f32", "f64"] {
1195 if rest.starts_with(suffix) {
Nika Layzellf8d5f212017-12-11 14:07:02 -05001196 return word_break(rest.advance(suffix.len()));
David Tolnay744a6b82017-06-01 11:34:29 -07001197 }
1198 }
1199 word_break(rest)
1200}
Alex Crichton44bffbc2017-05-19 17:51:59 -07001201
Nika Layzellf8d5f212017-12-11 14:07:02 -05001202fn float_digits(input: Cursor) -> PResult<()> {
Alex Crichton44bffbc2017-05-19 17:51:59 -07001203 let mut chars = input.chars().peekable();
1204 match chars.next() {
1205 Some(ch) if ch >= '0' && ch <= '9' => {}
David Tolnay1218e122017-06-01 11:13:45 -07001206 _ => return Err(LexError),
Alex Crichton44bffbc2017-05-19 17:51:59 -07001207 }
1208
1209 let mut len = 1;
1210 let mut has_dot = false;
1211 let mut has_exp = false;
1212 while let Some(&ch) = chars.peek() {
1213 match ch {
David Tolnayaf1e8bb2019-07-19 11:56:13 -07001214 '0'..='9' | '_' => {
Alex Crichton44bffbc2017-05-19 17:51:59 -07001215 chars.next();
1216 len += 1;
1217 }
1218 '.' => {
1219 if has_dot {
1220 break;
1221 }
1222 chars.next();
David Tolnayb28f38a2018-03-31 22:02:29 +02001223 if chars
1224 .peek()
1225 .map(|&ch| ch == '.' || UnicodeXID::is_xid_start(ch))
1226 .unwrap_or(false)
1227 {
David Tolnay1218e122017-06-01 11:13:45 -07001228 return Err(LexError);
Alex Crichton44bffbc2017-05-19 17:51:59 -07001229 }
1230 len += 1;
1231 has_dot = true;
1232 }
1233 'e' | 'E' => {
1234 chars.next();
1235 len += 1;
1236 has_exp = true;
1237 break;
1238 }
1239 _ => break,
1240 }
1241 }
1242
Nika Layzellf8d5f212017-12-11 14:07:02 -05001243 let rest = input.advance(len);
Alex Crichton44bffbc2017-05-19 17:51:59 -07001244 if !(has_dot || has_exp || rest.starts_with("f32") || rest.starts_with("f64")) {
David Tolnay1218e122017-06-01 11:13:45 -07001245 return Err(LexError);
Alex Crichton44bffbc2017-05-19 17:51:59 -07001246 }
1247
1248 if has_exp {
1249 let mut has_exp_value = false;
1250 while let Some(&ch) = chars.peek() {
1251 match ch {
1252 '+' | '-' => {
1253 if has_exp_value {
1254 break;
1255 }
1256 chars.next();
1257 len += 1;
1258 }
David Tolnayaf1e8bb2019-07-19 11:56:13 -07001259 '0'..='9' => {
Alex Crichton44bffbc2017-05-19 17:51:59 -07001260 chars.next();
1261 len += 1;
1262 has_exp_value = true;
1263 }
1264 '_' => {
1265 chars.next();
1266 len += 1;
1267 }
1268 _ => break,
1269 }
1270 }
1271 if !has_exp_value {
David Tolnay1218e122017-06-01 11:13:45 -07001272 return Err(LexError);
Alex Crichton44bffbc2017-05-19 17:51:59 -07001273 }
1274 }
1275
Nika Layzellf8d5f212017-12-11 14:07:02 -05001276 Ok((input.advance(len), ()))
Alex Crichton44bffbc2017-05-19 17:51:59 -07001277}
1278
Nika Layzellf8d5f212017-12-11 14:07:02 -05001279fn int(input: Cursor) -> PResult<()> {
David Tolnay744a6b82017-06-01 11:34:29 -07001280 let (rest, ()) = digits(input)?;
1281 for suffix in &[
David Tolnay48ea5042018-04-23 19:17:35 -07001282 "isize", "i8", "i16", "i32", "i64", "i128", "usize", "u8", "u16", "u32", "u64", "u128",
David Tolnay744a6b82017-06-01 11:34:29 -07001283 ] {
1284 if rest.starts_with(suffix) {
Nika Layzellf8d5f212017-12-11 14:07:02 -05001285 return word_break(rest.advance(suffix.len()));
David Tolnay744a6b82017-06-01 11:34:29 -07001286 }
1287 }
1288 word_break(rest)
1289}
Alex Crichton44bffbc2017-05-19 17:51:59 -07001290
Nika Layzellf8d5f212017-12-11 14:07:02 -05001291fn digits(mut input: Cursor) -> PResult<()> {
Alex Crichton44bffbc2017-05-19 17:51:59 -07001292 let base = if input.starts_with("0x") {
Nika Layzellf8d5f212017-12-11 14:07:02 -05001293 input = input.advance(2);
Alex Crichton44bffbc2017-05-19 17:51:59 -07001294 16
1295 } else if input.starts_with("0o") {
Nika Layzellf8d5f212017-12-11 14:07:02 -05001296 input = input.advance(2);
Alex Crichton44bffbc2017-05-19 17:51:59 -07001297 8
1298 } else if input.starts_with("0b") {
Nika Layzellf8d5f212017-12-11 14:07:02 -05001299 input = input.advance(2);
Alex Crichton44bffbc2017-05-19 17:51:59 -07001300 2
1301 } else {
1302 10
1303 };
1304
Alex Crichton44bffbc2017-05-19 17:51:59 -07001305 let mut len = 0;
1306 let mut empty = true;
1307 for b in input.bytes() {
1308 let digit = match b {
David Tolnayaf1e8bb2019-07-19 11:56:13 -07001309 b'0'..=b'9' => (b - b'0') as u64,
1310 b'a'..=b'f' => 10 + (b - b'a') as u64,
1311 b'A'..=b'F' => 10 + (b - b'A') as u64,
Alex Crichton44bffbc2017-05-19 17:51:59 -07001312 b'_' => {
1313 if empty && base == 10 {
David Tolnay1218e122017-06-01 11:13:45 -07001314 return Err(LexError);
Alex Crichton44bffbc2017-05-19 17:51:59 -07001315 }
1316 len += 1;
1317 continue;
1318 }
1319 _ => break,
1320 };
1321 if digit >= base {
David Tolnay1218e122017-06-01 11:13:45 -07001322 return Err(LexError);
Alex Crichton44bffbc2017-05-19 17:51:59 -07001323 }
Alex Crichton44bffbc2017-05-19 17:51:59 -07001324 len += 1;
1325 empty = false;
1326 }
1327 if empty {
David Tolnay1218e122017-06-01 11:13:45 -07001328 Err(LexError)
Alex Crichton44bffbc2017-05-19 17:51:59 -07001329 } else {
Nika Layzellf8d5f212017-12-11 14:07:02 -05001330 Ok((input.advance(len), ()))
Alex Crichton44bffbc2017-05-19 17:51:59 -07001331 }
1332}
1333
Alex Crichtonf3888432018-05-16 09:11:05 -07001334fn op(input: Cursor) -> PResult<Punct> {
David Tolnayea75c5f2017-05-31 23:40:33 -07001335 let input = skip_whitespace(input);
1336 match op_char(input) {
Alex Crichtonf3888432018-05-16 09:11:05 -07001337 Ok((rest, '\'')) => {
1338 symbol(rest)?;
1339 Ok((rest, Punct::new('\'', Spacing::Joint)))
1340 }
David Tolnay1218e122017-06-01 11:13:45 -07001341 Ok((rest, ch)) => {
David Tolnayea75c5f2017-05-31 23:40:33 -07001342 let kind = match op_char(rest) {
Alex Crichton1a7f7622017-07-05 17:47:15 -07001343 Ok(_) => Spacing::Joint,
1344 Err(LexError) => Spacing::Alone,
David Tolnayea75c5f2017-05-31 23:40:33 -07001345 };
Alex Crichtonf3888432018-05-16 09:11:05 -07001346 Ok((rest, Punct::new(ch, kind)))
David Tolnayea75c5f2017-05-31 23:40:33 -07001347 }
David Tolnay1218e122017-06-01 11:13:45 -07001348 Err(LexError) => Err(LexError),
Alex Crichton44bffbc2017-05-19 17:51:59 -07001349 }
1350}
1351
Nika Layzellf8d5f212017-12-11 14:07:02 -05001352fn op_char(input: Cursor) -> PResult<char> {
David Tolnay3a592ad2018-04-22 21:20:24 -07001353 if input.starts_with("//") || input.starts_with("/*") {
1354 // Do not accept `/` of a comment as an op.
1355 return Err(LexError);
1356 }
1357
David Tolnayea75c5f2017-05-31 23:40:33 -07001358 let mut chars = input.chars();
1359 let first = match chars.next() {
1360 Some(ch) => ch,
1361 None => {
David Tolnay1218e122017-06-01 11:13:45 -07001362 return Err(LexError);
David Tolnayea75c5f2017-05-31 23:40:33 -07001363 }
1364 };
Alex Crichtonf3888432018-05-16 09:11:05 -07001365 let recognized = "~!@#$%^&*-=+|;:,<.>/?'";
David Tolnayea75c5f2017-05-31 23:40:33 -07001366 if recognized.contains(first) {
Nika Layzellf8d5f212017-12-11 14:07:02 -05001367 Ok((input.advance(first.len_utf8()), first))
Alex Crichton44bffbc2017-05-19 17:51:59 -07001368 } else {
David Tolnay1218e122017-06-01 11:13:45 -07001369 Err(LexError)
Alex Crichton44bffbc2017-05-19 17:51:59 -07001370 }
1371}
1372
Alex Crichton1eb96a02018-04-04 13:07:35 -07001373fn doc_comment(input: Cursor) -> PResult<Vec<TokenTree>> {
1374 let mut trees = Vec::new();
1375 let (rest, ((comment, inner), span)) = spanned(input, doc_comment_contents)?;
Alex Crichtonf3888432018-05-16 09:11:05 -07001376 trees.push(TokenTree::Punct(Punct::new('#', Spacing::Alone)));
Alex Crichton1eb96a02018-04-04 13:07:35 -07001377 if inner {
Alex Crichtonf3888432018-05-16 09:11:05 -07001378 trees.push(Punct::new('!', Spacing::Alone).into());
Alex Crichton1eb96a02018-04-04 13:07:35 -07001379 }
1380 let mut stream = vec![
David Tolnay0f884b12019-07-19 11:59:20 -07001381 TokenTree::Ident(crate::Ident::new("doc", span)),
Alex Crichtonf3888432018-05-16 09:11:05 -07001382 TokenTree::Punct(Punct::new('=', Spacing::Alone)),
David Tolnay0f884b12019-07-19 11:59:20 -07001383 TokenTree::Literal(crate::Literal::string(comment)),
Alex Crichton1eb96a02018-04-04 13:07:35 -07001384 ];
1385 for tt in stream.iter_mut() {
1386 tt.set_span(span);
1387 }
David Tolnayf14813f2018-09-08 17:14:07 -07001388 let group = Group::new(Delimiter::Bracket, stream.into_iter().collect());
David Tolnay0f884b12019-07-19 11:59:20 -07001389 trees.push(crate::Group::_new_stable(group).into());
Alex Crichton1eb96a02018-04-04 13:07:35 -07001390 for tt in trees.iter_mut() {
1391 tt.set_span(span);
1392 }
1393 Ok((rest, trees))
1394}
1395
1396named!(doc_comment_contents -> (&str, bool), alt!(
Alex Crichton44bffbc2017-05-19 17:51:59 -07001397 do_parse!(
1398 punct!("//!") >>
Alex Crichton1eb96a02018-04-04 13:07:35 -07001399 s: take_until_newline_or_eof!() >>
1400 ((s, true))
Alex Crichton44bffbc2017-05-19 17:51:59 -07001401 )
1402 |
1403 do_parse!(
1404 option!(whitespace) >>
1405 peek!(tag!("/*!")) >>
Alex Crichton1eb96a02018-04-04 13:07:35 -07001406 s: block_comment >>
1407 ((s, true))
Alex Crichton44bffbc2017-05-19 17:51:59 -07001408 )
1409 |
1410 do_parse!(
1411 punct!("///") >>
1412 not!(tag!("/")) >>
Alex Crichton1eb96a02018-04-04 13:07:35 -07001413 s: take_until_newline_or_eof!() >>
1414 ((s, false))
Alex Crichton44bffbc2017-05-19 17:51:59 -07001415 )
1416 |
1417 do_parse!(
1418 option!(whitespace) >>
1419 peek!(tuple!(tag!("/**"), not!(tag!("*")))) >>
Alex Crichton1eb96a02018-04-04 13:07:35 -07001420 s: block_comment >>
1421 ((s, false))
Alex Crichton44bffbc2017-05-19 17:51:59 -07001422 )
1423));