commit 91d61b7ec3c46b9769f0562810f1f6bfd8a78b08 parent 7ab1d6432e51c50d90174cc1e5a3d97bff97cfc0 Author: William Casarin <jb55@jb55.com> Date: Thu, 6 Jul 2023 22:10:08 -0700 parser: add parse_char This is handy for parsing specific characters Diffstat:
M | src/parser.rs | | | 11 | +++++++++++ |
1 file changed, 11 insertions(+), 0 deletions(-)
diff --git a/src/parser.rs b/src/parser.rs @@ -117,6 +117,17 @@ impl<'a> Parser<'a> { Ok(number) } + /// Parser a specific character. If not found, do not advance the parser. + pub fn parse_char(&mut self, matching: char) -> Result<()> { + let start = self.pos(); + let c = self.pull_char()?; + if c == matching { + return Ok(()); + } + self.set_pos(start); + return Err(Error::NotFound); + } + pub fn peek_char(&mut self) -> Result<char> { let peek = true; self.pull_or_peek_char(peek)