Create a new span for the corresponding byte range in the given string.
(subject: &str, range: Range<usize>)
| 2348 | |
| 2349 | /// Create a new span for the corresponding byte range in the given string. |
| 2350 | fn span_range(subject: &str, range: Range<usize>) -> Span { |
| 2351 | let start = Position { |
| 2352 | offset: range.start, |
| 2353 | line: 1 + subject[..range.start].matches('\n').count(), |
| 2354 | column: 1 + subject[..range.start] |
| 2355 | .chars() |
| 2356 | .rev() |
| 2357 | .position(|c| c == '\n') |
| 2358 | .unwrap_or(subject[..range.start].chars().count()), |
| 2359 | }; |
| 2360 | let end = Position { |
| 2361 | offset: range.end, |
| 2362 | line: 1 + subject[..range.end].matches('\n').count(), |
| 2363 | column: 1 + subject[..range.end] |
| 2364 | .chars() |
| 2365 | .rev() |
| 2366 | .position(|c| c == '\n') |
| 2367 | .unwrap_or(subject[..range.end].chars().count()), |
| 2368 | }; |
| 2369 | Span::new(start, end) |
| 2370 | } |
| 2371 | |
| 2372 | /// Create a verbatim literal starting at the given position. |
| 2373 | fn lit(c: char, start: usize) -> Ast { |