Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to nom v8.0 #98

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ stable-deref-trait = ["stable_deref_trait"]
[dependencies]
bytecount = "^0.6"
memchr = { version = ">=1.0.1, <3.0.0", default-features = false } # ^1.0.0 + ^2.0
nom = { version = "7", default-features = false }
nom = { version = "8", default-features = false }
stable_deref_trait = { version = "^1", optional = true, default-features = false }
4 changes: 1 addition & 3 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
LocatedSpan has been designed to wrap any input type. By default it wraps `&str` and `&[u8]` but it should work with any other types.

To do so, all you need is to ensure that your input type implements these traits:
- `nom::InputLength`
- `nom::Slice`
- `nom::InputIter`
- `nom::Input`
- `nom::Compare`
- `nom::Offset`
- `nom::CompareResult`
Expand Down
3 changes: 1 addition & 2 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![feature(test)]
extern crate test;

use nom::Slice;
use nom_locate::LocatedSpan;
use nom_locate::{LocatedSpan, SliceInput};

use test::Bencher;

Expand Down
185 changes: 104 additions & 81 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@
pub mod std {
pub use std::fmt::{Display, Formatter, Result as FmtResult};
pub use std::hash::{Hash, Hasher};
pub use std::iter::{Copied, Enumerate};

Check warning on line 81 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused imports: `Copied` and `Enumerate`

Check warning on line 81 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused imports: `Copied` and `Enumerate`
pub use std::ops::{Range, RangeFrom, RangeFull, RangeTo};
pub use std::ops::{Bound, Range, RangeBounds, RangeFrom, RangeFull, RangeTo};

Check warning on line 82 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused imports: `RangeFrom`, `RangeFull`, `RangeTo`, and `Range`

Check warning on line 82 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused imports: `RangeFrom`, `RangeFull`, `RangeTo`, and `Range`
pub use std::slice;
pub use std::slice::Iter;

Check warning on line 84 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused import: `std::slice::Iter`

Check warning on line 84 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused import: `std::slice::Iter`
pub use std::str::{CharIndices, Chars, FromStr};

Check warning on line 85 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused imports: `CharIndices` and `Chars`

Check warning on line 85 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused imports: `CharIndices` and `Chars`
pub use std::string::{String, ToString};

Check warning on line 86 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused import: `String`

Check warning on line 86 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused import: `String`
pub use std::vec::Vec;

Check warning on line 87 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused import: `std::vec::Vec`

Check warning on line 87 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused import: `std::vec::Vec`
}

#[cfg(not(feature = "std"))]
Expand All @@ -92,15 +92,15 @@
#[cfg(feature = "alloc")]
pub use alloc::fmt::{Display, Formatter, Result as FmtResult};
#[cfg(feature = "alloc")]
pub use alloc::string::{String, ToString};

Check warning on line 95 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused import: `String`

Check warning on line 95 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused import: `String`
#[cfg(feature = "alloc")]
pub use alloc::vec::Vec;

Check warning on line 97 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused import: `alloc::vec::Vec`

Check warning on line 97 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused import: `alloc::vec::Vec`
pub use core::hash::{Hash, Hasher};
pub use core::iter::{Copied, Enumerate};

Check warning on line 99 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unused imports: `Copied` and `Enumerate`

Check warning on line 99 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unused imports: `Copied` and `Enumerate`

Check warning on line 99 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused imports: `Copied` and `Enumerate`

Check warning on line 99 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused imports: `Copied` and `Enumerate`
pub use core::ops::{Range, RangeFrom, RangeFull, RangeTo};
pub use core::ops::{Bound, Range, RangeBounds, RangeFrom, RangeFull, RangeTo};

Check warning on line 100 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unused imports: `RangeFrom`, `RangeFull`, `RangeTo`, and `Range`

Check warning on line 100 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unused imports: `RangeFrom`, `RangeFull`, `RangeTo`, and `Range`

Check warning on line 100 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused imports: `RangeFrom`, `RangeFull`, `RangeTo`, and `Range`

Check warning on line 100 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused imports: `RangeFrom`, `RangeFull`, `RangeTo`, and `Range`
pub use core::slice;
pub use core::slice::Iter;

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unused import: `core::slice::Iter`

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unused import: `core::slice::Iter`

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused import: `core::slice::Iter`

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused import: `core::slice::Iter`
pub use core::str::{CharIndices, Chars, FromStr};

Check warning on line 103 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unused imports: `CharIndices` and `Chars`

Check warning on line 103 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unused imports: `CharIndices` and `Chars`

