pub struct Parser<'input> {
pub pos: usize,
/* private fields */
}Expand description
A byte parser that recognizes Patterns
Fields§
§pos: usizeThe parser’s current position within the input
Implementations§
source§impl<'i> Parser<'i>
impl<'i> Parser<'i>
sourcepub fn new(input: &'i [u8]) -> Self
pub fn new(input: &'i [u8]) -> Self
Returns a new instance of Parser that will operate on input
sourcepub fn advance(&mut self, step: usize)
pub fn advance(&mut self, step: usize)
Advances the parser by step. Does nothing if the parser is at the end of the input
sourcepub fn eof(&self) -> bool
pub fn eof(&self) -> bool
Returns true if the parser reached the end of its input. Returns false otherwise
sourcepub fn try_match(&mut self, pattern: impl Pattern) -> Option<&'i [u8]>
pub fn try_match(&mut self, pattern: impl Pattern) -> Option<&'i [u8]>
Tests pattern against the remaining input. If the pattern matches, the matching portion
is returned and the parser is advanced by the length of the matched slice.
Returns None if the pattern does not match.
sourcepub fn peek_match(&self, pattern: impl Pattern) -> Option<&'i [u8]>
pub fn peek_match(&self, pattern: impl Pattern) -> Option<&'i [u8]>
Tests pattern against the remaining input but does not advance the parser. The matching
portion is returned.
You can use Parser::assert later to advance the parser with the same pattern.
sourcepub fn assert(&mut self, pattern: impl Pattern) -> &'i [u8] ⓘ
pub fn assert(&mut self, pattern: impl Pattern) -> &'i [u8] ⓘ
Similar to Parser::try_match, but panics if the pattern does not match.
This could be useful when you have previously peeked at the input (perhaps by using
Pattern::test or Parser::peek_match) and later want to advance the parser