summaryrefslogtreecommitdiff
path: root/src/parse/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse/parser.rs')
-rw-r--r--src/parse/parser.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/parse/parser.rs b/src/parse/parser.rs
index 27346587..8ea80d68 100644
--- a/src/parse/parser.rs
+++ b/src/parse/parser.rs
@@ -242,6 +242,16 @@ impl<'s> Parser<'s> {
}
}
+ /// Consume tokens while the condition is true.
+ pub fn eat_while<F>(&mut self, mut f: F)
+ where
+ F: FnMut(Token<'s>) -> bool,
+ {
+ while self.peek().map_or(false, |t| f(t)) {
+ self.eat();
+ }
+ }
+
/// Consume the next token if the closure maps it a to `Some`-variant.
pub fn eat_map<T, F>(&mut self, f: F) -> Option<T>
where
@@ -278,18 +288,6 @@ impl<'s> Parser<'s> {
debug_assert_eq!(next, Some(t));
}
- /// Skip whitespace and comment tokens.
- pub fn skip_white(&mut self) {
- while matches!(
- self.peek(),
- Some(Token::Space(_)) |
- Some(Token::LineComment(_)) |
- Some(Token::BlockComment(_))
- ) {
- self.eat();
- }
- }
-
/// The index at which the last token ended.
///
/// Refers to the end of the last _non-whitespace_ token in code mode.