diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-06-11 14:00:06 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-06-11 14:00:06 +0200 |
| commit | 4dbd9285c91d59d527f4324df4aaf239ecb007ca (patch) | |
| tree | 561a9a18a1eea6a2e598157f305667c4ea8e3e08 /src/parse/parser.rs | |
| parent | 3330767c20e14a05176902a93dcefb08cb509173 (diff) | |
Basic enums
Diffstat (limited to 'src/parse/parser.rs')
| -rw-r--r-- | src/parse/parser.rs | 22 |
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. |
