Trait nom8::Parser

source ·
pub trait Parser<I, O, E> {
Show 20 methods // Required method fn parse(&mut self, input: I) -> IResult<I, O, E>; // Provided methods fn by_ref(&mut self) -> ByRef<'_, Self> where Self: Sized { ... } fn value<O2>(self, val: O2) -> Value<Self, O, O2> where Self: Sized, O2: Clone { ... } fn output_into<O2: From<O>>(self) -> OutputInto<Self, O, O2> where Self: Sized { ... } fn recognize(self) -> Recognize<Self, O> where Self: Sized { ... } fn with_recognized(self) -> WithRecognized<Self, O> where Self: Sized { ... } fn span(self) -> Span<Self, O> where Self: Sized, I: Location + Clone { ... } fn with_span(self) -> WithSpan<Self, O> where Self: Sized, I: Location + Clone { ... } fn map<G, O2>(self, g: G) -> Map<Self, G, O> where G: Fn(O) -> O2, Self: Sized { ... } fn map_res<G, O2, E2>(self, g: G) -> MapRes<Self, G, O> where Self: Sized, G: FnMut(O) -> Result<O2, E2> { ... } fn map_opt<G, O2>(self, g: G) -> MapOpt<Self, G, O> where Self: Sized, G: FnMut(O) -> Option<O2> { ... } fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O> where G: FnMut(O) -> H, H: Parser<I, O2, E>, Self: Sized { ... } fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O> where G: Parser<O, O2, E>, Self: Sized { ... } fn verify<G, O2: ?Sized>(self, second: G) -> Verify<Self, G, O2> where Self: Sized, G: Fn(&O2) -> bool { ... } fn context<C>(self, context: C) -> Context<Self, O, C> where Self: Sized, C: Clone, E: ContextError<I, C> { ... } fn complete(self) -> Complete<Self> where Self: Sized { ... } fn err_into<E2: From<E>>(self) -> ErrInto<Self, E, E2> where Self: Sized { ... } fn dbg_err<C>(self, context: C) -> DbgErr<Self, O, C> where C: Display, Self: Sized { ... } fn and<G, O2>(self, g: G) -> And<Self, G> where G: Parser<I, O2, E>, Self: Sized { ... } fn or<G>(self, g: G) -> Or<Self, G> where G: Parser<I, O, E>, Self: Sized { ... }
}
Expand description

All nom parsers implement this trait

The simplest way to implement a Parser is with a function

use nom8::prelude::*;

fn success(input: &str) -> IResult<&str, ()> {
    let output = ();
    Ok((input, output))
}

let (input, output) = success.parse("Hello").unwrap();
assert_eq!(input, "Hello");  // We didn't consume any input

which can be made stateful by returning a function

use nom8::prelude::*;

fn success<O: Clone>(output: O) -> impl FnMut(&str) -> IResult<&str, O> {
    move |input: &str| {
        let output = output.clone();
        Ok((input, output))
    }
}

let (input, output) = success("World").parse("Hello").unwrap();
assert_eq!(input, "Hello");  // We didn't consume any input
assert_eq!(output, "World");

Additionally, some basic types implement Parser as well, including

Required Methods§

source

fn parse(&mut self, input: I) -> IResult<I, O, E>

A parser takes in input type, and returns a Result containing either the remaining input and the output value, or an error

Provided Methods§

source

fn by_ref(&mut self) -> ByRef<'_, Self>where Self: Sized,

Treat &mut Self as a parser

This helps when needing to move a Parser when all you have is a &mut Parser.

Example

Because parsers are FnMut, they can be called multiple times. This prevents moving f into length_data and g into complete:

pub fn length_value<'i, O, E: ParseError<&'i [u8]>>(
    mut f: impl Parser<&'i [u8], usize, E>,
    mut g: impl Parser<&'i [u8], O, E>
) -> impl FnMut(&'i [u8]) -> IResult<&'i [u8], O, E> {
  move |i: &'i [u8]| {
    let (i, data) = length_data(f).parse(i)?;
    let (_, o) = g.complete().parse(data)?;
    Ok((i, o))
  }
}

