Skip to content

Commit 750de24

Browse files
authored
Upgrade nom crate from 7.0 to 8.0 version (#14)
- vendor shrank version of 4.2.0 `nom_locate` crate
1 parent 7d2508b commit 750de24

File tree

10 files changed

+565
-276
lines changed

10 files changed

+565
-276
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ All user visible changes to `cucumber-expressions` crate will be documented in t
1414
### BC Breaks
1515

1616
- Bumped up [MSRV] to 1.81 because for `#[expect]` attribute usage. ([e1bb9266])
17+
- Upgraded [`nom`] to 8.0 version. ([#14])
1718

19+
[#14]: /../../pull/14
1820
[e1bb9266]: /../../commit/e1bb92668617432948ab0faa32232b67d6c530e7
1921

2022

@@ -117,6 +119,7 @@ All user visible changes to `cucumber-expressions` crate will be documented in t
117119

118120

119121

122+
[`nom`]: https://docs.rs/nom
120123
[`regex`]: https://docs.rs/regex
121124
[`Regex`]: https://docs.rs/regex
122125
[`regex-syntax`]: https://docs.rs/regex-syntax

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ into-regex = ["dep:either", "dep:regex", "dep:regex-syntax"]
2727

2828
[dependencies]
2929
derive_more = { version = "0.99.17", features = ["as_ref", "deref", "deref_mut", "display", "error", "from", "into"], default-features = false }
30-
nom = "7.0"
31-
nom_locate = "4.0"
30+
memchr = "2.3"
31+
nom = "8.0"
3232

3333
# "into-regex" feature dependencies
3434
either = { version = "1.6", optional = true }

src/ast.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
//! [AST]: https://en.wikipedia.org/wiki/Abstract_syntax_tree
1818
1919
use derive_more::{AsRef, Deref, DerefMut};
20-
use nom::{error::ErrorKind, Err, InputLength};
21-
use nom_locate::LocatedSpan;
20+
use nom::{error::ErrorKind, Err, Input};
2221

23-
use crate::parse;
22+
use crate::{parse, vendor::nom_locate::LocatedSpan};
2423

2524
/// [`str`] along with its location information in the original input.
2625
pub type Spanned<'s> = LocatedSpan<&'s str>;
@@ -112,7 +111,7 @@ pub type SingleAlternation<Input> = Vec<Alternative<Input>>;
112111
#[derive(AsRef, Clone, Debug, Deref, DerefMut, Eq, PartialEq)]
113112
pub struct Alternation<Input>(pub Vec<SingleAlternation<Input>>);
114113

115-
impl<Input: InputLength> Alternation<Input> {
114+
impl<I: Input> Alternation<I> {
116115
/// Returns length of this [`Alternation`]'s span in the `Input`.
117116
pub(crate) fn span_len(&self) -> usize {
118117
self.0

src/combinator.rs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010

1111
//! Helper parser combinators.
1212
13-
use std::ops::RangeFrom;
14-
1513
use nom::{
1614
error::{ErrorKind, ParseError},
17-
AsChar, Err, IResult, InputIter, InputLength, InputTake,
18-
InputTakeAtPosition, Offset, Parser, Slice,
15+
AsChar, Err, IResult, Input, Offset, Parser,
1916
};
2017

2118
/// Applies the given `map` function to the `parser`'s [`IResult`] in case it
@@ -26,13 +23,13 @@ use nom::{
2623
/// [`Error`]: nom::Err::Error
2724
/// [`Failure`]: nom::Err::Failure
2825
/// [`verify()`]: nom::combinator::verify()
29-
pub(crate) fn map_err<I, O1, E: ParseError<I>, F, G>(
26+
pub(crate) fn map_err<I, F, G>(
3027
mut parser: F,
3128
mut map: G,
32-
) -> impl FnMut(I) -> IResult<I, O1, E>
29+
) -> impl FnMut(I) -> IResult<I, F::Output, F::Error>
3330
where
34-
F: Parser<I, O1, E>,
35-
G: FnMut(Err<E>) -> Err<E>,
31+
F: Parser<I>,
32+
G: FnMut(Err<F::Error>) -> Err<F::Error>,
3633
{
3734
move |input: I| parser.parse(input).map_err(&mut map)
3835
}
@@ -47,26 +44,19 @@ where
4744
/// non-`escapable` `Input` or end of line.
4845
///
4946
/// [`escaped()`]: nom::bytes::complete::escaped()
50-
pub(crate) fn escaped0<'a, Input, Error, F, G, O1, O2>(
47+
pub(crate) fn escaped0<'a, I, Error, F, G>(
5148
mut normal: F,
5249
control_char: char,
5350
mut escapable: G,
54-
) -> impl FnMut(Input) -> IResult<Input, Input, Error>
51+
) -> impl FnMut(I) -> IResult<I, I, Error>
5552
where
56-
Input: Clone
57-
+ Offset
58-
+ InputLength
59-
+ InputTake
60-
+ InputTakeAtPosition
61-
+ Slice<RangeFrom<usize>>
62-
+ InputIter
63-
+ 'a,
64-
<Input as InputIter>::Item: AsChar,
65-
F: Parser<Input, O1, Error>,
66-
G: Parser<Input, O2, Error>,
67-
Error: ParseError<Input>,
53+
I: Clone + Offset + Input + 'a,
54+
<I as Input>::Item: AsChar,
55+
F: Parser<I, Error = Error>,
56+
G: Parser<I, Error = Error>,
57+
Error: ParseError<I>,
6858
{
69-
move |input: Input| {
59+
move |input: I| {
7060
let mut i = input.clone();
7161
let mut consumed_nothing = false;
7262

@@ -76,7 +66,7 @@ where
7666
match (normal.parse(i.clone()), consumed_nothing) {
7767
(Ok((i2, _)), false) => {
7868
if i2.input_len() == 0 {
79-
return Ok((input.slice(input.input_len()..), input));
69+
return Ok((input.take_from(input.input_len()), input));
8070
}
8171
if i2.input_len() == current_len {
8272
consumed_nothing = true;
@@ -102,11 +92,11 @@ where
10292
ErrorKind::Escaped,
10393
)));
10494
}
105-
match escapable.parse(i.slice(next..)) {
95+
match escapable.parse(i.take_from(next)) {
10696
Ok((i2, _)) => {
10797
if i2.input_len() == 0 {
10898
return Ok((
109-
input.slice(input.input_len()..),
99+
input.take_from(input.input_len()),
110100
input,
111101
));
112102
}
@@ -133,7 +123,7 @@ where
133123
}
134124
}
135125

136-
Ok((input.slice(input.input_len()..), input))
126+
Ok((input.take_from(input.input_len()), input))
137127
}
138128
}
139129

0 commit comments

Comments
 (0)