Skip to content

Commit

Permalink
chore: Upgrade to winnow 0.6.26
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jan 30, 2025
1 parent 675edca commit 5dfa5b0
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 72 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.3.0", features = ["std"] }
winnow = { version = "0.6.18", optional = true }
winnow = { version = "0.6.26", optional = true }
serde = { version = "1.0.145", optional = true }
kstring = { version = "2.0.0", features = ["max_inline"], optional = true }
toml_datetime = { version = "0.6.8", path = "../toml_datetime" }
Expand Down
6 changes: 3 additions & 3 deletions crates/toml_edit/src/parser/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::parser::prelude::*;
// ;; Array

// array = array-open array-values array-close
pub(crate) fn array<'i>(input: &mut Input<'i>) -> PResult<Array> {
pub(crate) fn array<'i>(input: &mut Input<'i>) -> ModalResult<Array> {
trace("array", move |input: &mut Input<'i>| {
delimited(
ARRAY_OPEN,
Expand All @@ -39,7 +39,7 @@ const ARRAY_SEP: u8 = b',';

// array-values = ws-comment-newline val ws-comment-newline array-sep array-values
// array-values =/ ws-comment-newline val ws-comment-newline [ array-sep ]
pub(crate) fn array_values(input: &mut Input<'_>) -> PResult<Array> {
pub(crate) fn array_values(input: &mut Input<'_>) -> ModalResult<Array> {
if peek(opt(ARRAY_CLOSE)).parse_next(input)?.is_some() {
// Optimize for empty arrays, avoiding `value` from being expected to fail
return Ok(Array::new());
Expand All @@ -57,7 +57,7 @@ pub(crate) fn array_values(input: &mut Input<'_>) -> PResult<Array> {
Ok(array)
}

pub(crate) fn array_value(input: &mut Input<'_>) -> PResult<Item> {
pub(crate) fn array_value(input: &mut Input<'_>) -> ModalResult<Item> {
let prefix = ws_comment_newline.span().parse_next(input)?;
let value = value.parse_next(input)?;
let suffix = ws_comment_newline.span().parse_next(input)?;
Expand Down
29 changes: 15 additions & 14 deletions crates/toml_edit/src/parser/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use winnow::token::take_while;
// local-date = full-date
// local-time = partial-time
// full-time = partial-time time-offset
pub(crate) fn date_time(input: &mut Input<'_>) -> PResult<Datetime> {
pub(crate) fn date_time(input: &mut Input<'_>) -> ModalResult<Datetime> {
trace(
"date-time",
alt((
Expand Down Expand Up @@ -53,11 +53,11 @@ pub(crate) fn date_time(input: &mut Input<'_>) -> PResult<Datetime> {
}

// full-date = date-fullyear "-" date-month "-" date-mday
pub(crate) fn full_date(input: &mut Input<'_>) -> PResult<Date> {
pub(crate) fn full_date(input: &mut Input<'_>) -> ModalResult<Date> {
trace("full-date", full_date_).parse_next(input)
}

fn full_date_(input: &mut Input<'_>) -> PResult<Date> {
fn full_date_(input: &mut Input<'_>) -> ModalResult<Date> {
let year = date_fullyear.parse_next(input)?;
let _ = b'-'.parse_next(input)?;
let month = cut_err(date_month).parse_next(input)?;
Expand All @@ -74,6 +74,7 @@ fn full_date_(input: &mut Input<'_>) -> PResult<Date> {
};
if max_days_in_month < day {
input.reset(&day_start);
#[expect(deprecated)]
return Err(winnow::error::ErrMode::from_external_error(
input,
winnow::error::ErrorKind::Verify,
Expand All @@ -86,7 +87,7 @@ fn full_date_(input: &mut Input<'_>) -> PResult<Date> {
}

// partial-time = time-hour ":" time-minute ":" time-second [time-secfrac]
pub(crate) fn partial_time(input: &mut Input<'_>) -> PResult<Time> {
pub(crate) fn partial_time(input: &mut Input<'_>) -> ModalResult<Time> {
trace(
"partial-time",
(
Expand All @@ -106,7 +107,7 @@ pub(crate) fn partial_time(input: &mut Input<'_>) -> PResult<Time> {

// time-offset = "Z" / time-numoffset
// time-numoffset = ( "+" / "-" ) time-hour ":" time-minute
pub(crate) fn time_offset(input: &mut Input<'_>) -> PResult<Offset> {
pub(crate) fn time_offset(input: &mut Input<'_>) -> ModalResult<Offset> {
trace(
"time-offset",
alt((
Expand All @@ -132,14 +133,14 @@ pub(crate) fn time_offset(input: &mut Input<'_>) -> PResult<Offset> {
}

// date-fullyear = 4DIGIT
pub(crate) fn date_fullyear(input: &mut Input<'_>) -> PResult<u16> {
pub(crate) fn date_fullyear(input: &mut Input<'_>) -> ModalResult<u16> {
unsigned_digits::<4, 4>
.map(|s: &str| s.parse::<u16>().expect("4DIGIT should match u8"))
.parse_next(input)
}

// date-month = 2DIGIT ; 01-12
pub(crate) fn date_month(input: &mut Input<'_>) -> PResult<u8> {
pub(crate) fn date_month(input: &mut Input<'_>) -> ModalResult<u8> {
unsigned_digits::<2, 2>
.try_map(|s: &str| {
let d = s.parse::<u8>().expect("2DIGIT should match u8");
Expand All @@ -153,7 +154,7 @@ pub(crate) fn date_month(input: &mut Input<'_>) -> PResult<u8> {
}

// date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on month/year
pub(crate) fn date_mday(input: &mut Input<'_>) -> PResult<u8> {
pub(crate) fn date_mday(input: &mut Input<'_>) -> ModalResult<u8> {
unsigned_digits::<2, 2>
.try_map(|s: &str| {
let d = s.parse::<u8>().expect("2DIGIT should match u8");
Expand All @@ -167,14 +168,14 @@ pub(crate) fn date_mday(input: &mut Input<'_>) -> PResult<u8> {
}

// time-delim = "T" / %x20 ; T, t, or space
pub(crate) fn time_delim(input: &mut Input<'_>) -> PResult<u8> {
pub(crate) fn time_delim(input: &mut Input<'_>) -> ModalResult<u8> {
one_of(TIME_DELIM).parse_next(input)
}

const TIME_DELIM: (u8, u8, u8) = (b'T', b't', b' ');

// time-hour = 2DIGIT ; 00-23
pub(crate) fn time_hour(input: &mut Input<'_>) -> PResult<u8> {
pub(crate) fn time_hour(input: &mut Input<'_>) -> ModalResult<u8> {
unsigned_digits::<2, 2>
.try_map(|s: &str| {
let d = s.parse::<u8>().expect("2DIGIT should match u8");
Expand All @@ -188,7 +189,7 @@ pub(crate) fn time_hour(input: &mut Input<'_>) -> PResult<u8> {
}

// time-minute = 2DIGIT ; 00-59
pub(crate) fn time_minute(input: &mut Input<'_>) -> PResult<u8> {
pub(crate) fn time_minute(input: &mut Input<'_>) -> ModalResult<u8> {
unsigned_digits::<2, 2>
.try_map(|s: &str| {
let d = s.parse::<u8>().expect("2DIGIT should match u8");
Expand All @@ -202,7 +203,7 @@ pub(crate) fn time_minute(input: &mut Input<'_>) -> PResult<u8> {
}

// time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second rules
pub(crate) fn time_second(input: &mut Input<'_>) -> PResult<u8> {
pub(crate) fn time_second(input: &mut Input<'_>) -> ModalResult<u8> {
unsigned_digits::<2, 2>
.try_map(|s: &str| {
let d = s.parse::<u8>().expect("2DIGIT should match u8");
Expand All @@ -216,7 +217,7 @@ pub(crate) fn time_second(input: &mut Input<'_>) -> PResult<u8> {
}

// time-secfrac = "." 1*DIGIT
pub(crate) fn time_secfrac(input: &mut Input<'_>) -> PResult<u32> {
pub(crate) fn time_secfrac(input: &mut Input<'_>) -> ModalResult<u32> {
static SCALE: [u32; 10] = [
0,
100_000_000,
Expand Down Expand Up @@ -253,7 +254,7 @@ pub(crate) fn time_secfrac(input: &mut Input<'_>) -> PResult<u32> {

pub(crate) fn unsigned_digits<'i, const MIN: usize, const MAX: usize>(
input: &mut Input<'i>,
) -> PResult<&'i str> {
) -> ModalResult<&'i str> {
take_while(MIN..=MAX, DIGIT)
.map(|b: &[u8]| unsafe { from_utf8_unchecked(b, "`is_ascii_digit` filters out on-ASCII") })
.parse_next(input)
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 @@ -97,7 +97,7 @@ pub(crate) fn keyval<'s, 'i>(
}

// keyval = key keyval-sep val
pub(crate) fn parse_keyval(input: &mut Input<'_>) -> PResult<(Vec<Key>, (Key, Item))> {
pub(crate) fn parse_keyval(input: &mut Input<'_>) -> ModalResult<(Vec<Key>, (Key, Item))> {
trace(
"keyval",
(
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
Expand Up @@ -17,7 +17,7 @@ use indexmap::map::Entry;
// ;; Inline Table

// inline-table = inline-table-open inline-table-keyvals inline-table-close
pub(crate) fn inline_table<'i>(input: &mut Input<'i>) -> PResult<InlineTable> {
pub(crate) fn inline_table<'i>(input: &mut Input<'i>) -> ModalResult<InlineTable> {
trace("inline-table", move |input: &mut Input<'i>| {
delimited(
INLINE_TABLE_OPEN,
Expand Down Expand Up @@ -117,15 +117,15 @@ pub(crate) const KEYVAL_SEP: u8 = b'=';

fn inline_table_keyvals(
input: &mut Input<'_>,
) -> PResult<(Vec<(Vec<Key>, (Key, Item))>, RawString)> {
) -> ModalResult<(Vec<(Vec<Key>, (Key, Item))>, RawString)> {
(
separated(0.., keyval, INLINE_TABLE_SEP),
ws.span().map(RawString::with_span),
)
.parse_next(input)
}

fn keyval(input: &mut Input<'_>) -> PResult<(Vec<Key>, (Key, Item))> {
fn keyval(input: &mut Input<'_>) -> ModalResult<(Vec<Key>, (Key, Item))> {
(
key,
cut_err((
Expand Down
6 changes: 3 additions & 3 deletions crates/toml_edit/src/parser/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::RawString;

// key = simple-key / dotted-key
// dotted-key = simple-key 1*( dot-sep simple-key )
pub(crate) fn key(input: &mut Input<'_>) -> PResult<Vec<Key>> {
pub(crate) fn key(input: &mut Input<'_>) -> ModalResult<Vec<Key>> {
let mut key_path = trace(
"dotted-key",
separated(
Expand Down Expand Up @@ -68,7 +68,7 @@ pub(crate) fn key(input: &mut Input<'_>) -> PResult<Vec<Key>> {

// simple-key = quoted-key / unquoted-key
// quoted-key = basic-string / literal-string
pub(crate) fn simple_key(input: &mut Input<'_>) -> PResult<(RawString, InternalString)> {
pub(crate) fn simple_key(input: &mut Input<'_>) -> ModalResult<(RawString, InternalString)> {
trace(
"simple-key",
dispatch! {peek(any);
Expand All @@ -87,7 +87,7 @@ pub(crate) fn simple_key(input: &mut Input<'_>) -> PResult<(RawString, InternalS
}

// unquoted-key = 1*( ALPHA / DIGIT / %x2D / %x5F ) ; A-Z / a-z / 0-9 / - / _
fn unquoted_key<'i>(input: &mut Input<'i>) -> PResult<&'i str> {
fn unquoted_key<'i>(input: &mut Input<'i>) -> ModalResult<&'i str> {
trace(
"unquoted-key",
take_while(1.., UNQUOTED_CHAR)
Expand Down
8 changes: 5 additions & 3 deletions crates/toml_edit/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ pub(crate) mod prelude {
pub(crate) use winnow::error::FromExternalError;
pub(crate) use winnow::error::StrContext;
pub(crate) use winnow::error::StrContextValue;
pub(crate) use winnow::PResult;
pub(crate) use winnow::ModalResult;
pub(crate) use winnow::Parser;

pub(crate) type Input<'b> = winnow::Stateful<winnow::Located<&'b winnow::BStr>, RecursionCheck>;
pub(crate) type Input<'b> =
winnow::Stateful<winnow::LocatingSlice<&'b winnow::BStr>, RecursionCheck>;

pub(crate) fn new_input(s: &str) -> Input<'_> {
winnow::Stateful {
input: winnow::Located::new(winnow::BStr::new(s)),
input: winnow::LocatingSlice::new(winnow::BStr::new(s)),
state: Default::default(),
}
}
Expand Down Expand Up @@ -138,6 +139,7 @@ pub(crate) mod prelude {
) -> impl Parser<Input<'b>, O, ContextError> {
move |input: &mut Input<'b>| {
input.state.enter().map_err(|err| {
#[allow(deprecated)]
winnow::error::ErrMode::from_external_error(
input,
winnow::error::ErrorKind::Eof,
Expand Down
Loading

0 comments on commit 5dfa5b0

Please sign in to comment.