By adding by_ref, we can make this work:

pub fn length_value<'i, O, E: ParseError<&'i [u8]>>(
    mut f: impl Parser<&'i [u8], usize, E>,
    mut g: impl Parser<&'i [u8], O, E>
) -> impl FnMut(&'i [u8]) -> IResult<&'i [u8], O, E> {
  move |i: &'i [u8]| {
    let (i, data) = length_data(f.by_ref()).parse(i)?;
    let (_, o) = g.by_ref().complete().parse(data)?;
    Ok((i, o))
  }
}
source

fn value<O2>(self, val: O2) -> Value<Self, O, O2>where Self: Sized, O2: Clone,

Returns the provided value if the child parser succeeds.

Example
use nom8::character::alpha1;

let mut parser = alpha1.value(1234);

assert_eq!(parser.parse("abcd"), Ok(("", 1234)));
assert_eq!(parser.parse("123abcd;"), Err(Err::Error(("123abcd;", ErrorKind::Alpha))));
source

fn output_into<O2: From<O>>(self) -> OutputInto<Self, O, O2>where Self: Sized,

Convert the parser’s output to another type using std::convert::From

Example
use nom8::character::alpha1;

 fn parser1(i: &str) -> IResult<&str, &str> {
   alpha1(i)
 }

 let mut parser2 = parser1.output_into();

// the parser converts the &str output of the child parser into a Vec<u8>
let bytes: IResult<&str, Vec<u8>> = parser2.parse("abcd");
assert_eq!(bytes, Ok(("", vec![97, 98, 99, 100])));
source

fn recognize(self) -> Recognize<Self, O>where Self: Sized,

If the child parser was successful, return the consumed input as produced value.

Example
use nom8::character::{alpha1};
use nom8::sequence::separated_pair;

let mut parser = separated_pair(alpha1, ',', alpha1).recognize();

assert_eq!(parser.parse("abcd,efgh"), Ok(("", "abcd,efgh")));
assert_eq!(parser.parse("abcd;"),Err(Err::Error((";", ErrorKind::OneOf))));
source

fn with_recognized(self) -> WithRecognized<Self, O>where Self: Sized,

if the child parser was successful, return the consumed input with the output as a tuple. Functions similarly to recognize except it returns the parser output as well.

This can be useful especially in cases where the output is not the same type as the input, or the input is a user defined type.

Returned tuple is of the format (produced output, consumed input).

Example
use nom8::character::{alpha1};
use nom8::bytes::tag;
use nom8::sequence::separated_pair;

fn inner_parser(input: &str) -> IResult<&str, bool> {
    tag("1234").value(true).parse(input)
}


let mut consumed_parser = separated_pair(alpha1, ',', alpha1).value(true).with_recognized();

assert_eq!(consumed_parser.parse("abcd,efgh1"), Ok(("1", (true, "abcd,efgh"))));
assert_eq!(consumed_parser.parse("abcd;"),Err(Err::Error((";", ErrorKind::OneOf))));

// the second output (representing the consumed input)
// should be the same as that of the `recognize` parser.
let mut recognize_parser = inner_parser.recognize();
let mut consumed_parser = inner_parser.with_recognized().map(|(output, consumed)| consumed);

assert_eq!(recognize_parser.parse("1234"), consumed_parser.parse("1234"));
assert_eq!(recognize_parser.parse("abcd"), consumed_parser.parse("abcd"));
source

fn span(self) -> Span<Self, O>where Self: Sized, I: Location + Clone,

If the child parser was successful, return the location of the consumed input as produced value.

Example
use nom8::input::Located;
use nom8::character::alpha1;
use nom8::sequence::separated_pair;

let mut parser = separated_pair(alpha1.span(), ',', alpha1.span());

