summaryrefslogtreecommitdiff
path: root/src/syntax/lines.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-01 01:38:18 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-01 01:38:18 +0200
commit4b9bc660281b2740c310bd9439493064017c9814 (patch)
tree609a44b34871c8582dffaf27cbb6636f1a869313 /src/syntax/lines.rs
parent38607b8bea1ede7a124c8fe384d7efca76f9f011 (diff)
Implement low-level char parser 🥜
Diffstat (limited to 'src/syntax/lines.rs')
-rw-r--r--src/syntax/lines.rs14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/syntax/lines.rs b/src/syntax/lines.rs
index 86fc461b..7f7ee049 100644
--- a/src/syntax/lines.rs
+++ b/src/syntax/lines.rs
@@ -3,7 +3,7 @@
use std::fmt::{self, Debug, Display, Formatter};
use super::Pos;
-use crate::parse::is_newline_char;
+use crate::parse::{is_newline_char, CharParser};
/// Enables conversion of byte position to locations.
pub struct LineMap<'s> {
@@ -15,17 +15,11 @@ impl<'s> LineMap<'s> {
/// Create a new line map for a source string.
pub fn new(src: &'s str) -> Self {
let mut line_starts = vec![Pos::ZERO];
- let mut iter = src.char_indices().peekable();
+ let mut p = CharParser::new(src);
- while let Some((mut i, c)) = iter.next() {
+ while let Some(c) = p.eat_merging_crlf() {
if is_newline_char(c) {
- i += c.len_utf8();
- if c == '\r' && matches!(iter.peek(), Some((_, '\n'))) {
- i += '\n'.len_utf8();
- iter.next();
- }
-
- line_starts.push(Pos(i as u32));
+ line_starts.push(p.index().into());
}
}