Struct aoc_parser::prelude::Parser

source ·
pub struct Parser<'inp> { /* private fields */ }

Implementations§

source§

impl<'inp> Parser<'inp>

source

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>,

source

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>,

source

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>,

source

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,

source

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>

source

pub fn new(input_line: &'inp str) -> Parser<'inp>

source

pub fn new_lines(input_lines: &'inp [&'inp str]) -> Parser<'inp>

source

pub fn confirm(&mut self) -> &mut Self

source

pub fn set_ignore_whitespace(&mut self, ignore_whitespace: bool) -> &mut Self

source

pub fn set_word_pred(&mut self, word_pred: fn(_: char) -> bool) -> &mut Self

source

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

source

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

source

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

source

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

source

pub fn item<Item>(&mut self) -> ParseResult<Item>where Item: FromParser<'inp>,

source

pub fn item_range<Item>( &mut self, range: impl RangeBounds<Item> ) -> ParseResult<Item>where Item: FromParser<'inp> + PartialOrd,

source

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

source

pub fn word_into<'par, Output>(&'par mut self) -> ParseResult<Output>where Output: TryFrom<&'par str, Error = GenError>,

Consume and return a single word from the input, transforming it with TryInto

Errors

Returns Err (self.err ()) if there is no word remaining.

Returns Err (ParseError::Wrapped (err)) if the conversion fails.

source

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

source

pub fn peek_word(&mut self) -> Option<&'inp str>

Return a word from the input without consuming it

source

pub fn skip_whitespace( &mut self, range: impl RangeBounds<u32> ) -> ParseResult<&mut Self>

Consume any whitespace from the start of the remaining input

source

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.

source

pub fn next(&mut self) -> Option<char>

Consume and return the next character from the input

source

pub fn peek(&mut self) -> Option<char>

Return the next character from the input without consuming it

source

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.

source

pub const fn err(&self) -> ParseError

Return a ParseError with the current position

source

pub fn any<Item>(&mut self) -> ParserAny<'_, 'inp, Item>

source

pub fn wrap<Output, WrapFn>( input: &'inp str, wrap_fn: WrapFn ) -> ParseResult<Output>where WrapFn: FnMut(&mut Parser<'inp>) -> ParseResult<Output>,

source

pub fn wrap_auto<Output, WrapFn>( input: &'inp str, wrap_fn: WrapFn ) -> GenResult<Output>where WrapFn: for<'par1> FnMut(&'par1 mut Parser<'inp>) -> ParseResult<Output>,

source

pub fn wrap_lines_auto<Output, WrapFn>( input: impl Iterator<Item = (usize, &'inp str)>, wrap_fn: WrapFn ) -> GenResult<Vec<Output>>where WrapFn: FnMut(&mut Parser<'inp>) -> ParseResult<Output>,

source

pub fn wrap_lines<Output, WrapFn>( input_lines: &'inp [&'inp str], wrap_fn: WrapFn ) -> GenResult<Output>where WrapFn: FnMut(&mut Parser<'inp>) -> ParseResult<Output>,

source

pub fn wrap_lines_auto_items<Output: FromParser<'inp>>( input: impl Iterator<Item = (usize, &'inp str)> ) -> GenResult<Vec<Output>>

source

pub const fn peek_rest(&self) -> &'inp str

source

pub fn take_rest(&mut self) -> InpStr<'inp>

source

pub fn take_rest_while( &mut self, char_pred: fn(_: char) -> bool, len: impl RangeBounds<u32> ) -> ParseResult<InpStr<'inp>>

source

pub fn take_exactly(&mut self, num_chars: u32) -> ParseResult<InpStr<'inp>>

source

pub fn opt_fn<ParseFn, Output>(&mut self, parse_fn: ParseFn) -> Outputwhere Output: Default, ParseFn: FnMut(&mut Parser<'inp>) -> ParseResult<Output>,

source

pub fn nest<ParseFn, Output>( &mut self, parse_fn: ParseFn ) -> ParseResult<Output>where ParseFn: FnMut(&mut Parser<'inp>) -> ParseResult<Output>,

Trait Implementations§

source§

impl<'inp> Clone for Parser<'inp>

source§

fn clone(&self) -> Parser<'inp>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'inp> Copy for Parser<'inp>

Auto Trait Implementations§

§

impl<'inp> RefUnwindSafe for Parser<'inp>

§

impl<'inp> Send for Parser<'inp>

§

impl<'inp> Sync for Parser<'inp>

§

impl<'inp> Unpin for Parser<'inp>

§

impl<'inp> UnwindSafe for Parser<'inp>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<From, To> QuickInto<To> for Fromwhere To: QuickFrom<From>,

source§

fn quick_into(self) -> To

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.