Skip to content

Commit a82eb45

Browse files
committed
Simplify whitespace skipping
1 parent ca13400 commit a82eb45

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/strnom.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ impl<'a> Cursor<'a> {
6969

7070
pub(crate) type PResult<'a, O> = Result<(Cursor<'a>, O), LexError>;
7171

72-
pub(crate) fn whitespace(input: Cursor) -> PResult<()> {
73-
if input.is_empty() {
74-
return Err(LexError);
75-
}
76-
72+
pub(crate) fn skip_whitespace(input: Cursor) -> Cursor {
7773
let bytes = input.as_bytes();
7874
let mut i = 0;
7975
while i < bytes.len() {
@@ -95,9 +91,13 @@ pub(crate) fn whitespace(input: Cursor) -> PResult<()> {
9591
&& (!s.starts_with("/**") || s.starts_with("/***"))
9692
&& !s.starts_with("/*!")
9793
{
98-
let (_, com) = block_comment(s)?;
99-
i += com.len();
100-
continue;
94+
match block_comment(s) {
95+
Ok((_, com)) => {
96+
i += com.len();
97+
continue;
98+
}
99+
Err(LexError) => return input,
100+
}
101101
}
102102
}
103103
match bytes[i] {
@@ -114,9 +114,9 @@ pub(crate) fn whitespace(input: Cursor) -> PResult<()> {
114114
}
115115
}
116116
}
117-
return if i > 0 { Ok((s, ())) } else { Err(LexError) };
117+
return s;
118118
}
119-
Ok((input.advance(input.len()), ()))
119+
input.advance(input.len())
120120
}
121121

122122
pub(crate) fn block_comment(input: Cursor) -> PResult<&str> {
@@ -144,13 +144,6 @@ pub(crate) fn block_comment(input: Cursor) -> PResult<&str> {
144144
Err(LexError)
145145
}
146146

147-
pub(crate) fn skip_whitespace(input: Cursor) -> Cursor {
148-
match whitespace(input) {
149-
Ok((rest, _)) => rest,
150-
Err(LexError) => input,
151-
}
152-
}
153-
154147
fn is_whitespace(ch: char) -> bool {
155148
// Rust treats left-to-right mark and right-to-left mark as whitespace
156149
ch.is_whitespace() || ch == '\u{200e}' || ch == '\u{200f}'

0 commit comments

Comments
 (0)