From 4bd10f7e0c193dd91c0749a24181076d471177d6 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 12 Feb 2025 14:13:47 +0100 Subject: [PATCH] Add CharStream::skip_to_newline to replace eat_not_char --- src/sudoers/ast.rs | 2 +- src/sudoers/basic_parser.rs | 4 ++-- src/sudoers/char_stream.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sudoers/ast.rs b/src/sudoers/ast.rs index bc639c772..51518adc8 100644 --- a/src/sudoers/ast.rs +++ b/src/sudoers/ast.rs @@ -512,7 +512,7 @@ impl Parse for Sudo { // the failed "try_nonterminal::" will have consumed the '#' // the most ignominious part of sudoers: having to parse bits of comments parse_include(stream).or_else(|_| { - while stream.eat_not_char('\n') {} + stream.skip_to_newline(); make(Sudo::LineComment) }) }; diff --git a/src/sudoers/basic_parser.rs b/src/sudoers/basic_parser.rs index a26c02b80..00565e44e 100644 --- a/src/sudoers/basic_parser.rs +++ b/src/sudoers/basic_parser.rs @@ -139,7 +139,7 @@ impl Parse for Comment { if !stream.eat_char('#') { return Err(Status::Reject); } - while stream.eat_not_char('\n') {} + stream.skip_to_newline(); make(Comment {}) } } @@ -324,7 +324,7 @@ where let error = |stream: &mut CharStream| unrecoverable!(stream, "{msg}"); result.push(error(stream)); } - while stream.eat_not_char('\n') {} + stream.skip_to_newline(); } } diff --git a/src/sudoers/char_stream.rs b/src/sudoers/char_stream.rs index 59b314aab..53836f9e6 100644 --- a/src/sudoers/char_stream.rs +++ b/src/sudoers/char_stream.rs @@ -32,8 +32,8 @@ impl CharStream<'_> { self.next_if(|c| c == expect_char).is_some() } - pub fn eat_not_char(&mut self, expect_not_char: char) -> bool { - self.next_if(|c| c != expect_not_char).is_some() + pub fn skip_to_newline(&mut self) { + while self.next_if(|c| c != '\n').is_some() {} } pub fn peek(&mut self) -> Option {