Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Nov 24, 2020
1 parent 36fabd7 commit bd1adeb
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/character/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ pub fn is_space(chr: u8) -> bool {
#[inline]
pub fn is_newline(chr: u8) -> bool {
chr == b'\n'
}
}
12 changes: 6 additions & 6 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ pub trait Finish<I, O, E> {
impl<I, O, E> Finish<I, O, E> for IResult<I, O, E> {
fn finish(self) -> Result<(I, O), E> {
match self {
Ok(res) => Ok(res),
Err(Err::Error(e)) | Err(Err::Failure(e)) => Err(e),
Err(Err::Incomplete(_)) => {
panic!("Cannot call `finish()` on `Err(Err::Incomplete(_))`: this result means that the parser does not have enough data to decide, you should gather more data and try to reapply the parser instead")
}
}
Ok(res) => Ok(res),
Err(Err::Error(e)) | Err(Err::Failure(e)) => Err(e),
Err(Err::Incomplete(_)) => {
panic!("Cannot call `finish()` on `Err(Err::Incomplete(_))`: this result means that the parser does not have enough data to decide, you should gather more data and try to reapply the parser instead")
}
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/multi/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,10 @@ mod tests {
let i_err_pos = &i[3..];
assert_eq!(
empty_sep(i),
Err(Err::Error(error_position!(i_err_pos, ErrorKind::SeparatedList)))
Err(Err::Error(error_position!(
i_err_pos,
ErrorKind::SeparatedList
)))
);
let res4 = vec![&b"abcd"[..], &b"abcd"[..]];
assert_eq!(multi(e), Ok((&b",ef"[..], res4)));
Expand Down
12 changes: 10 additions & 2 deletions src/multi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,11 @@ where
/// assert_eq!(parser("123123"), Ok(("123123", vec![])));
/// assert_eq!(parser(""), Ok(("", vec![])));
/// ```
pub fn fold_many0<I, O, E, F, G, R>(mut f: F, init: R, mut g: G) -> impl FnMut(I) -> IResult<I, R, E>
pub fn fold_many0<I, O, E, F, G, R>(
mut f: F,
init: R,
mut g: G,
) -> impl FnMut(I) -> IResult<I, R, E>
where
I: Clone + PartialEq,
F: Parser<I, O, E>,
Expand Down Expand Up @@ -804,7 +808,11 @@ where
/// assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Many1))));
/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Many1))));
/// ```
pub fn fold_many1<I, O, E, F, G, R>(mut f: F, init: R, mut g: G) -> impl FnMut(I) -> IResult<I, R, E>
pub fn fold_many1<I, O, E, F, G, R>(
mut f: F,
init: R,
mut g: G,
) -> impl FnMut(I) -> IResult<I, R, E>
where
I: Clone + PartialEq,
F: Parser<I, O, E>,
Expand Down
30 changes: 24 additions & 6 deletions src/regexp/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ macro_rules! re_bytes_find (
///
/// Requires the `regexp` feature.
#[macro_export(local_inner_macros)]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
macro_rules! re_matches (
($i:expr, $re:expr) => ( {
let r = $crate::lib::regex::Regex::new($re).unwrap();
Expand All @@ -68,7 +71,10 @@ macro_rules! re_matches (
///
/// Requires the `regexp` feature.
#[macro_export(local_inner_macros)]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
macro_rules! re_bytes_matches (
($i:expr, $re:expr) => ( {
let r = $crate::lib::regex::bytes::Regex::new($re).unwrap();
Expand All @@ -81,7 +87,10 @@ macro_rules! re_bytes_matches (
///
/// Requires the `regexp` feature.
#[macro_export(local_inner_macros)]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
macro_rules! re_capture (
($i:expr, $re:expr) => ( {
let r = $crate::lib::regex::Regex::new($re).unwrap();
Expand All @@ -94,7 +103,10 @@ macro_rules! re_capture (
///
/// Requires the `regexp` feature.
#[macro_export(local_inner_macros)]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
macro_rules! re_bytes_capture (
($i:expr, $re:expr) => ( {
let r = $crate::lib::regex::bytes::Regex::new($re).unwrap();
Expand All @@ -108,7 +120,10 @@ macro_rules! re_bytes_capture (
///
/// Requires the `regexp` feature.
#[macro_export(local_inner_macros)]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
macro_rules! re_captures (
($i:expr, $re:expr) => ( {
let r = $crate::lib::regex::Regex::new($re).unwrap();
Expand All @@ -121,7 +136,10 @@ macro_rules! re_captures (
///
/// Requires the `regexp` feature.
#[macro_export(local_inner_macros)]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
macro_rules! re_bytes_captures (
($i:expr, $re:expr) => ( {
let r = $crate::lib::regex::bytes::Regex::new($re).unwrap();
Expand Down
30 changes: 24 additions & 6 deletions src/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ pub mod str {
/// # }
/// ```
#[cfg(all(feature = "regexp", feature = "alloc"))]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
pub fn re_matches<'a, E>(re: Regex) -> impl Fn(&'a str) -> IResult<&'a str, Vec<&'a str>, E>
where
E: ParseError<&'a str>,
Expand Down Expand Up @@ -130,7 +133,10 @@ pub mod str {
/// # }
/// ```
#[cfg(all(feature = "regexp", feature = "alloc"))]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
pub fn re_capture<'a, E>(re: Regex) -> impl Fn(&'a str) -> IResult<&'a str, Vec<&'a str>, E>
where
E: ParseError<&'a str>,
Expand Down Expand Up @@ -171,7 +177,10 @@ pub mod str {
/// # }
/// ```
#[cfg(all(feature = "regexp", feature = "alloc"))]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
pub fn re_captures<'a, E>(re: Regex) -> impl Fn(&'a str) -> IResult<&'a str, Vec<Vec<&'a str>>, E>
where
E: ParseError<&'a str>,
Expand Down Expand Up @@ -361,7 +370,10 @@ pub mod bytes {
/// # }
/// ```
#[cfg(all(feature = "regexp", feature = "alloc"))]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
pub fn re_matches<'a, E>(re: Regex) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], Vec<&'a [u8]>, E>
where
E: ParseError<&'a [u8]>,
Expand Down Expand Up @@ -431,7 +443,10 @@ pub mod bytes {
/// # }
/// ```
#[cfg(all(feature = "regexp", feature = "alloc"))]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
pub fn re_capture<'a, E>(re: Regex) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], Vec<&'a [u8]>, E>
where
E: ParseError<&'a [u8]>,
Expand Down Expand Up @@ -472,7 +487,10 @@ pub mod bytes {
/// # }
/// ```
#[cfg(all(feature = "regexp", feature = "alloc"))]
#[cfg_attr(feature = "docsrs", doc(cfg(all(feature = "regexp", feature = "alloc"))))]
#[cfg_attr(
feature = "docsrs",
doc(cfg(all(feature = "regexp", feature = "alloc")))
)]
pub fn re_captures<'a, E>(
re: Regex,
) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], Vec<Vec<&'a [u8]>>, E>
Expand Down
19 changes: 7 additions & 12 deletions tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,11 @@ named!(issue_962<&[u8], Vec<&[u8]>>,

#[test]
fn issue_1231_bits_expect_fn_closure() {
use nom::bits::{bits, complete::take};
use nom::error::Error;
use nom::sequence::tuple;
pub fn example(input: &[u8]) -> IResult<&[u8], (u8, u8)> {
bits::<_, _, Error<_>, _, _>(tuple((
take(1usize), take(1usize)
)))(input)
}
assert_eq!(
example(&[0xff]),
Ok((&b""[..], (1, 1)))
);
use nom::bits::{bits, complete::take};
use nom::error::Error;
use nom::sequence::tuple;
pub fn example(input: &[u8]) -> IResult<&[u8], (u8, u8)> {
bits::<_, _, Error<_>, _, _>(tuple((take(1usize), take(1usize))))(input)
}
assert_eq!(example(&[0xff]), Ok((&b""[..], (1, 1))));
}

0 comments on commit bd1adeb

Please sign in to comment.