diff options
Diffstat (limited to 'vendor/gix-object/src/commit/decode.rs')
-rw-r--r-- | vendor/gix-object/src/commit/decode.rs | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/vendor/gix-object/src/commit/decode.rs b/vendor/gix-object/src/commit/decode.rs index 821feaabb..0b8243ef3 100644 --- a/vendor/gix-object/src/commit/decode.rs +++ b/vendor/gix-object/src/commit/decode.rs @@ -1,71 +1,71 @@ use std::borrow::Cow; -use nom::{ - branch::alt, - bytes::complete::{is_not, tag}, - combinator::{all_consuming, opt}, - error::{context, ContextError, ParseError}, - multi::many0, - IResult, Parser, -}; use smallvec::SmallVec; +use winnow::{ + combinator::{alt, eof, opt, preceded, repeat, rest, terminated}, + error::{AddContext, ParserError, StrContext}, + prelude::*, + token::take_till1, +}; use crate::{parse, parse::NL, BStr, ByteSlice, CommitRef}; -pub fn message<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> { +pub fn message<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8], StrContext>>( + i: &mut &'a [u8], +) -> PResult<&'a BStr, E> { if i.is_empty() { // newline + [message] - return Err(nom::Err::Error(E::add_context( - i, - "newline + <message>", - E::from_error_kind(i, nom::error::ErrorKind::Eof), - ))); + return Err( + winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::Eof) + .add_context(i, StrContext::Expected("newline + <message>".into())), + ); } - let (i, _) = context("a newline separates headers from the message", tag(NL))(i)?; - Ok((&[], i.as_bstr())) + preceded(NL, rest.map(ByteSlice::as_bstr)) + .context(StrContext::Expected( + "a newline separates headers from the message".into(), + )) + .parse_next(i) } -pub fn commit<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( - i: &'a [u8], -) -> IResult<&'a [u8], CommitRef<'_>, E> { - let (i, tree) = context("tree <40 lowercase hex char>", |i| { - parse::header_field(i, b"tree", parse::hex_hash) - })(i)?; - let (i, parents) = context( - "zero or more 'parent <40 lowercase hex char>'", - many0(|i| parse::header_field(i, b"parent", parse::hex_hash)), - )(i)?; - let (i, author) = context("author <signature>", |i| { - parse::header_field(i, b"author", parse::signature) - })(i)?; - let (i, committer) = context("committer <signature>", |i| { - parse::header_field(i, b"committer", parse::signature) - })(i)?; - let (i, encoding) = context( - "encoding <encoding>", - opt(|i| parse::header_field(i, b"encoding", is_not(NL))), - )(i)?; - let (i, extra_headers) = context( - "<field> <single-line|multi-line>", - many0(alt(( - parse::any_header_field_multi_line.map(|(k, o)| (k.as_bstr(), Cow::Owned(o))), - |i| { - parse::any_header_field(i, is_not(NL)).map(|(i, (k, o))| (i, (k.as_bstr(), Cow::Borrowed(o.as_bstr())))) +pub fn commit<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8], StrContext>>( + i: &mut &'a [u8], +) -> PResult<CommitRef<'a>, E> { + ( + (|i: &mut _| parse::header_field(i, b"tree", parse::hex_hash)) + .context(StrContext::Expected("tree <40 lowercase hex char>".into())), + repeat(0.., |i: &mut _| parse::header_field(i, b"parent", parse::hex_hash)) + .map(|p: Vec<_>| p) + .context(StrContext::Expected( + "zero or more 'parent <40 lowercase hex char>'".into(), + )), + (|i: &mut _| parse::header_field(i, b"author", parse::signature)) + .context(StrContext::Expected("author <signature>".into())), + (|i: &mut _| parse::header_field(i, b"committer", parse::signature)) + .context(StrContext::Expected("committer <signature>".into())), + opt(|i: &mut _| parse::header_field(i, b"encoding", take_till1(NL))) + .context(StrContext::Expected("encoding <encoding>".into())), + repeat( + 0.., + alt(( + parse::any_header_field_multi_line.map(|(k, o)| (k.as_bstr(), Cow::Owned(o))), + |i: &mut _| { + parse::any_header_field(i, take_till1(NL)).map(|(k, o)| (k.as_bstr(), Cow::Borrowed(o.as_bstr()))) + }, + )), + ) + .context(StrContext::Expected("<field> <single-line|multi-line>".into())), + terminated(message, eof), + ) + .map( + |(tree, parents, author, committer, encoding, extra_headers, message)| CommitRef { + tree, + parents: SmallVec::from(parents), + author, + committer, + encoding: encoding.map(ByteSlice::as_bstr), + message, + extra_headers, }, - ))), - )(i)?; - let (i, message) = all_consuming(message)(i)?; - - Ok(( - i, - CommitRef { - tree, - parents: SmallVec::from(parents), - author, - committer, - encoding: encoding.map(ByteSlice::as_bstr), - message, - extra_headers, - }, - )) + ) + .parse_next(i) } |