assert_eq!(parser.parse(Located::new("abcd,efgh")).finish(), Ok((0..4, 5..9)));
assert_eq!(parser.parse(Located::new("abcd;")),Err(Err::Error((Located::new("abcd;").slice(4..), ErrorKind::OneOf))));
source

fn with_span(self) -> WithSpan<Self, O>where Self: Sized, I: Location + Clone,

if the child parser was successful, return the location of consumed input with the output as a tuple. Functions similarly to Parser::span except it returns the parser output as well.

This can be useful especially in cases where the output is not the same type as the input, or the input is a user defined type.

Returned tuple is of the format (produced output, consumed input).

Example
use nom8::input::Located;
use nom8::character::alpha1;
use nom8::bytes::tag;
use nom8::sequence::separated_pair;

fn inner_parser(input: Located<&str>) -> IResult<Located<&str>, bool> {
    tag("1234").value(true).parse(input)
}


let mut consumed_parser = separated_pair(alpha1.value(1).with_span(), ',', alpha1.value(2).with_span());

assert_eq!(consumed_parser.parse(Located::new("abcd,efgh")).finish(), Ok(((1, 0..4), (2, 5..9))));
assert_eq!(consumed_parser.parse(Located::new("abcd;")),Err(Err::Error((Located::new("abcd;").slice(4..), ErrorKind::OneOf))));

// the second output (representing the consumed input)
// should be the same as that of the `span` parser.
let mut recognize_parser = inner_parser.span();
let mut consumed_parser = inner_parser.with_span().map(|(output, consumed)| consumed);

assert_eq!(recognize_parser.parse(Located::new("1234")), consumed_parser.parse(Located::new("1234")));
assert_eq!(recognize_parser.parse(Located::new("abcd")), consumed_parser.parse(Located::new("abcd")));
source

fn map<G, O2>(self, g: G) -> Map<Self, G, O>where G: Fn(O) -> O2, Self: Sized,

Maps a function over the result of a parser

Example
use nom8::{Err,error::ErrorKind, IResult,Parser};
use nom8::character::digit1;

let mut parser = digit1.map(|s: &str| s.len());

// the parser will count how many characters were returned by digit1
assert_eq!(parser.parse("123456"), Ok(("", 6)));

// this will fail if digit1 fails
assert_eq!(parser.parse("abc"), Err(Err::Error(("abc", ErrorKind::Digit))));
source

fn map_res<G, O2, E2>(self, g: G) -> MapRes<Self, G, O>where Self: Sized, G: FnMut(O) -> Result<O2, E2>,

Applies a function returning a Result over the result of a parser.

Example
use nom8::character::digit1;

let mut parse = digit1.map_res(|s: &str| s.parse::<u8>());

// the parser will convert the result of digit1 to a number
assert_eq!(parse.parse("123"), Ok(("", 123)));

// this will fail if digit1 fails
assert_eq!(parse.parse("abc"), Err(Err::Error(("abc", ErrorKind::Digit))));

// this will fail if the mapped function fails (a `u8` is too small to hold `123456`)
assert_eq!(parse.parse("123456"), Err(Err::Error(("123456", ErrorKind::MapRes))));
source

fn map_opt<G, O2>(self, g: G) -> MapOpt<Self, G, O>where Self: Sized, G: FnMut(O) -> Option<O2>,

Applies a function returning an Option over the result of a parser.

Example
use nom8::character::digit1;

let mut parse = digit1.map_opt(|s: &str| s.parse::<u8>().ok());

// the parser will convert the result of digit1 to a number
assert_eq!(parse.parse("123"), Ok(("", 123)));

// this will fail if digit1 fails
assert_eq!(parse.parse("abc"), Err(Err::Error(("abc", ErrorKind::Digit))));

// this will fail if the mapped function fails (a `u8` is too small to hold `123456`)
assert_eq!(parse.parse("123456"), Err(Err::Error(("123456", ErrorKind::MapOpt))));
source

fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>where G: FnMut(O) -> H, H: Parser<I, O2, E>, Self: Sized,

Creates a second parser from the output of the first one, then apply over the rest of the input

Example
use nom8::bytes::take;
use nom8::number::u8;

let mut length_data = u8.flat_map(take);

assert_eq!(length_data.parse(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..])));
assert_eq!(length_data.parse(&[4, 0, 1, 2][..]), Err(Err::Error((&[0, 1, 2][..], ErrorKind::Eof))));
source

fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>where G: Parser<O, O2, E>, Self: Sized,

Applies a second parser over the output of the first one

Example
use nom8::character::digit1;
use nom8::bytes::take;

let mut digits = take(5u8).and_then(digit1);

assert_eq!(digits.parse("12345"), Ok(("", "12345")));
assert_eq!(digits.parse("123ab"), Ok(("", "123")));
assert_eq!(digits.parse("123"), Err(Err::Error(("123", ErrorKind::Eof))));
source

fn verify<G, O2: ?Sized>(self, second: G) -> Verify<Self, G, O2>where Self: Sized, G: Fn(&O2) -> bool,

Returns the result of the child parser if it satisfies a verification function.

The verification function takes as argument a reference to the output of the parser.

Example

let mut parser = alpha1.verify(|s: &str| s.len() == 4);

assert_eq!(parser.parse("abcd"), Ok(("", "abcd")));
assert_eq!(parser.parse("abcde"), Err(Err::Error(("abcde", ErrorKind::Verify))));
assert_eq!(parser.parse("123abcd;"),Err(Err::Error(("123abcd;", ErrorKind::Alpha))));
source

fn context<C>(self, context: C) -> Context<Self, O, C>where Self: Sized, C: Clone, E: ContextError<I, C>,

If parsing fails, add context to the error

This is used mainly to add user friendly information to errors when backtracking through a parse tree.

source

fn complete(self) -> Complete<Self>where Self: Sized,

Transforms Incomplete into Error

Example

let mut parser = take(5u8).complete();

assert_eq!(parser.parse(Streaming("abcdefg")), Ok((Streaming("fg"), "abcde")));
assert_eq!(parser.parse(Streaming("abcd")), Err(Err::Error((Streaming("abcd"), ErrorKind::Complete))));
source

fn err_into<E2: From<E>>(self) -> ErrInto<Self, E, E2>where Self: Sized,

Convert the parser’s error to another type using std::convert::From

source

fn dbg_err<C>(self, context: C) -> DbgErr<Self, O, C>where C: Display, Self: Sized,

Prints a message and the input if the parser fails.

The message prints the Error or Incomplete and the parser’s calling code.

It also displays the input in hexdump format

use nom8::prelude::*;
use nom8::{IResult, bytes::tag};

fn f(i: &[u8]) -> IResult<&[u8], &[u8]> {
  tag("abcd").dbg_err("alpha tag").parse(i)
}

let a = &b"efghijkl"[..];
f(a);

Will print the following message:

alpha tag: Error(Position(0, [101, 102, 103, 104, 105, 106, 107, 108])) at:
00000000        65 66 67 68 69 6a 6b 6c         efghijkl
source

fn and<G, O2>(self, g: G) -> And<Self, G>where G: Parser<I, O2, E>, Self: Sized,

👎Deprecated since 8.0.0: Replaced with `nom8::sequence::tuple

Applies a second parser after the first one, return their results as a tuple

WARNING: Deprecated, replaced with nom8::sequence::tuple

source

fn or<G>(self, g: G) -> Or<Self, G>where G: Parser<I, O, E>, Self: Sized,

👎Deprecated since 8.0.0: Replaced with `nom8::branch::alt

Applies a second parser over the input if the first one failed

WARNING: Deprecated, replaced with nom8::branch::alt

Trait Implementations§

source§

impl<'a, I, O, E> Parser<I, O, E> for Box<dyn Parser<I, O, E> + 'a>

