Skip to content

Update winnow to 0.6 #1290

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

Merged
merged 3 commits into from
Feb 13, 2024
Merged
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
37 changes: 23 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gix-actor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gix-date = { version = "^0.8.3", path = "../gix-date" }
thiserror = "1.0.38"
btoi = "0.4.2"
bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"]}
winnow = { version = "0.5.36", features = ["simd"] }
winnow = { version = "0.6.0", features = ["simd"] }
itoa = "1.0.1"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}

Expand Down
4 changes: 2 additions & 2 deletions gix-actor/src/signature/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ mod tests {
.map_err(to_bstr_err)
.expect_err("parse fails as > is missing")
.to_string(),
"in slice at ' 12345 -1215'\n 0: expected `<email>` at ' 12345 -1215'\n 1: expected `<name> <<email>>` at ' 12345 -1215'\n 2: expected `<name> <<email>> <timestamp> <+|-><HHMM>` at ' 12345 -1215'\n"
"in slice at ' 12345 -1215'\n 0: expected `<email>` at ' 12345 -1215'\n 1: expected `<name> <<email>>` at 'hello < 12345 -1215'\n 2: expected `<name> <<email>> <timestamp> <+|-><HHMM>` at 'hello < 12345 -1215'\n"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.6 included a change that allows TreeError to behave closer to how nom behaved with errors in capturing the start location for each stage things are processed rather than always attaching it to only the original error location

);
}

Expand All @@ -173,7 +173,7 @@ mod tests {
.map_err(to_bstr_err)
.expect_err("parse fails as > is missing")
.to_string(),
"in predicate verification at 'abc -1215'\n 0: expected `<timestamp>` at 'abc -1215'\n 1: expected `<name> <<email>> <timestamp> <+|-><HHMM>` at 'abc -1215'\n"
"in predicate verification at 'abc -1215'\n 0: expected `<timestamp>` at 'abc -1215'\n 1: expected `<name> <<email>> <timestamp> <+|-><HHMM>` at 'hello <> abc -1215'\n"
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion gix-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gix-sec = { version = "^0.10.4", path = "../gix-sec" }
gix-ref = { version = "^0.42.0", path = "../gix-ref" }
gix-glob = { version = "^0.16.0", path = "../gix-glob" }

winnow = { version = "0.5.36", features = ["simd"] }
winnow = { version = "0.6.0", features = ["simd"] }
memchr = "2"
thiserror = "1.0.26"
unicode-bom = "2.0.2"
Expand Down
20 changes: 10 additions & 10 deletions gix-config/src/parse/nom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ pub fn from_bytes<'i>(mut input: &'i [u8], dispatch: &mut dyn FnMut(Event<'i>))
Ok(())
}

fn newlines_from(input: &[u8], start: winnow::stream::Checkpoint<&[u8]>) -> usize {
fn newlines_from(input: &[u8], start: winnow::stream::Checkpoint<&[u8], &[u8]>) -> usize {
let offset = input.offset_from(&start);
let mut start_input = input;
start_input.reset(start);
start_input.reset(&start);
start_input.next_slice(offset).iter().filter(|c| **c == b'\n').count()
}

Expand All @@ -97,7 +97,7 @@ fn section<'i>(
) -> PResult<(), NomError<&'i [u8]>> {
let start = i.checkpoint();
let header = section_header(i).map_err(|e| {
i.reset(start);
i.reset(&start);
e
})?;
dispatch(Event::SectionHeader(header));
Expand Down Expand Up @@ -277,17 +277,17 @@ fn value_impl<'i>(i: &mut &'i [u8], dispatch: &mut dyn FnMut(Event<'i>)) -> PRes
let escaped_index = i.offset_from(&value_start_checkpoint);
let escape_index = escaped_index - 1;
let Some(mut c) = i.next_token() else {
i.reset(start_checkpoint);
i.reset(&start_checkpoint);
return Err(winnow::error::ErrMode::from_error_kind(i, ErrorKind::Token));
};
let mut consumed = 1;
if c == b'\r' {
c = i.next_token().ok_or_else(|| {
i.reset(start_checkpoint);
i.reset(&start_checkpoint);
winnow::error::ErrMode::from_error_kind(i, ErrorKind::Token)
})?;
if c != b'\n' {
i.reset(start_checkpoint);
i.reset(&start_checkpoint);
return Err(winnow::error::ErrMode::from_error_kind(i, ErrorKind::Slice));
}
consumed += 1;
Expand All @@ -297,7 +297,7 @@ fn value_impl<'i>(i: &mut &'i [u8], dispatch: &mut dyn FnMut(Event<'i>)) -> PRes
b'\n' => {
partial_value_found = true;

i.reset(value_start_checkpoint);
i.reset(&value_start_checkpoint);

let value = i.next_slice(escape_index).as_bstr();
dispatch(Event::ValueNotDone(Cow::Borrowed(value)));
Expand All @@ -312,7 +312,7 @@ fn value_impl<'i>(i: &mut &'i [u8], dispatch: &mut dyn FnMut(Event<'i>)) -> PRes
}
b'n' | b't' | b'\\' | b'b' | b'"' => {}
_ => {
i.reset(start_checkpoint);
i.reset(&start_checkpoint);
return Err(winnow::error::ErrMode::from_error_kind(i, ErrorKind::Token));
}
}
Expand All @@ -325,7 +325,7 @@ fn value_impl<'i>(i: &mut &'i [u8], dispatch: &mut dyn FnMut(Event<'i>)) -> PRes
}
}
if is_in_quotes {
i.reset(start_checkpoint);
i.reset(&start_checkpoint);
return Err(winnow::error::ErrMode::from_error_kind(i, ErrorKind::Slice));
}

Expand All @@ -342,7 +342,7 @@ fn value_impl<'i>(i: &mut &'i [u8], dispatch: &mut dyn FnMut(Event<'i>)) -> PRes
Some(idx) => idx,
};

i.reset(value_start_checkpoint);
i.reset(&value_start_checkpoint);
let value_end_no_trailing_whitespace = i[..value_end]
.iter()
.enumerate()
Expand Down
2 changes: 1 addition & 1 deletion gix-object/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ btoi = "0.4.2"
itoa = "1.0.1"
thiserror = "1.0.34"
bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"] }
winnow = { version = "0.5.36", features = ["simd"] }
winnow = { version = "0.6.0", features = ["simd"] }
smallvec = { version = "1.4.0", features = ["write"] }
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}

Expand Down
9 changes: 7 additions & 2 deletions gix-object/src/commit/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use winnow::{
combinator::{alt, eof, opt, preceded, repeat, rest, terminated},
error::{AddContext, ParserError, StrContext},
prelude::*,
stream::Stream as _,
token::take_till,
};

Expand All @@ -15,9 +16,13 @@ pub fn message<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8], StrContext>>(
) -> PResult<&'a BStr, E> {
if i.is_empty() {
// newline + [message]
let start = i.checkpoint();
return Err(
winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::Eof)
.add_context(i, StrContext::Expected("newline + <message>".into())),
winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::Eof).add_context(
i,
&start,
StrContext::Expected("newline + <message>".into()),
),
);
}
preceded(NL, rest.map(ByteSlice::as_bstr))
Expand Down
2 changes: 1 addition & 1 deletion gix-object/src/commit/message/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn subject_and_body<'a, E: ParserError<&'a [u8]>>(i: &mut &'a [u8]) -> PResult<(
}
}

