Struct aoc_parser::prelude::Parser
source · pub struct Parser<'inp> { /* private fields */ }
Implementations§
source§impl<'inp> Parser<'inp>
impl<'inp> Parser<'inp>
pub fn delim_fn<'par0, Delim, Output, ParseFn>( &'par0 mut self, delim: Delim, parse_fn: ParseFn ) -> ParserDelim<'par0, 'inp, Delim, Output, ParseFn> ⓘwhere Delim: ParseDelimiter, ParseFn: FnMut(&mut Parser<'inp>) -> ParseResult<Output>,
pub fn repeat<'par, Output, ParseFn>( &'par mut self, parse_fn: ParseFn ) -> ParserRepeat<'par, 'inp, Output, ParseFn> ⓘwhere ParseFn: FnMut(&mut Parser<'inp>) -> ParseResult<Output>,
pub fn delim_items<'par, Delim, Output, ParseFn>( &'par mut self, delim: Delim ) -> ParserDelim<'par, 'inp, Delim, Output, impl FnMut(&mut Parser<'inp>) -> ParseResult<Output>> ⓘwhere Delim: ParseDelimiter, Output: FromParser<'inp>,
pub fn delim_uints<'par, Delim, Output: FromStr>( &'par mut self, delim: Delim ) -> ParserDelim<'par, 'inp, Delim, Output, impl FnMut(&mut Parser<'inp>) -> ParseResult<Output>> ⓘwhere Delim: ParseDelimiter,
pub fn delim_ints<'par, Delim, Output: FromStr + 'static>( &'par mut self, delim: Delim ) -> ParserDelim<'par, 'inp, Delim, Output, impl FnMut(&mut Parser<'inp>) -> ParseResult<Output>> ⓘwhere Delim: ParseDelimiter,
source§impl<'inp> Parser<'inp>
impl<'inp> Parser<'inp>
pub fn new(input_line: &'inp str) -> Parser<'inp>
pub fn new_lines(input_lines: &'inp [&'inp str]) -> Parser<'inp>
pub fn confirm(&mut self) -> &mut Self
pub fn set_ignore_whitespace(&mut self, ignore_whitespace: bool) -> &mut Self
pub fn set_word_pred(&mut self, word_pred: fn(_: char) -> bool) -> &mut Self
sourcepub fn expect(&mut self, expect: &str) -> ParseResult<&mut Self>
pub fn expect(&mut self, expect: &str) -> ParseResult<&mut Self>
Consume a specific string from the input
Errors
Returns Err (self.err ())
if the input does not match the specified value
sourcepub fn expect_word(&mut self, expect: &str) -> ParseResult<&mut Self>
pub fn expect_word(&mut self, expect: &str) -> ParseResult<&mut Self>
Consume a specific word from the input
Errors
Returns Err (self.err ())
if the input does not match the specified value
sourcepub fn int<IntType>(&mut self) -> ParseResult<IntType>where
IntType: FromStr,
pub fn int<IntType>(&mut self) -> ParseResult<IntType>where IntType: FromStr,
Consume and return a decimal integer from the input
This consumes a string of the form [-+]?[0-9]+ from the input and calls str::parse
to
convert it to the specified type.
Errors
Returns Err (self.err ())
if parse
returns an Err
sourcepub fn uint<IntType>(&mut self) -> ParseResult<IntType>where
IntType: FromStr,
pub fn uint<IntType>(&mut self) -> ParseResult<IntType>where IntType: FromStr,
Consume and return an unsigned decimal integer from the input
This consumes a string of the form [0-9]+ from the input and calls str::parse
to
convert it to the specified type.
This will actually work with signed integers, although note that it will only match digits and never a leading minus sign.
Errors
Returns Err (self.err ())
if parse
returns an Err
pub fn item<Item>(&mut self) -> ParseResult<Item>where Item: FromParser<'inp>,
pub fn item_range<Item>( &mut self, range: impl RangeBounds<Item> ) -> ParseResult<Item>where Item: FromParser<'inp> + PartialOrd,
sourcepub fn word(&mut self) -> ParseResult<&'inp str>
pub fn word(&mut self) -> ParseResult<&'inp str>
Consume and return a single word from the input
Errors
Returns Err (self.err ())
if there is no word remaining
sourcepub fn word_into<'par, Output>(&'par mut self) -> ParseResult<Output>where
Output: TryFrom<&'par str, Error = GenError>,
pub fn word_into<'par, Output>(&'par mut self) -> ParseResult<Output>where Output: TryFrom<&'par str, Error = GenError>,
sourcepub fn word_if<'par_1>(
&'par_1 mut self,
pred: impl FnOnce(&'inp str) -> bool
) -> ParseResult<&'inp str>
pub fn word_if<'par_1>( &'par_1 mut self, pred: impl FnOnce(&'inp str) -> bool ) -> ParseResult<&'inp str>
Consume and return a single word from the input, validating it with the provided function
Errors
Returns Err (self.err ())
if there is no word remaining, or if the provided predicate
function returns false
sourcepub fn peek_word(&mut self) -> Option<&'inp str>
pub fn peek_word(&mut self) -> Option<&'inp str>
Return a word from the input without consuming it
sourcepub fn skip_whitespace(
&mut self,
range: impl RangeBounds<u32>
) -> ParseResult<&mut Self>
pub fn skip_whitespace( &mut self, range: impl RangeBounds<u32> ) -> ParseResult<&mut Self>
Consume any whitespace from the start of the remaining input
sourcepub fn end(&mut self) -> ParseResult<()>
pub fn end(&mut self) -> ParseResult<()>
Assert that there is no more input to consume
Errors
Returns Err (self.err ())
if there is more input.
sourcepub fn peek(&mut self) -> Option<char>
pub fn peek(&mut self) -> Option<char>
Return the next character from the input without consuming it
sourcepub fn expect_next(&mut self) -> ParseResult<char>
pub fn expect_next(&mut self) -> ParseResult<char>
Consume and return the next character from the input
Errors
Will return Err (self.err ())
if there is no input remaining.
sourcepub const fn err(&self) -> ParseError
pub const fn err(&self) -> ParseError
Return a ParseError
with the current position