Check warning on line 103 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused imports: `CharIndices` and `Chars`

Check warning on line 103 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused imports: `CharIndices` and `Chars`
}
}

Expand All @@ -112,8 +112,8 @@
use nom::ExtendInto;
use nom::{
error::{ErrorKind, ParseError},
AsBytes, Compare, CompareResult, Err, FindSubstring, FindToken, IResult, InputIter,
InputLength, InputTake, InputTakeAtPosition, Offset, ParseTo, Slice,
AsBytes, Compare, CompareResult, Err, FindSubstring, FindToken, IResult, Input, Offset,
ParseTo,
};
#[cfg(feature = "stable-deref-trait")]
use stable_deref_trait::StableDeref;
Expand Down Expand Up @@ -288,13 +288,13 @@
/// use nom::{
/// IResult,
/// combinator::{recognize, map_res},
/// sequence::{terminated, tuple},

Check warning on line 291 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

use of deprecated function `nom::sequence::tuple`: `Parser` is directly implemented for tuples

Check warning on line 291 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

use of deprecated function `nom::sequence::tuple`: `Parser` is directly implemented for tuples
/// character::{complete::{char, one_of}, is_digit},
/// bytes::complete::{tag, take_while1}
/// };
///
/// fn decimal(input: LocatedSpan<&str>) -> IResult<LocatedSpan<&str>, LocatedSpan<&str>> {
/// recognize(

Check failure on line 297 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

expected function, found `impl Parser<_, Output = _, Error = _>`

Check failure on line 297 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

expected function, found `impl Parser<_, Output = _, Error = _>`
/// take_while1(|c| is_digit(c as u8) || c == '_')
/// )(input)
/// }
Expand Down Expand Up @@ -401,7 +401,7 @@
/// # extern crate nom_locate;
/// # extern crate nom;
/// # use nom_locate::LocatedSpan;
/// # use nom::{Slice, FindSubstring};

Check failure on line 404 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unresolved import `nom::Slice`

Check failure on line 404 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unresolved import `nom::Slice`

Check failure on line 404 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unresolved import `nom::Slice`
/// #
/// # fn main() {
/// let program = LocatedSpan::new(
Expand All @@ -411,7 +411,7 @@
/// let multi = program.find_substring("multi").unwrap();
///
/// assert_eq!(
/// program.slice(multi..).get_line_beginning(),

Check failure on line 414 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

no method named `slice` found for struct `LocatedSpan<&str>` in the current scope

Check failure on line 414 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

no method named `slice` found for struct `LocatedSpan<&str>` in the current scope
/// "This is a multi-line input".as_bytes(),
/// );
/// # }
Expand All @@ -435,12 +435,12 @@
/// # extern crate nom_locate;
/// # extern crate nom;
/// # use nom_locate::LocatedSpan;
/// # use nom::Slice;

Check failure on line 438 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unresolved import `nom::Slice`

Check failure on line 438 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unresolved import `nom::Slice`

Check failure on line 438 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unresolved import `nom::Slice`
/// #
/// # fn main() {
/// let span = LocatedSpan::new("foobar");
///
/// assert_eq!(span.slice(3..).get_column(), 4);

Check failure on line 443 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

no method named `slice` found for struct `LocatedSpan<&str>` in the current scope

Check failure on line 443 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

no method named `slice` found for struct `LocatedSpan<&str>` in the current scope

Check failure on line 443 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

no method named `slice` found for struct `LocatedSpan<&str>` in the current scope
/// # }
/// ```
pub fn get_column(&self) -> usize {
Expand All @@ -461,14 +461,14 @@
/// # extern crate nom_locate;
/// # extern crate nom;
/// # use nom_locate::LocatedSpan;
/// # use nom::{Slice, FindSubstring};

Check failure on line 464 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unresolved import `nom::Slice`

Check failure on line 464 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unresolved import `nom::Slice`

Check failure on line 464 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unresolved import `nom::Slice`
/// #
/// # fn main() {
/// let span = LocatedSpan::new("メカジキ");
/// let indexOf3dKanji = span.find_substring("ジ").unwrap();
///
/// assert_eq!(span.slice(indexOf3dKanji..).get_column(), 7);

Check failure on line 470 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

no method named `slice` found for struct `LocatedSpan<&str>` in the current scope

Check failure on line 470 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

no method named `slice` found for struct `LocatedSpan<&str>` in the current scope

Check failure on line 470 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

no method named `slice` found for struct `LocatedSpan<&str>` in the current scope
/// assert_eq!(span.slice(indexOf3dKanji..).get_utf8_column(), 3);

Check failure on line 471 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

no method named `slice` found for struct `LocatedSpan<&str>` in the current scope

Check failure on line 471 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

no method named `slice` found for struct `LocatedSpan<&str>` in the current scope
/// # }
/// ```
pub fn get_utf8_column(&self) -> usize {
Expand Down Expand Up @@ -532,31 +532,92 @@
}
}