source§

fn parse(&mut self, input: I) -> IResult<I, O, E>

A parser takes in input type, and returns a Result containing either the remaining input and the output value, or an error
source§

fn by_ref(&mut self) -> ByRef<'_, Self>where Self: Sized,

Treat &mut Self as a parser Read more
source§

fn value<O2>(self, val: O2) -> Value<Self, O, O2>where Self: Sized, O2: Clone,

Returns the provided value if the child parser succeeds. Read more
source§

fn output_into<O2: From<O>>(self) -> OutputInto<Self, O, O2>where Self: Sized,

Convert the parser’s output to another type using std::convert::From Read more
source§

fn recognize(self) -> Recognize<Self, O>where Self: Sized,

If the child parser was successful, return the consumed input as produced value. Read more
source§

fn with_recognized(self) -> WithRecognized<Self, O>where Self: Sized,

if the child parser was successful, return the consumed input with the output as a tuple. Functions similarly to recognize except it returns the parser output as well. Read more
source§

fn map<G, O2>(self, g: G) -> Map<Self, G, O>where G: Fn(O) -> O2, Self: Sized,

Maps a function over the result of a parser Read more
source§

fn map_res<G, O2, E2>(self, g: G) -> MapRes<Self, G, O>where Self: Sized, G: FnMut(O) -> Result<O2, E2>,

Applies a function returning a Result over the result of a parser. Read more
source§

fn map_opt<G, O2>(self, g: G) -> MapOpt<Self, G, O>where Self: Sized, G: FnMut(O) -> Option<O2>,

Applies a function returning an Option over the result of a parser. Read more
source§

fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>where G: FnMut(O) -> H, H: Parser<I, O2, E>, Self: Sized,

Creates a second parser from the output of the first one, then apply over the rest of the input Read more
source§

fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>where G: Parser<O, O2, E>, Self: Sized,

Applies a second parser over the output of the first one Read more
source§

fn verify<G, O2: ?Sized>(self, second: G) -> Verify<Self, G, O2>where Self: Sized, G: Fn(&O2) -> bool,

Returns the result of the child parser if it satisfies a verification function. Read more
source§

fn context<C>(self, context: C) -> Context<Self, O, C>where Self: Sized, C: Clone, E: ContextError<I, C>,

If parsing fails, add context to the error Read more
source§

fn complete(self) -> Complete<Self>where Self: Sized,

Transforms Incomplete into Error Read more
source§

fn err_into<E2: From<E>>(self) -> ErrInto<Self, E, E2>where Self: Sized,

Convert the parser’s error to another type using std::convert::From
source§

fn dbg_err<C>(self, context: C) -> DbgErr<Self, O, C>where C: Display, Self: Sized,

Prints a message and the input if the parser fails. Read more
source§

fn and<G, O2>(self, g: G) -> And<Self, G>where G: Parser<I, O2, E>, Self: Sized,

👎Deprecated since 8.0.0: Replaced with `nom8::sequence::tuple
Applies a second parser after the first one, return their results as a tuple Read more
source§

fn or<G>(self, g: G) -> Or<Self, G>where G: Parser<I, O, E>, Self: Sized,

👎Deprecated since 8.0.0: Replaced with `nom8::branch::alt
Applies a second parser over the input if the first one failed Read more

Implementations on Foreign Types§

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>,

source§

impl<I, O1, O2, E: ParseError<I>, P1, P2> Parser<I, (O1, O2), E> for (P1, P2)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>,

source§

fn parse(&mut self, i: I) -> IResult<I, (O1, O2), E>

source§

impl<I, O1, O2, O3, E: ParseError<I>, P1, P2, P3> Parser<I, (O1, O2, O3), E> for (P1, P2, P3)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>,

source§

fn parse(&mut self, i: I) -> IResult<I, (O1, O2, O3), E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>, P17: Parser<I, O17, E>, P18: Parser<I, O18, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>, P17: Parser<I, O17, E>, P18: Parser<I, O18, E>, P19: Parser<I, O19, E>,

