From 4dbd9285c91d59d527f4324df4aaf239ecb007ca Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 11 Jun 2021 14:00:06 +0200 Subject: Basic enums --- src/parse/parser.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/parse/parser.rs') 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(&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(&mut self, f: F) -> Option 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. -- cgit v1.2.3