impl<T: InputLength, X> InputLength for LocatedSpan<T, X> {
fn input_len(&self) -> usize {
self.fragment.input_len()
impl<T, X> LocatedSpan<T, X>
where
T: Input + Clone + Offset + AsBytes,
X: Clone,
{
fn split_with(self: &LocatedSpan<T, X>, next_fragment: T) -> LocatedSpan<T, X>
where
T: Input + Clone + Offset + AsBytes,
X: Clone,
{
let consumed_len = self.fragment.offset(&next_fragment);
if consumed_len == 0 {
return LocatedSpan {
line: self.line,
offset: self.offset,
fragment: next_fragment,
extra: self.extra.clone(),
};
}

let consumed = self.fragment.take(consumed_len);

let next_offset = self.offset + consumed_len;

let consumed_as_bytes = consumed.as_bytes();
let iter = Memchr::new(b'\n', consumed_as_bytes);
let number_of_lines = iter.count() as u32;
let next_line = self.line + number_of_lines;

LocatedSpan {
line: next_line,
offset: next_offset,
fragment: next_fragment,
extra: self.extra.clone(),
}
}
}

impl<T, X> InputTake for LocatedSpan<T, X>
impl<T, X> Input for LocatedSpan<T, X>
where
Self: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
T: Input + Clone + Offset + AsBytes,
X: Clone,
{
type Item = T::Item;
type Iter = T::Iter;
type IterIndices = T::IterIndices;

fn input_len(&self) -> usize {
self.fragment.input_len()
}

fn take(&self, count: usize) -> Self {
self.slice(..count)
self.split_with(self.fragment.take(count))
}

fn take_split(&self, count: usize) -> (Self, Self) {
(self.slice(count..), self.slice(..count))
let (before, after) = self.fragment.take_split(count);
(self.split_with(before), self.split_with(after))
}
}

impl<T, X> InputTakeAtPosition for LocatedSpan<T, X>
where
T: InputTakeAtPosition + InputLength + InputIter,
Self: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Clone,
{
type Item = <T as InputIter>::Item;
fn take_from(&self, index: usize) -> Self {
self.split_with(self.fragment.take_from(index))
}

#[inline]
fn iter_indices(&self) -> Self::IterIndices {
self.fragment.iter_indices()
}

#[inline]
fn iter_elements(&self) -> Self::Iter {
self.fragment.iter_elements()
}

#[inline]
fn position<P>(&self, predicate: P) -> Option<usize>
where
P: Fn(Self::Item) -> bool,
{
self.fragment.position(predicate)
}

#[inline]
fn slice_index(&self, count: usize) -> Result<usize, nom::Needed> {
self.fragment.slice_index(count)
}

fn split_at_position_complete<P, E: ParseError<Self>>(
&self,
Expand Down Expand Up @@ -618,6 +679,30 @@
}
}

pub trait SliceInput {
fn slice(&self, range: impl RangeBounds<usize>) -> Self;
}

impl<I: Input> SliceInput for I {
fn slice(&self, range: impl RangeBounds<usize>) -> I {
let start = match range.start_bound() {
Bound::Included(&n) => n,
Bound::Excluded(&n) => n + 1,
Bound::Unbounded => 0,
};
let end = match range.end_bound() {
Bound::Included(&n) => n + 1,
Bound::Excluded(&n) => n,
Bound::Unbounded => self.input_len(),
};
if start == 0 {
self.take(end)
} else {
self.take_from(start).take(end - start)
}
}
}

#[macro_export]
#[deprecated(
since = "3.1.0",
Expand All @@ -627,34 +712,6 @@
() => {};
}

impl<'a, T, X> InputIter for LocatedSpan<T, X>
where
T: InputIter,
{
type Item = T::Item;
type Iter = T::Iter;
type IterElem = T::IterElem;
#[inline]
fn iter_indices(&self) -> Self::Iter {
self.fragment.iter_indices()
}
#[inline]
fn iter_elements(&self) -> Self::IterElem {
self.fragment.iter_elements()
}
#[inline]
fn position<P>(&self, predicate: P) -> Option<usize>
where
P: Fn(Self::Item) -> bool,
{
self.fragment.position(predicate)
}
#[inline]
fn slice_index(&self, count: usize) -> Result<usize, nom::Needed> {
self.fragment.slice_index(count)
}
}

impl<A: Compare<B>, B: Into<LocatedSpan<B>>, X> Compare<B> for LocatedSpan<A, X> {
#[inline(always)]
fn compare(&self, t: B) -> CompareResult {
Expand Down Expand Up @@ -694,40 +751,6 @@
( $fragment_type:ty ) => {};
}

impl<'a, T, R, X: Clone> Slice<R> for LocatedSpan<T, X>
where
T: Slice<R> + Offset + AsBytes + Slice<RangeTo<usize>>,
{
fn slice(&self, range: R) -> Self {
let next_fragment = self.fragment.slice(range);
let consumed_len = self.fragment.offset(&next_fragment);
if consumed_len == 0 {
return LocatedSpan {
line: self.line,
offset: self.offset,
fragment: next_fragment,
extra: self.extra.clone(),
};
}

let consumed = self.fragment.slice(..consumed_len);

let next_offset = self.offset + consumed_len;

let consumed_as_bytes = consumed.as_bytes();
let iter = Memchr::new(b'\n', consumed_as_bytes);
let number_of_lines = iter.count() as u32;
let next_line = self.line + number_of_lines;

LocatedSpan {
line: next_line,
offset: next_offset,
fragment: next_fragment,
extra: self.extra.clone(),
}
}
}

impl<Fragment: FindToken<Token>, Token, X> FindToken<Token> for LocatedSpan<Fragment, X> {
fn find_token(&self, token: Token) -> bool {
self.fragment.find_token(token)
Expand Down Expand Up @@ -835,7 +858,7 @@
pub fn position<T, E>(s: T) -> IResult<T, T, E>
where
E: ParseError<T>,
T: InputIter + InputTake,
T: Input,
{
nom::bytes::complete::take(0usize)(s)
}
7 changes: 2 additions & 5 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ mod lib {
}
}

use super::{LocatedSpan, SliceInput};
#[cfg(feature = "alloc")]
use lib::std::*;

use super::LocatedSpan;
#[cfg(feature = "alloc")]
use nom::ParseTo;
use nom::{
error::ErrorKind, Compare, CompareResult, FindSubstring, FindToken, InputIter, InputTake,
InputTakeAtPosition, Offset, Slice,
};
use nom::{error::ErrorKind, Compare, CompareResult, FindSubstring, FindToken, Input, Offset};

type StrSpan<'a> = LocatedSpan<&'a str>;
type BytesSpan<'a> = LocatedSpan<&'a [u8]>;
Expand Down
39 changes: 20 additions & 19 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use nom::{error::ErrorKind, error_position, AsBytes, FindSubstring, IResult, InputLength, Slice};
use nom_locate::LocatedSpan;
use nom::{error::ErrorKind, error_position, AsBytes, FindSubstring, IResult, Input, Parser};

Check warning on line 1 in tests/integration_tests.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unused import: `Parser`
use nom_locate::{LocatedSpan, SliceInput};
use std::cmp;
use std::fmt::Debug;
use std::ops::{Range, RangeFull};

Check warning on line 5 in tests/integration_tests.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

unused imports: `RangeFull` and `Range`

Check warning on line 5 in tests/integration_tests.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --features alloc --no-default-features)

unused imports: `RangeFull` and `Range`

Check warning on line 5 in tests/integration_tests.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused imports: `RangeFull` and `Range`

#[cfg(feature = "alloc")]
use nom::bytes::complete::escaped_transform;
Expand All @@ -16,14 +16,14 @@
sequence::{delimited, preceded},
};

type StrSpan<'a> = LocatedSpan<&'a str>;

Check warning on line 19 in tests/integration_tests.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

type alias `StrSpan` is never used
type BytesSpan<'a> = LocatedSpan<&'a [u8]>;

Check warning on line 20 in tests/integration_tests.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

type alias `BytesSpan` is never used

#[cfg(any(feature = "std", feature = "alloc"))]
fn simple_parser_str(i: StrSpan) -> IResult<StrSpan, Vec<StrSpan>> {
let (i, foo) = delimited(multispace0, tag("foo"), multispace0)(i)?;
let (i, bar) = delimited(multispace0, tag("bar"), multispace0)(i)?;
let (i, baz) = many0(delimited(multispace0, tag("baz"), multispace0))(i)?;
let (i, foo) = delimited(multispace0, tag("foo"), multispace0).parse(i)?;
let (i, bar) = delimited(multispace0, tag("bar"), multispace0).parse(i)?;
let (i, baz) = many0(delimited(multispace0, tag("baz"), multispace0)).parse(i)?;
let (i, eof) = eof(i)?;

Ok({
Expand All @@ -36,10 +36,10 @@

#[cfg(any(feature = "std", feature = "alloc"))]
fn simple_parser_u8(i: BytesSpan) -> IResult<BytesSpan, Vec<BytesSpan>> {
let (i, foo) = delimited(multispace0, tag("foo"), multispace0)(i)?;
let (i, bar) = delimited(multispace0, tag("bar"), multispace0)(i)?;
let (i, baz) = many0(delimited(multispace0, tag("baz"), multispace0))(i)?;
let (i, eof) = eof(i)?;
let (i, foo) = delimited(multispace0, tag("foo"), multispace0).parse(i)?;
let (i, bar) = delimited(multispace0, tag("bar"), multispace0).parse(i)?;
let (i, baz) = many0(delimited(multispace0, tag("baz"), multispace0)).parse(i)?;
let (i, eof) = eof.parse(i)?;

Ok({
let mut res = vec![foo, bar];
Expand All @@ -49,7 +49,7 @@
})
}

struct Position {

Check warning on line 52 in tests/integration_tests.rs

View workflow job for this annotation

GitHub Actions / Test (stable, --no-default-features)

struct `Position` is never constructed
line: u32,
column: usize,
offset: usize,
Expand All @@ -59,7 +59,7 @@
fn test_str_fragments<'a, F, T>(parser: F, input: T, positions: Vec<Position>)
where
F: Fn(LocatedSpan<T>) -> IResult<LocatedSpan<T>, Vec<LocatedSpan<T>>>,
T: InputLength + Slice<Range<usize>> + Slice<RangeFull> + Debug + PartialEq + AsBytes,
T: Input + Debug + PartialEq + AsBytes,
{
let res = parser(LocatedSpan::new(input.slice(..)))
.map_err(|err| {
Expand Down Expand Up @@ -255,7 +255,8 @@
nom::character::complete::anychar,
),
char('"'),
)(i)
)
.parse(i)
}

let res = string(LocatedSpan::new("\"foo\\\"bar\""));
Expand All @@ -270,9 +271,9 @@
#[cfg(any(feature = "std", feature = "alloc"))]
fn plague(i: StrSpan) -> IResult<StrSpan, Vec<StrSpan>> {
let (i, ojczyzno) = find_substring(i, "Ojczyzno")?;
let (i, jak) = many0(|i| find_substring(i, "jak "))(i)?;
let (i, jak) = many0(|i| find_substring(i, "jak ")).parse(i)?;
let (i, zielona) = find_substring(i, "Zielona")?;
let (i, _) = preceded(take_until("."), tag("."))(i)?;
let (i, _) = preceded(take_until("."), tag(".")).parse(i)?;

Ok({
let mut res = vec![ojczyzno];
Expand Down Expand Up @@ -345,9 +346,9 @@
#[test]
fn test_take_until_str() {
fn parser(i: StrSpan) -> IResult<StrSpan, ()> {
let (i, _) = delimited(take_until("foo"), tag("foo"), multispace0)(i)?;
let (i, _) = delimited(take_until("bar"), tag("bar"), multispace0)(i)?;
let (i, _) = eof(i)?;
let (i, _) = delimited(take_until("foo"), tag("foo"), multispace0).parse(i)?;
let (i, _) = delimited(take_until("bar"), tag("bar"), multispace0).parse(i)?;
let (i, _) = eof.parse(i)?;
Ok((i, ()))
}
let res = parser(LocatedSpan::new(" X foo Y bar "));
Expand All @@ -363,9 +364,9 @@
fn test_take_until_u8() {
fn parser(i: BytesSpan) -> IResult<BytesSpan, ()> {
// Mix string and byte conditions.
let (i, _) = delimited(take_until("foo"), tag("foo"), multispace0)(i)?;
let (i, _) = delimited(take_until(&b"bar"[..]), tag(&b"bar"[..]), multispace0)(i)?;
let (i, _) = eof(i)?;
let (i, _) = delimited(take_until("foo"), tag("foo"), multispace0).parse(i)?;
let (i, _) = delimited(take_until(&b"bar"[..]), tag(&b"bar"[..]), multispace0).parse(i)?;
let (i, _) = eof.parse(i)?;
Ok((i, ()))
}
let res = parser(LocatedSpan::new(&b" X foo Y bar "[..]));
Expand Down
Loading