From 7bc8a90178358ddb5934f8e6f78e70a1afe8bb42 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 12 Feb 2024 20:38:33 -0600 Subject: [PATCH 1/2] chore: Update winnow --- Cargo.lock | 4 +-- crates/toml_edit/Cargo.toml | 2 +- crates/toml_edit/src/parser/array.rs | 24 ++++++++-------- crates/toml_edit/src/parser/datetime.rs | 2 +- crates/toml_edit/src/parser/document.rs | 2 +- crates/toml_edit/src/parser/inline_table.rs | 6 ++-- crates/toml_edit/src/parser/key.rs | 7 +++-- crates/toml_edit/src/parser/numbers.rs | 31 ++++++++++----------- crates/toml_edit/src/parser/strings.rs | 23 ++++++++------- crates/toml_edit/src/parser/trivia.rs | 2 +- 10 files changed, 51 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 707c8fd6..8da55e2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1119,9 +1119,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.0" +version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fac9742fd1ad1bd9643b991319f72dd031016d44b77039a26977eb667141e7" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" dependencies = [ "memchr", ] diff --git a/crates/toml_edit/Cargo.toml b/crates/toml_edit/Cargo.toml index 9a5132a8..816952ef 100644 --- a/crates/toml_edit/Cargo.toml +++ b/crates/toml_edit/Cargo.toml @@ -41,7 +41,7 @@ unbounded = [] [dependencies] indexmap = { version = "2.0.0", features = ["std"] } -winnow = { version = "0.5.0", optional = true } +winnow = { version = "0.5.40", optional = true } serde = { version = "1.0.145", optional = true } kstring = { version = "2.0.0", features = ["max_inline"], optional = true } toml_datetime = { version = "0.6.5", path = "../toml_datetime" } diff --git a/crates/toml_edit/src/parser/array.rs b/crates/toml_edit/src/parser/array.rs index 07831919..561c4235 100644 --- a/crates/toml_edit/src/parser/array.rs +++ b/crates/toml_edit/src/parser/array.rs @@ -1,8 +1,8 @@ use winnow::combinator::cut_err; use winnow::combinator::delimited; use winnow::combinator::opt; -use winnow::combinator::separated1; -use winnow::trace::trace; +use winnow::combinator::separated; +use winnow::combinator::trace; use crate::parser::trivia::ws_comment_newline; use crate::parser::value::value; @@ -44,16 +44,16 @@ pub(crate) fn array_values<'i>( move |input: &mut Input<'i>| { let check = check.recursing(input)?; ( - opt( - (separated1(array_value(check), ARRAY_SEP), opt(ARRAY_SEP)).map( - |(v, trailing): (Vec, Option)| { - ( - Array::with_vec(v.into_iter().map(Item::Value).collect()), - trailing.is_some(), - ) - }, - ), - ), + opt(( + separated(1.., array_value(check), ARRAY_SEP), + opt(ARRAY_SEP), + ) + .map(|(v, trailing): (Vec, Option)| { + ( + Array::with_vec(v.into_iter().map(Item::Value).collect()), + trailing.is_some(), + ) + })), ws_comment_newline.span(), ) .try_map::<_, _, std::str::Utf8Error>(|(array, trailing)| { diff --git a/crates/toml_edit/src/parser/datetime.rs b/crates/toml_edit/src/parser/datetime.rs index 945dc693..541aa0ba 100644 --- a/crates/toml_edit/src/parser/datetime.rs +++ b/crates/toml_edit/src/parser/datetime.rs @@ -9,10 +9,10 @@ use winnow::combinator::alt; use winnow::combinator::cut_err; use winnow::combinator::opt; use winnow::combinator::preceded; +use winnow::combinator::trace; use winnow::stream::Stream as _; use winnow::token::one_of; use winnow::token::take_while; -use winnow::trace::trace; // ;; Date and Time (as defined in RFC 3339) diff --git a/crates/toml_edit/src/parser/document.rs b/crates/toml_edit/src/parser/document.rs index aa8fb115..839e3385 100644 --- a/crates/toml_edit/src/parser/document.rs +++ b/crates/toml_edit/src/parser/document.rs @@ -5,9 +5,9 @@ use winnow::combinator::eof; use winnow::combinator::opt; use winnow::combinator::peek; use winnow::combinator::repeat; +use winnow::combinator::trace; use winnow::token::any; use winnow::token::one_of; -use winnow::trace::trace; use crate::document::Document; use crate::key::Key; diff --git a/crates/toml_edit/src/parser/inline_table.rs b/crates/toml_edit/src/parser/inline_table.rs index c2e6619a..ac6ad76b 100644 --- a/crates/toml_edit/src/parser/inline_table.rs +++ b/crates/toml_edit/src/parser/inline_table.rs @@ -1,8 +1,8 @@ use winnow::combinator::cut_err; use winnow::combinator::delimited; -use winnow::combinator::separated0; +use winnow::combinator::separated; +use winnow::combinator::trace; use winnow::token::one_of; -use winnow::trace::trace; use crate::key::Key; use crate::parser::error::CustomError; @@ -124,7 +124,7 @@ fn inline_table_keyvals<'i>( move |input: &mut Input<'i>| { let check = check.recursing(input)?; ( - separated0(keyval(check), INLINE_TABLE_SEP), + separated(0.., keyval(check), INLINE_TABLE_SEP), ws.span().map(RawString::with_span), ) .parse_next(input) diff --git a/crates/toml_edit/src/parser/key.rs b/crates/toml_edit/src/parser/key.rs index e72b1957..ee729fda 100644 --- a/crates/toml_edit/src/parser/key.rs +++ b/crates/toml_edit/src/parser/key.rs @@ -1,10 +1,10 @@ use std::ops::RangeInclusive; use winnow::combinator::peek; -use winnow::combinator::separated1; +use winnow::combinator::separated; +use winnow::combinator::trace; use winnow::token::any; use winnow::token::take_while; -use winnow::trace::trace; use crate::key::Key; use crate::parser::error::CustomError; @@ -20,7 +20,8 @@ use crate::RawString; pub(crate) fn key(input: &mut Input<'_>) -> PResult> { let mut key_path = trace( "dotted-key", - separated1( + separated( + 1.., (ws.span(), simple_key, ws.span()).map(|(pre, (raw, key), suffix)| { Key::new(key) .with_repr_unchecked(Repr::new_unchecked(raw)) diff --git a/crates/toml_edit/src/parser/numbers.rs b/crates/toml_edit/src/parser/numbers.rs index 96815268..dcd96b88 100644 --- a/crates/toml_edit/src/parser/numbers.rs +++ b/crates/toml_edit/src/parser/numbers.rs @@ -7,10 +7,9 @@ use winnow::combinator::peek; use winnow::combinator::preceded; use winnow::combinator::repeat; use winnow::combinator::rest; +use winnow::combinator::trace; use winnow::token::one_of; -use winnow::token::tag; use winnow::token::take; -use winnow::trace::trace; use crate::parser::prelude::*; use crate::parser::trivia::from_utf8_unchecked; @@ -63,20 +62,20 @@ pub(crate) fn dec_int<'i>(input: &mut Input<'i>) -> PResult<&'i str> { repeat( 0.., alt(( - digit.value(()), + digit.void(), ( one_of(b'_'), cut_err(digit).context(StrContext::Expected( StrContextValue::Description("digit"), )), ) - .value(()), + .void(), )), ) .map(|()| ()), ) - .value(()), - digit.value(()), + .void(), + digit.void(), )), ) .recognize() @@ -101,14 +100,14 @@ pub(crate) fn hex_int<'i>(input: &mut Input<'i>) -> PResult<&'i str> { repeat( 0.., alt(( - hexdig.value(()), + hexdig.void(), ( one_of(b'_'), cut_err(hexdig).context(StrContext::Expected( StrContextValue::Description("digit"), )), ) - .value(()), + .void(), )), ) .map(|()| ()), @@ -134,14 +133,14 @@ pub(crate) fn oct_int<'i>(input: &mut Input<'i>) -> PResult<&'i str> { repeat( 0.., alt(( - one_of(DIGIT0_7).value(()), + one_of(DIGIT0_7).void(), ( one_of(b'_'), cut_err(one_of(DIGIT0_7)).context(StrContext::Expected( StrContextValue::Description("digit"), )), ) - .value(()), + .void(), )), ) .map(|()| ()), @@ -168,14 +167,14 @@ pub(crate) fn bin_int<'i>(input: &mut Input<'i>) -> PResult<&'i str> { repeat( 0.., alt(( - one_of(DIGIT0_1).value(()), + one_of(DIGIT0_1).void(), ( one_of(b'_'), cut_err(one_of(DIGIT0_1)).context(StrContext::Expected( StrContextValue::Description("digit"), )), ) - .value(()), + .void(), )), ) .map(|()| ()), @@ -250,13 +249,13 @@ pub(crate) fn zero_prefixable_int<'i>(input: &mut Input<'i>) -> PResult<&'i str> repeat( 0.., alt(( - digit.value(()), + digit.void(), ( one_of(b'_'), cut_err(digit) .context(StrContext::Expected(StrContextValue::Description("digit"))), ) - .value(()), + .void(), )), ) .map(|()| ()), @@ -296,12 +295,12 @@ pub(crate) fn special_float(input: &mut Input<'_>) -> PResult { } // inf = %x69.6e.66 ; inf pub(crate) fn inf(input: &mut Input<'_>) -> PResult { - tag(INF).value(f64::INFINITY).parse_next(input) + INF.value(f64::INFINITY).parse_next(input) } const INF: &[u8] = b"inf"; // nan = %x6e.61.6e ; nan pub(crate) fn nan(input: &mut Input<'_>) -> PResult { - tag(NAN).value(f64::NAN.copysign(1.0)).parse_next(input) + NAN.value(f64::NAN.copysign(1.0)).parse_next(input) } const NAN: &[u8] = b"nan"; diff --git a/crates/toml_edit/src/parser/strings.rs b/crates/toml_edit/src/parser/strings.rs index 675b5c67..b2d8a526 100644 --- a/crates/toml_edit/src/parser/strings.rs +++ b/crates/toml_edit/src/parser/strings.rs @@ -5,21 +5,20 @@ use std::ops::RangeInclusive; use winnow::combinator::alt; use winnow::combinator::cut_err; use winnow::combinator::delimited; +use winnow::combinator::empty; use winnow::combinator::fail; use winnow::combinator::opt; use winnow::combinator::peek; use winnow::combinator::preceded; use winnow::combinator::repeat; -use winnow::combinator::success; use winnow::combinator::terminated; +use winnow::combinator::trace; use winnow::prelude::*; use winnow::stream::Stream; use winnow::token::any; use winnow::token::none_of; use winnow::token::one_of; -use winnow::token::tag; use winnow::token::take_while; -use winnow::trace::trace; use crate::parser::error::CustomError; use crate::parser::numbers::HEXDIG; @@ -110,15 +109,15 @@ pub(crate) const ESCAPE: u8 = b'\\'; // escape-seq-char =/ %x55 8HEXDIG ; UXXXXXXXX U+XXXXXXXX fn escape_seq_char(input: &mut Input<'_>) -> PResult { dispatch! {any; - b'b' => success('\u{8}'), - b'f' => success('\u{c}'), - b'n' => success('\n'), - b'r' => success('\r'), - b't' => success('\t'), + b'b' => empty.value('\u{8}'), + b'f' => empty.value('\u{c}'), + b'n' => empty.value('\n'), + b'r' => empty.value('\r'), + b't' => empty.value('\t'), b'u' => cut_err(hexescape::<4>).context(StrContext::Label("unicode 4-digit hex code")), b'U' => cut_err(hexescape::<8>).context(StrContext::Label("unicode 8-digit hex code")), - b'\\' => success('\\'), - b'"' => success('"'), + b'\\' => empty.value('\\'), + b'"' => empty.value('"'), _ => { cut_err(fail::<_, char, _>) .context(StrContext::Label("escape sequence")) @@ -187,7 +186,7 @@ fn ml_basic_body<'i>(input: &mut Input<'i>) -> PResult> { } } - if let Some(qi) = opt(mlb_quotes(tag(ML_BASIC_STRING_DELIM).value(()))).parse_next(input)? { + if let Some(qi) = opt(mlb_quotes(ML_BASIC_STRING_DELIM.void())).parse_next(input)? { c.to_mut().push_str(qi); } @@ -320,7 +319,7 @@ fn ml_literal_body<'i>(input: &mut Input<'i>) -> PResult<&'i str> { ), ) .map(|()| ()), - opt(mll_quotes(tag(ML_LITERAL_STRING_DELIM).value(()))), + opt(mll_quotes(ML_LITERAL_STRING_DELIM.void())), ) .recognize() .try_map(std::str::from_utf8) diff --git a/crates/toml_edit/src/parser/trivia.rs b/crates/toml_edit/src/parser/trivia.rs index 4575fb15..8d903a56 100644 --- a/crates/toml_edit/src/parser/trivia.rs +++ b/crates/toml_edit/src/parser/trivia.rs @@ -99,7 +99,7 @@ pub(crate) fn ws_comment_newline<'i>(input: &mut Input<'i>) -> PResult<&'i [u8]> alt((take_while(1.., WSCHAR), newline.value(&b"\n"[..]))), ) .map(|()| ()), - comment.value(()), + comment.void(), )), ) .map(|()| ()) From 065b9f99524acc5c81b87222a95183ccc4c9ce72 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 12 Feb 2024 20:42:32 -0600 Subject: [PATCH 2/2] chore: Update winnow --- Cargo.lock | 4 ++-- crates/toml_edit/Cargo.toml | 2 +- crates/toml_edit/src/parser/datetime.rs | 2 +- crates/toml_edit/src/parser/strings.rs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8da55e2e..ac1dd6b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1119,9 +1119,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.40" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +checksum = "6b1dbce9e90e5404c5a52ed82b1d13fc8cfbdad85033b6f57546ffd1265f8451" dependencies = [ "memchr", ] diff --git a/crates/toml_edit/Cargo.toml b/crates/toml_edit/Cargo.toml index 816952ef..eca83d0d 100644 --- a/crates/toml_edit/Cargo.toml +++ b/crates/toml_edit/Cargo.toml @@ -41,7 +41,7 @@ unbounded = [] [dependencies] indexmap = { version = "2.0.0", features = ["std"] } -winnow = { version = "0.5.40", optional = true } +winnow = { version = "0.6.0", optional = true } serde = { version = "1.0.145", optional = true } kstring = { version = "2.0.0", features = ["max_inline"], optional = true } toml_datetime = { version = "0.6.5", path = "../toml_datetime" } diff --git a/crates/toml_edit/src/parser/datetime.rs b/crates/toml_edit/src/parser/datetime.rs index 541aa0ba..86c5a5bc 100644 --- a/crates/toml_edit/src/parser/datetime.rs +++ b/crates/toml_edit/src/parser/datetime.rs @@ -73,7 +73,7 @@ fn full_date_(input: &mut Input<'_>) -> PResult { _ => 31, }; if max_days_in_month < day { - input.reset(day_start); + input.reset(&day_start); return Err(winnow::error::ErrMode::from_external_error( input, winnow::error::ErrorKind::Verify, diff --git a/crates/toml_edit/src/parser/strings.rs b/crates/toml_edit/src/parser/strings.rs index b2d8a526..6223e706 100644 --- a/crates/toml_edit/src/parser/strings.rs +++ b/crates/toml_edit/src/parser/strings.rs @@ -222,7 +222,7 @@ fn mlb_quotes<'i>( match res { Err(winnow::error::ErrMode::Backtrack(_)) => { - input.reset(start); + input.reset(&start); terminated(b"\"", peek(term.by_ref())) .map(|b| unsafe { from_utf8_unchecked(b, "`bytes` out non-ASCII") }) .parse_next(input) @@ -351,7 +351,7 @@ fn mll_quotes<'i>( match res { Err(winnow::error::ErrMode::Backtrack(_)) => { - input.reset(start); + input.reset(&start); terminated(b"'", peek(term.by_ref())) .map(|b| unsafe { from_utf8_unchecked(b, "`bytes` out non-ASCII") }) .parse_next(input)