source§

impl<I, E> Parser<I, <I as InputIter>::Item, E> for charwhere I: Slice<RangeFrom<usize>> + InputIter + InputLength + InputIsStreaming<false>, <I as InputIter>::Item: AsChar + Copy, E: ParseError<I>,

This is a shortcut for one_of.

Example

fn parser(i: &str) -> IResult<&str, char> {
    'a'.parse(i)
}
assert_eq!(parser("abc"), Ok(("bc", 'a')));
assert_eq!(parser(" abc"), Err(Err::Error(Error::new(" abc", ErrorKind::OneOf))));
assert_eq!(parser("bc"), Err(Err::Error(Error::new("bc", ErrorKind::OneOf))));
assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::OneOf))));
source§

fn parse(&mut self, i: I) -> IResult<I, <I as InputIter>::Item, E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>, P17: Parser<I, O17, E>,

source§

impl<I, O1, E: ParseError<I>, P1> Parser<I, (O1,), E> for (P1,)where P1: Parser<I, O1, E>,

source§

fn parse(&mut self, i: I) -> IResult<I, (O1,), E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, E: ParseError<I>, P1, P2, P3, P4, P5, P6> Parser<I, (O1, O2, O3, O4, O5, O6), E> for (P1, P2, P3, P4, P5, P6)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>,

source§

fn parse(&mut self, i: I) -> IResult<I, (O1, O2, O3, O4, O5, O6), E>

source§

impl<I, O1, O2, O3, O4, E: ParseError<I>, P1, P2, P3, P4> Parser<I, (O1, O2, O3, O4), E> for (P1, P2, P3, P4)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>,

source§

fn parse(&mut self, i: I) -> IResult<I, (O1, O2, O3, O4), E>

source§

impl<I, E> Parser<I, u8, E> for u8where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength + InputIsStreaming<false>, E: ParseError<I>,

This is a shortcut for one_of.

Example

fn parser(i: &[u8]) -> IResult<&[u8], u8> {
    b'a'.parse(i)
}
assert_eq!(parser(&b"abc"[..]), Ok((&b"bc"[..], b'a')));
assert_eq!(parser(&b" abc"[..]), Err(Err::Error(Error::new(&b" abc"[..], ErrorKind::OneOf))));
assert_eq!(parser(&b"bc"[..]), Err(Err::Error(Error::new(&b"bc"[..], ErrorKind::OneOf))));
assert_eq!(parser(&b""[..]), Err(Err::Error(Error::new(&b""[..], ErrorKind::OneOf))));
source§

fn parse(&mut self, i: I) -> IResult<I, u8, E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>,

source§

impl<'a, I, O, E> Parser<I, O, E> for Box<dyn Parser<I, O, E> + 'a>

source§

fn parse(&mut self, input: I) -> IResult<I, O, E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8), E> for (P1, P2, P3, P4, P5, P6, P7, P8)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>,

source§

impl<I, O1, O2, O3, O4, O5, E: ParseError<I>, P1, P2, P3, P4, P5> Parser<I, (O1, O2, O3, O4, O5), E> for (P1, P2, P3, P4, P5)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>,

source§

fn parse(&mut self, i: I) -> IResult<I, (O1, O2, O3, O4, O5), E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19, O20, O21, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19, O20, O21), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>, P17: Parser<I, O17, E>, P18: Parser<I, O18, E>, P19: Parser<I, O19, E>, P20: Parser<I, O20, E>, P21: Parser<I, O21, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7> Parser<I, (O1, O2, O3, O4, O5, O6, O7), E> for (P1, P2, P3, P4, P5, P6, P7)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>,

source§

fn parse(&mut self, i: I) -> IResult<I, (O1, O2, O3, O4, O5, O6, O7), E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>,

source§

