Skip to content

Commit

Permalink
Add CharStream::skip_to_newline to replace eat_not_char
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Feb 12, 2025
1 parent c634760 commit 4bd10f7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/sudoers/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl Parse for Sudo {
// the failed "try_nonterminal::<Identifier>" 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)
})
};
Expand Down
4 changes: 2 additions & 2 deletions src/sudoers/basic_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {})
}
}
Expand Down Expand Up @@ -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();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/sudoers/char_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Expand Down

0 comments on commit 4bd10f7

Please sign in to comment.