Skip to content

Commit

Permalink
Merge pull request #686 from epage/winnow
Browse files Browse the repository at this point in the history
chore: Update winnow
  • Loading branch information
epage authored Feb 13, 2024
2 parents 7ad85b6 + 065b9f9 commit 57b4a00
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 55 deletions.
4 changes: 2 additions & 2 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 crates/toml_edit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ unbounded = []

[dependencies]
indexmap = { version = "2.0.0", features = ["std"] }
winnow = { version = "0.5.0", 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" }
Expand Down
24 changes: 12 additions & 12 deletions crates/toml_edit/src/parser/array.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Value>, Option<u8>)| {
(
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<Value>, Option<u8>)| {
(
Array::with_vec(v.into_iter().map(Item::Value).collect()),
trailing.is_some(),
)
})),
ws_comment_newline.span(),
)
.try_map::<_, _, std::str::Utf8Error>(|(array, trailing)| {
Expand Down
4 changes: 2 additions & 2 deletions crates/toml_edit/src/parser/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -73,7 +73,7 @@ fn full_date_(input: &mut Input<'_>) -> PResult<Date> {
_ => 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,
Expand Down
2 changes: 1 addition & 1 deletion crates/toml_edit/src/parser/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions crates/toml_edit/src/parser/inline_table.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions crates/toml_edit/src/parser/key.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,7 +20,8 @@ use crate::RawString;
pub(crate) fn key(input: &mut Input<'_>) -> PResult<Vec<Key>> {
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))
Expand Down
31 changes: 15 additions & 16 deletions crates/toml_edit/src/parser/numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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(|()| ()),
Expand All @@ -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(|()| ()),
Expand All @@ -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(|()| ()),
Expand Down Expand Up @@ -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(|()| ()),
Expand Down Expand Up @@ -296,12 +295,12 @@ pub(crate) fn special_float(input: &mut Input<'_>) -> PResult<f64> {
}
// inf = %x69.6e.66 ; inf
pub(crate) fn inf(input: &mut Input<'_>) -> PResult<f64> {
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<f64> {
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";

Expand Down
27 changes: 13 additions & 14 deletions crates/toml_edit/src/parser/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<char> {
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"))
Expand Down Expand Up @@ -187,7 +186,7 @@ fn ml_basic_body<'i>(input: &mut Input<'i>) -> PResult<Cow<'i, str>> {
}
}

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);
}

Expand Down Expand Up @@ -223,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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -352,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)
Expand Down
2 changes: 1 addition & 1 deletion crates/toml_edit/src/parser/trivia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|()| ())
Expand Down

0 comments on commit 57b4a00

Please sign in to comment.