impl<'s, I, E: ParseError<I>> Parser<I, <I as IntoOutput>::Output, E> for &'s [u8]where I: InputTake + InputLength + Compare<&'s [u8]> + InputIsStreaming<false> + IntoOutput,

This is a shortcut for tag.

Example


fn parser(s: &[u8]) -> IResult<&[u8], &[u8]> {
  alt((&"Hello"[..], take(5usize))).parse(s)
}

assert_eq!(parser(&b"Hello, World!"[..]), Ok((&b", World!"[..], &b"Hello"[..])));
assert_eq!(parser(&b"Something"[..]), Ok((&b"hing"[..], &b"Somet"[..])));
assert_eq!(parser(&b"Some"[..]), Err(Err::Error(Error::new(&b"Some"[..], ErrorKind::Eof))));
assert_eq!(parser(&b""[..]), Err(Err::Error(Error::new(&b""[..], ErrorKind::Eof))));
source§

fn parse(&mut self, i: I) -> IResult<I, <I as IntoOutput>::Output, E>

source§

impl<'s, I, E: ParseError<I>> Parser<I, <I as IntoOutput>::Output, E> for &'s strwhere I: InputTake + InputLength + Compare<&'s str> + InputIsStreaming<false> + IntoOutput,

This is a shortcut for tag.

Example


fn parser(s: &str) -> IResult<&str, &str> {
  alt(("Hello", take(5usize))).parse(s)
}

assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
assert_eq!(parser("Something"), Ok(("hing", "Somet")));
assert_eq!(parser("Some"), Err(Err::Error(Error::new("Some", ErrorKind::Eof))));
assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Eof))));
source§

fn parse(&mut self, i: I) -> IResult<I, <I as IntoOutput>::Output, E>

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>,

source§

impl<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19, O20, E: ParseError<I>, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20> Parser<I, (O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, O13, O14, O15, O16, O17, O18, O19, O20), E> for (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20)where P1: Parser<I, O1, E>, P2: Parser<I, O2, E>, P3: Parser<I, O3, E>, P4: Parser<I, O4, E>, P5: Parser<I, O5, E>, P6: Parser<I, O6, E>, P7: Parser<I, O7, E>, P8: Parser<I, O8, E>, P9: Parser<I, O9, E>, P10: Parser<I, O10, E>, P11: Parser<I, O11, E>, P12: Parser<I, O12, E>, P13: Parser<I, O13, E>, P14: Parser<I, O14, E>, P15: Parser<I, O15, E>, P16: Parser<I, O16, E>, P17: Parser<I, O17, E>, P18: Parser<I, O18, E>, P19: Parser<I, O19, E>, P20: Parser<I, O20, E>,

source§

impl<'s, I, E: ParseError<I>, const N: usize> Parser<I, <I as IntoOutput>::Output, E> for &'s [u8; N]where I: InputTake + InputLength + Compare<&'s [u8; N]> + InputIsStreaming<false> + IntoOutput,

This is a shortcut for tag.

Example


fn parser(s: &[u8]) -> IResult<&[u8], &[u8]> {
  alt((b"Hello", take(5usize))).parse(s)
}

assert_eq!(parser(&b"Hello, World!"[..]), Ok((&b", World!"[..], &b"Hello"[..])));
assert_eq!(parser(&b"Something"[..]), Ok((&b"hing"[..], &b"Somet"[..])));
assert_eq!(parser(&b"Some"[..]), Err(Err::Error(Error::new(&b"Some"[..], ErrorKind::Eof))));
assert_eq!(parser(&b""[..]), Err(Err::Error(Error::new(&b""[..], ErrorKind::Eof))));
source§

fn parse(&mut self, i: I) -> IResult<I, <I as IntoOutput>::Output, E>

source§

impl<I, E: ParseError<I>> Parser<I, (), E> for ()

source§

fn parse(&mut self, i: I) -> IResult<I, (), E>

Implementors§

source§

