Skip to content

Commit ee75de1

Browse files
committed
Switch gix to winnow 0.3
Things to do later - Use traits on `winnow::ErrMode` instead of manually constructing (anytime) - Switch error trait functions to use umcs (anytime) - Rely on `ErrMode::into_inner` (0.5)
1 parent 510192e commit ee75de1

File tree

26 files changed

+93
-85
lines changed

26 files changed

+93
-85
lines changed

Cargo.lock

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-actor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ gix-date = { version = "^0.7.1", path = "../gix-date" }
2323
thiserror = "1.0.38"
2424
btoi = "0.4.2"
2525
bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"]}
26-
nom = { version = "7", default-features = false, features = ["std"]}
26+
winnow = { version = "0.3", features = ["simd"] }
2727
itoa = "1.0.1"
2828
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
2929

gix-actor/src/identity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::{signature::decode, Identity, IdentityRef};
44

55
impl<'a> IdentityRef<'a> {
66
/// Deserialize an identity from the given `data`.
7-
pub fn from_bytes<E>(data: &'a [u8]) -> Result<Self, nom::Err<E>>
7+
pub fn from_bytes<E>(data: &'a [u8]) -> Result<Self, winnow::Err<E>>
88
where
9-
E: nom::error::ParseError<&'a [u8]> + nom::error::ContextError<&'a [u8]>,
9+
E: winnow::error::ParseError<&'a [u8]> + winnow::error::ContextError<&'a [u8]>,
1010
{
1111
decode::identity(data).map(|(_, t)| t)
1212
}

gix-actor/src/signature/decode.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ pub(crate) mod function {
22
use bstr::ByteSlice;
33
use btoi::btoi;
44
use gix_date::{time::Sign, OffsetInSeconds, SecondsSinceUnixEpoch, Time};
5-
use nom::multi::many1_count;
6-
use nom::{
5+
use std::cell::RefCell;
6+
use winnow::{
77
branch::alt,
88
bytes::complete::{tag, take, take_until, take_while_m_n},
99
character::is_digit,
1010
error::{context, ContextError, ParseError},
11+
multi::many1_count,
12+
prelude::*,
1113
sequence::{terminated, tuple},
12-
IResult,
1314
};
14-
use std::cell::RefCell;
1515

1616
use crate::{IdentityRef, SignatureRef};
1717

@@ -21,7 +21,6 @@ pub(crate) mod function {
2121
pub fn decode<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
2222
i: &'a [u8],
2323
) -> IResult<&'a [u8], SignatureRef<'a>, E> {
24-
use nom::Parser;
2524
let tzsign = RefCell::new(b'-'); // TODO: there should be no need for this.
2625
let (i, (identity, _, time, _tzsign_count, hours, minutes)) = context(
2726
"<name> <<email>> <timestamp> <+|-><HHMM>",
@@ -30,9 +29,9 @@ pub(crate) mod function {
3029
tag(b" "),
3130
context("<timestamp>", |i| {
3231
terminated(take_until(SPACE), take(1usize))(i).and_then(|(i, v)| {
33-
btoi::<SecondsSinceUnixEpoch>(v)
34-
.map(|v| (i, v))
35-
.map_err(|_| nom::Err::Error(E::from_error_kind(i, nom::error::ErrorKind::MapRes)))
32+
btoi::<SecondsSinceUnixEpoch>(v).map(|v| (i, v)).map_err(|_| {
33+
winnow::Err::Backtrack(E::from_error_kind(i, winnow::error::ErrorKind::MapRes))
34+
})
3635
})
3736
}),
3837
context(
@@ -44,16 +43,16 @@ pub(crate) mod function {
4443
),
4544
context("HH", |i| {
4645
take_while_m_n(2usize, 2, is_digit)(i).and_then(|(i, v)| {
47-
btoi::<OffsetInSeconds>(v)
48-
.map(|v| (i, v))
49-
.map_err(|_| nom::Err::Error(E::from_error_kind(i, nom::error::ErrorKind::MapRes)))
46+
btoi::<OffsetInSeconds>(v).map(|v| (i, v)).map_err(|_| {
47+
winnow::Err::Backtrack(E::from_error_kind(i, winnow::error::ErrorKind::MapRes))
48+
})
5049
})
5150
}),
5251
context("MM", |i| {
5352
take_while_m_n(1usize, 2, is_digit)(i).and_then(|(i, v)| {
54-
btoi::<OffsetInSeconds>(v)
55-
.map(|v| (i, v))
56-
.map_err(|_| nom::Err::Error(E::from_error_kind(i, nom::error::ErrorKind::MapRes)))
53+
btoi::<OffsetInSeconds>(v).map(|v| (i, v)).map_err(|_| {
54+
winnow::Err::Backtrack(E::from_error_kind(i, winnow::error::ErrorKind::MapRes))
55+
})
5756
})
5857
}),
5958
)),
@@ -107,11 +106,11 @@ mod tests {
107106
use bstr::ByteSlice;
108107
use gix_date::{time::Sign, OffsetInSeconds, SecondsSinceUnixEpoch};
109108
use gix_testtools::to_bstr_err;
110-
use nom::IResult;
109+
use winnow::IResult;
111110

112111
use crate::{signature, SignatureRef, Time};
113112

114-
fn decode(i: &[u8]) -> IResult<&[u8], SignatureRef<'_>, nom::error::VerboseError<&[u8]>> {
113+
fn decode(i: &[u8]) -> IResult<&[u8], SignatureRef<'_>, winnow::error::VerboseError<&[u8]>> {
115114
signature::decode(i)
116115
}
117116

gix-actor/src/signature/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ mod _ref {
55

66
impl<'a> SignatureRef<'a> {
77
/// Deserialize a signature from the given `data`.
8-
pub fn from_bytes<E>(data: &'a [u8]) -> Result<SignatureRef<'a>, nom::Err<E>>
8+
pub fn from_bytes<E>(data: &'a [u8]) -> Result<SignatureRef<'a>, winnow::Err<E>>
99
where
10-
E: nom::error::ParseError<&'a [u8]> + nom::error::ContextError<&'a [u8]>,
10+
E: winnow::error::ParseError<&'a [u8]> + winnow::error::ContextError<&'a [u8]>,
1111
{
1212
decode(data).map(|(_, t)| t)
1313
}

gix-actor/tests/identity/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn round_trip() -> gix_testtools::Result {
99
b".. whitespace \t is explicitly allowed - unicode aware trimming must be done elsewhere <[email protected]>"
1010
];
1111
for input in DEFAULTS {
12-
let signature: Identity = gix_actor::IdentityRef::from_bytes::<()>(input)?.into();
12+
let signature: Identity = gix_actor::IdentityRef::from_bytes::<()>(input).unwrap().into();
1313
let mut output = Vec::new();
1414
signature.write_to(&mut output)?;
1515
assert_eq!(output.as_bstr(), input.as_bstr());

gix-actor/tests/signature/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn round_trip() -> Result<(), Box<dyn std::error::Error>> {
7373
];
7474

7575
for input in DEFAULTS {
76-
let signature: Signature = gix_actor::SignatureRef::from_bytes::<()>(input)?.into();
76+
let signature: Signature = gix_actor::SignatureRef::from_bytes::<()>(input).unwrap().into();
7777
let mut output = Vec::new();
7878
signature.write_to(&mut output)?;
7979
assert_eq!(output.as_bstr(), input.as_bstr());

gix-config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ gix-ref = { version = "^0.34.0", path = "../gix-ref" }
2525
gix-glob = { version = "^0.10.2", path = "../gix-glob" }
2626

2727
log = "0.4.17"
28-
winnow = "0.5"
28+
winnow = { version = "0.5", features = ["simd"] }
2929
memchr = "2"
3030
thiserror = "1.0.26"
3131
unicode-bom = "2.0.2"

gix-object/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ serde = ["dep:serde", "bstr/serde", "smallvec/serde", "gix-hash/serde", "gix-act
2525
## details information about the error location will be collected.
2626
## Use it in applications which expect broken or invalid objects or for debugging purposes. Incorrectly formatted objects aren't at all
2727
## common otherwise.
28-
verbose-object-parsing-errors = ["nom/std"]
28+
verbose-object-parsing-errors = []
2929

3030
[dependencies]
3131
gix-features = { version = "^0.32.1", path = "../gix-features", features = ["rustsha1"] }
@@ -38,7 +38,7 @@ btoi = "0.4.2"
3838
itoa = "1.0.1"
3939
thiserror = "1.0.34"
4040
bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"] }
41-
nom = { version = "7", default-features = false, features = ["std"]}
41+
winnow = { version = "0.3", features = ["simd"] }
4242
smallvec = { version = "1.4.0", features = ["write"] }
4343
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
4444

gix-object/src/commit/decode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
use std::borrow::Cow;
22

3-
use nom::{
3+
use smallvec::SmallVec;
4+
use winnow::{
45
branch::alt,
56
bytes::complete::{is_not, tag},
67
combinator::{all_consuming, opt},
78
error::{context, ContextError, ParseError},
89
multi::many0,
910
IResult, Parser,
1011
};
11-
use smallvec::SmallVec;
1212

1313
use crate::{parse, parse::NL, BStr, ByteSlice, CommitRef};
1414

1515
pub fn message<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> {
1616
if i.is_empty() {
1717
// newline + [message]
18-
return Err(nom::Err::Error(E::add_context(
18+
return Err(winnow::Err::Backtrack(E::add_context(
19+
E::from_error_kind(i, winnow::error::ErrorKind::Eof),
1920
i,
2021
"newline + <message>",
21-
E::from_error_kind(i, nom::error::ErrorKind::Eof),
2222
)));
2323
}
2424
let (i, _) = context("a newline separates headers from the message", tag(NL))(i)?;
@@ -31,7 +31,7 @@ pub fn commit<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
3131
let (i, tree) = context("tree <40 lowercase hex char>", |i| {
3232
parse::header_field(i, b"tree", parse::hex_hash)
3333
})(i)?;
34-
let (i, parents) = context(
34+
let (i, parents): (_, Vec<_>) = context(
3535
"zero or more 'parent <40 lowercase hex char>'",
3636
many0(|i| parse::header_field(i, b"parent", parse::hex_hash)),
3737
)(i)?;

0 commit comments

Comments
 (0)