i.reset(start);
i.reset(&start);
rest.map(|r: &[u8]| (r.as_bstr(), None)).parse_next(i)
}

Expand Down
2 changes: 1 addition & 1 deletion gix-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ gix-credentials = { version = "^0.24.0", path = "../gix-credentials" }
thiserror = "1.0.32"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"] }
winnow = { version = "0.5.36", features = ["simd"] }
winnow = { version = "0.6.0", features = ["simd"] }
btoi = "0.4.2"

# for async-client
Expand Down
4 changes: 2 additions & 2 deletions gix-protocol/src/remote_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bstr::ByteSlice;
use winnow::{
combinator::{opt, preceded, terminated},
prelude::*,
token::{tag, take_till},
token::take_till,
};

/// The information usually found in remote progress messages as sent by a git server during
Expand Down Expand Up @@ -85,7 +85,7 @@ fn next_optional_percentage(i: &mut &[u8]) -> PResult<Option<u32>, ()> {
take_till(0.., |c: u8| c.is_ascii_digit()),
parse_number.try_map(u32::try_from),
),
tag(b"%"),
b"%",
))
.parse_next(i)
}
Expand Down
2 changes: 1 addition & 1 deletion gix-ref/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gix-lock = { version = "^13.0.0", path = "../gix-lock" }
gix-tempfile = { version = "^13.0.0", default-features = false, path = "../gix-tempfile" }

thiserror = "1.0.34"
winnow = { version = "0.5.36", features = ["simd"] }
winnow = { version = "0.6.0", features = ["simd"] }
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}

# packed refs
Expand Down
2 changes: 1 addition & 1 deletion gix-ref/src/store/packed/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'a> Iterator for packed::Iter<'a> {
Some(Ok(reference))
}
Err(_) => {
self.cursor.reset(start);
self.cursor.reset(&start);
let (failed_line, next_cursor) = self
.cursor
.find_byte(b'\n')
Expand Down
2 changes: 1 addition & 1 deletion tests/tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ gix-worktree = "0.26"
gix-fs = { version = "^0.10.0", path = "../../gix-fs" }
gix-tempfile = { version = "^13.0.0", default-features = false, features = ["signals"], path = "../../gix-tempfile" }

winnow = { version = "0.5.36", features = ["simd"] }
winnow = { version = "0.6.0", features = ["simd"] }
fastrand = "2.0.0"
bstr = { version = "1.5.0", default-features = false }
crc = "3.0.0"
Expand Down
6 changes: 3 additions & 3 deletions tests/tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
};

pub use bstr;
use bstr::{BStr, ByteSlice};
use bstr::ByteSlice;
use io_close::Close;
pub use is_ci;
pub use once_cell;
Expand Down Expand Up @@ -697,9 +697,9 @@ fn extract_archive(
/// Transform a verbose parser errors from raw bytes into a `BStr` to make printing/debugging human-readable.
pub fn to_bstr_err(
err: winnow::error::ErrMode<winnow::error::TreeError<&[u8], winnow::error::StrContext>>,
) -> winnow::error::TreeError<&BStr, winnow::error::StrContext> {
) -> winnow::error::TreeError<&winnow::stream::BStr, winnow::error::StrContext> {
let err = err.into_inner().expect("not a streaming parser");
err.map_input(ByteSlice::as_bstr)
err.map_input(winnow::stream::BStr::new)
}

fn family_name() -> &'static str {
Expand Down