impl<'a, I, O1, O2, E, F: Parser<I, O1, E>, G: Fn(O1) -> H, H: Parser<I, O2, E>> Parser<I, O2, E> for FlatMap<F, G, O1>

source§

impl<'a, I, O1, O2, E, F: Parser<I, O1, E>, G: Fn(O1) -> O2> Parser<I, O2, E> for Map<F, G, O1>

source§

impl<'a, I, O1, O2, E, F: Parser<I, O1, E>, G: Parser<I, O2, E>> Parser<I, (O1, O2), E> for And<F, G>

source§

impl<'a, I, O1, O2, E, F: Parser<I, O1, E>, G: Parser<O1, O2, E>> Parser<I, O2, E> for AndThen<F, G, O1>

source§

impl<'a, I, O, E, F> Parser<I, O, E> for Fwhere F: FnMut(I) -> IResult<I, O, E> + 'a,

source§

impl<'a, I: Clone, O1, O2: From<O1>, E, F: Parser<I, O1, E>> Parser<I, O2, E> for OutputInto<F, O1, O2>

source§

impl<'a, I: Clone, O, E1, E2: ParseError<I> + From<E1>, F: Parser<I, O, E1>> Parser<I, O, E2> for ErrInto<F, E1, E2>

source§

impl<'a, I: Clone, O, E: ParseError<I>, F: Parser<I, O, E>, G: Parser<I, O, E>> Parser<I, O, E> for Or<F, G>

source§

impl<'p, I, O, E, P: Parser<I, O, E>> Parser<I, O, E> for ByRef<'p, P>

source§

impl<F, I, O, E> Parser<I, O, E> for Complete<F>where I: Clone, F: Parser<I, O, E>, E: ParseError<I>,

source§

impl<I, O1, O2, E, E2, F, G> Parser<I, O2, E> for MapRes<F, G, O1>where I: Clone, F: Parser<I, O1, E>, G: FnMut(O1) -> Result<O2, E2>, E: FromExternalError<I, E2>,

source§

impl<I, O1, O2, E, F, G> Parser<I, O1, E> for Verify<F, G, O2>where I: Clone, E: ParseError<I>, F: Parser<I, O1, E>, G: Fn(&O2) -> bool, O1: Borrow<O2>, O2: ?Sized,

source§

impl<I, O1, O2, E, F, G> Parser<I, O2, E> for MapOpt<F, G, O1>where I: Clone, F: Parser<I, O1, E>, G: FnMut(O1) -> Option<O2>, E: ParseError<I>,

source§

impl<I, O1, O2: Clone, E: ParseError<I>, F: Parser<I, O1, E>> Parser<I, O2, E> for Value<F, O1, O2>

source§

impl<I, O, E, F> Parser<I, <I as IntoOutput>::Output, E> for Recognize<F, O>where I: Clone + Offset + Slice<RangeTo<usize>> + IntoOutput, E: ParseError<I>, F: Parser<I, O, E>,

source§

impl<I, O, E, F> Parser<I, (O, <I as IntoOutput>::Output), E> for WithRecognized<F, O>where I: Clone + Offset + Slice<RangeTo<usize>> + IntoOutput, E: ParseError<I>, F: Parser<I, O, E>,

source§

impl<I, O, E, F> Parser<I, (O, Range<usize>), E> for WithSpan<F, O>where I: Clone + Location, E: ParseError<I>, F: Parser<I, O, E>,

source§

impl<I, O, E, F> Parser<I, Range<usize>, E> for Span<F, O>where I: Clone + Location, E: ParseError<I>, F: Parser<I, O, E>,

source§

impl<I, O, E, F, C> Parser<I, O, E> for Context<F, O, C>where I: Clone, C: Clone, E: ContextError<I, C>, F: Parser<I, O, E>,

source§

impl<I, O, E, F, C> Parser<I, O, E> for DbgErr<F, O, C>where I: AsBytes + Clone, E: Debug, F: Parser<I, O, E>, C: Display,