Skip to content

Commit faac518

Browse files
authored
Merge pull request #555 from epage/winnow
refactor(parser): Resolve deprecations
2 parents 0951271 + a52a722 commit faac518

File tree

7 files changed

+103
-81
lines changed

7 files changed

+103
-81
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/toml_edit/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ unbounded = []
4040

4141
[dependencies]
4242
indexmap = { version = "1.9.1", features = ["std"] }
43-
winnow = "0.4.3"
43+
winnow = "0.4.6"
4444
serde = { version = "1.0.145", optional = true }
4545
kstring = { version = "2.0.0", features = ["max_inline"], optional = true }
4646
toml_datetime = { version = "0.6.1", path = "../toml_datetime" }

crates/toml_edit/src/parser/document.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use winnow::combinator::cut_err;
44
use winnow::combinator::eof;
55
use winnow::combinator::opt;
66
use winnow::combinator::peek;
7-
use winnow::combinator::repeat0;
7+
use winnow::combinator::repeat;
88
use winnow::error::FromExternalError;
99
use winnow::token::any;
1010
use winnow::token::one_of;
@@ -38,7 +38,7 @@ pub(crate) fn document(input: Input<'_>) -> IResult<Input<'_>, Document, ParserE
3838
// Remove BOM if present
3939
opt(b"\xEF\xBB\xBF"),
4040
parse_ws(state_ref),
41-
repeat0((
41+
repeat(0.., (
4242
dispatch! {peek(any);
4343
crate::parser::trivia::COMMENT_START_SYMBOL => cut_err(parse_comment(state_ref)),
4444
crate::parser::table::STD_TABLE_OPEN => cut_err(table(state_ref)),

crates/toml_edit/src/parser/key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ops::RangeInclusive;
33
use winnow::combinator::peek;
44
use winnow::combinator::separated1;
55
use winnow::token::any;
6-
use winnow::token::take_while1;
6+
use winnow::token::take_while;
77

88
use crate::key::Key;
99
use crate::parser::errors::CustomError;
@@ -58,7 +58,7 @@ pub(crate) fn simple_key(
5858

5959
// unquoted-key = 1*( ALPHA / DIGIT / %x2D / %x5F ) ; A-Z / a-z / 0-9 / - / _
6060
fn unquoted_key(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> {
61-
take_while1(UNQUOTED_CHAR)
61+
take_while(1.., UNQUOTED_CHAR)
6262
.map(|b| unsafe { from_utf8_unchecked(b, "`is_unquoted_char` filters out on-ASCII") })
6363
.parse_next(input)
6464
}

crates/toml_edit/src/parser/numbers.rs

+60-44
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use winnow::combinator::cut_err;
55
use winnow::combinator::opt;
66
use winnow::combinator::peek;
77
use winnow::combinator::preceded;
8-
use winnow::combinator::repeat0;
8+
use winnow::combinator::repeat;
99
use winnow::combinator::rest;
1010
use winnow::token::one_of;
1111
use winnow::token::tag;
@@ -56,15 +56,18 @@ pub(crate) fn dec_int(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<
5656
alt((
5757
(
5858
one_of(DIGIT1_9),
59-
repeat0(alt((
60-
digit.value(()),
61-
(
62-
one_of(b'_'),
63-
cut_err(digit)
64-
.context(Context::Expected(ParserValue::Description("digit"))),
65-
)
66-
.value(()),
67-
)))
59+
repeat(
60+
0..,
61+
alt((
62+
digit.value(()),
63+
(
64+
one_of(b'_'),
65+
cut_err(digit)
66+
.context(Context::Expected(ParserValue::Description("digit"))),
67+
)
68+
.value(()),
69+
)),
70+
)
6871
.map(|()| ()),
6972
)
7073
.value(()),
@@ -85,14 +88,18 @@ pub(crate) fn hex_int(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<
8588
HEX_PREFIX,
8689
cut_err((
8790
hexdig,
88-
repeat0(alt((
89-
hexdig.value(()),
90-
(
91-
one_of(b'_'),
92-
cut_err(hexdig).context(Context::Expected(ParserValue::Description("digit"))),
93-
)
94-
.value(()),
95-
)))
91+
repeat(
92+
0..,
93+
alt((
94+
hexdig.value(()),
95+
(
96+
one_of(b'_'),
97+
cut_err(hexdig)
98+
.context(Context::Expected(ParserValue::Description("digit"))),
99+
)
100+
.value(()),
101+
)),
102+
)
96103
.map(|()| ()),
97104
))
98105
.recognize(),
@@ -110,15 +117,18 @@ pub(crate) fn oct_int(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<
110117
OCT_PREFIX,
111118
cut_err((
112119
one_of(DIGIT0_7),
113-
repeat0(alt((
114-
one_of(DIGIT0_7).value(()),
115-
(
116-
one_of(b'_'),
117-
cut_err(one_of(DIGIT0_7))
118-
.context(Context::Expected(ParserValue::Description("digit"))),
119-
)
120-
.value(()),
121-
)))
120+
repeat(
121+
0..,
122+
alt((
123+
one_of(DIGIT0_7).value(()),
124+
(
125+
one_of(b'_'),
126+
cut_err(one_of(DIGIT0_7))
127+
.context(Context::Expected(ParserValue::Description("digit"))),
128+
)
129+
.value(()),
130+
)),
131+
)
122132
.map(|()| ()),
123133
))
124134
.recognize(),
@@ -137,15 +147,18 @@ pub(crate) fn bin_int(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<
137147
BIN_PREFIX,
138148
cut_err((
139149
one_of(DIGIT0_1),
140-
repeat0(alt((
141-
one_of(DIGIT0_1).value(()),
142-
(
143-
one_of(b'_'),
144-
cut_err(one_of(DIGIT0_1))
145-
.context(Context::Expected(ParserValue::Description("digit"))),
146-
)
147-
.value(()),
148-
)))
150+
repeat(
151+
0..,
152+
alt((
153+
one_of(DIGIT0_1).value(()),
154+
(
155+
one_of(b'_'),
156+
cut_err(one_of(DIGIT0_1))
157+
.context(Context::Expected(ParserValue::Description("digit"))),
158+
)
159+
.value(()),
160+
)),
161+
)
149162
.map(|()| ()),
150163
))
151164
.recognize(),
@@ -207,14 +220,17 @@ pub(crate) fn frac(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>
207220
pub(crate) fn zero_prefixable_int(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> {
208221
(
209222
digit,
210-
repeat0(alt((
211-
digit.value(()),
212-
(
213-
one_of(b'_'),
214-
cut_err(digit).context(Context::Expected(ParserValue::Description("digit"))),
215-
)
216-
.value(()),
217-
)))
223+
repeat(
224+
0..,
225+
alt((
226+
digit.value(()),
227+
(
228+
one_of(b'_'),
229+
cut_err(digit).context(Context::Expected(ParserValue::Description("digit"))),
230+
)
231+
.value(()),
232+
)),
233+
)
218234
.map(|()| ()),
219235
)
220236
.recognize()

crates/toml_edit/src/parser/strings.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use winnow::combinator::fail;
99
use winnow::combinator::opt;
1010
use winnow::combinator::peek;
1111
use winnow::combinator::preceded;
12-
use winnow::combinator::repeat0;
13-
use winnow::combinator::repeat1;
12+
use winnow::combinator::repeat;
1413
use winnow::combinator::success;
1514
use winnow::combinator::terminated;
1615
use winnow::prelude::*;
@@ -19,8 +18,6 @@ use winnow::token::none_of;
1918
use winnow::token::one_of;
2019
use winnow::token::tag;
2120
use winnow::token::take_while;
22-
use winnow::token::take_while0;
23-
use winnow::token::take_while1;
2421

2522
use crate::parser::errors::CustomError;
2623
use crate::parser::numbers::HEXDIG;
@@ -71,7 +68,7 @@ fn basic_chars(input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, ParserError
7168
alt((
7269
// Deviate from the official grammar by batching the unescaped chars so we build a string a
7370
// chunk at a time, rather than a `char` at a time.
74-
take_while1(BASIC_UNESCAPED)
71+
take_while(1.., BASIC_UNESCAPED)
7572
.try_map(std::str::from_utf8)
7673
.map(Cow::Borrowed),
7774
escaped.map(|c| Cow::Owned(String::from(c))),
@@ -203,7 +200,7 @@ fn mlb_content(input: Input<'_>) -> IResult<Input<'_>, Cow<'_, str>, ParserError
203200
alt((
204201
// Deviate from the official grammar by batching the unescaped chars so we build a string a
205202
// chunk at a time, rather than a `char` at a time.
206-
take_while1(MLB_UNESCAPED)
203+
take_while(1.., MLB_UNESCAPED)
207204
.try_map(std::str::from_utf8)
208205
.map(Cow::Borrowed),
209206
// Order changed fromg grammar so `escaped` can more easily `cut_err` on bad escape sequences
@@ -247,7 +244,7 @@ pub(crate) const MLB_UNESCAPED: (
247244
// (including newlines) up to the next non-whitespace
248245
// character or closing delimiter.
249246
fn mlb_escaped_nl(input: Input<'_>) -> IResult<Input<'_>, (), ParserError<'_>> {
250-
repeat1((ESCAPE, ws, ws_newlines))
247+
repeat(1.., (ESCAPE, ws, ws_newlines))
251248
.map(|()| ())
252249
.value(())
253250
.parse_next(input)
@@ -259,7 +256,7 @@ fn mlb_escaped_nl(input: Input<'_>) -> IResult<Input<'_>, (), ParserError<'_>> {
259256
pub(crate) fn literal_string(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> {
260257
delimited(
261258
APOSTROPHE,
262-
cut_err(take_while0(LITERAL_CHAR)),
259+
cut_err(take_while(0.., LITERAL_CHAR)),
263260
cut_err(APOSTROPHE),
264261
)
265262
.try_map(std::str::from_utf8)
@@ -304,11 +301,14 @@ pub(crate) const ML_LITERAL_STRING_DELIM: &[u8] = b"'''";
304301
// ml-literal-body = *mll-content *( mll-quotes 1*mll-content ) [ mll-quotes ]
305302
fn ml_literal_body(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> {
306303
(
307-
repeat0(mll_content).map(|()| ()),
308-
repeat0((
309-
mll_quotes(none_of(APOSTROPHE).value(())),
310-
repeat1(mll_content).map(|()| ()),
311-
))
304+
repeat(0.., mll_content).map(|()| ()),
305+
repeat(
306+
0..,
307+
(
308+
mll_quotes(none_of(APOSTROPHE).value(())),
309+
repeat(1.., mll_content).map(|()| ()),
310+
),
311+
)
312312
.map(|()| ()),
313313
opt(mll_quotes(tag(ML_LITERAL_STRING_DELIM).value(()))),
314314
)

crates/toml_edit/src/parser/trivia.rs

+23-17
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ use std::ops::RangeInclusive;
33
use winnow::combinator::alt;
44
use winnow::combinator::eof;
55
use winnow::combinator::opt;
6-
use winnow::combinator::repeat0;
7-
use winnow::combinator::repeat1;
6+
use winnow::combinator::repeat;
87
use winnow::combinator::terminated;
98
use winnow::prelude::*;
109
use winnow::token::one_of;
11-
use winnow::token::take_while0;
12-
use winnow::token::take_while1;
10+
use winnow::token::take_while;
1311

1412
use crate::parser::prelude::*;
1513

@@ -31,7 +29,7 @@ pub(crate) const WSCHAR: (u8, u8) = (b' ', b'\t');
3129

3230
// ws = *wschar
3331
pub(crate) fn ws(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> {
34-
take_while0(WSCHAR)
32+
take_while(0.., WSCHAR)
3533
.map(|b| unsafe { from_utf8_unchecked(b, "`is_wschar` filters out on-ASCII") })
3634
.parse_next(input)
3735
}
@@ -51,7 +49,7 @@ pub(crate) const COMMENT_START_SYMBOL: u8 = b'#';
5149

5250
// comment = comment-start-symbol *non-eol
5351
pub(crate) fn comment(input: Input<'_>) -> IResult<Input<'_>, &[u8], ParserError<'_>> {
54-
(COMMENT_START_SYMBOL, take_while0(NON_EOL))
52+
(COMMENT_START_SYMBOL, take_while(0.., NON_EOL))
5553
.recognize()
5654
.parse_next(input)
5755
}
@@ -70,13 +68,14 @@ pub(crate) const CR: u8 = b'\r';
7068

7169
// ws-newline = *( wschar / newline )
7270
pub(crate) fn ws_newline(input: Input<'_>) -> IResult<Input<'_>, &str, ParserError<'_>> {
73-
repeat0(alt((newline.value(&b"\n"[..]), take_while1(WSCHAR))))
74-
.map(|()| ())
75-
.recognize()
76-
.map(|b| unsafe {
77-
from_utf8_unchecked(b, "`is_wschar` and `newline` filters out on-ASCII")
78-
})
79-
.parse_next(input)
71+
repeat(
72+
0..,
73+
alt((newline.value(&b"\n"[..]), take_while(1.., WSCHAR))),
74+
)
75+
.map(|()| ())
76+
.recognize()
77+
.map(|b| unsafe { from_utf8_unchecked(b, "`is_wschar` and `newline` filters out on-ASCII") })
78+
.parse_next(input)
8079
}
8180

8281
// ws-newlines = newline *( wschar / newline )
@@ -92,10 +91,17 @@ pub(crate) fn ws_newlines(input: Input<'_>) -> IResult<Input<'_>, &str, ParserEr
9291
// note: this rule is not present in the original grammar
9392
// ws-comment-newline = *( ws-newline-nonempty / comment )
9493
pub(crate) fn ws_comment_newline(input: Input<'_>) -> IResult<Input<'_>, &[u8], ParserError<'_>> {
95-
repeat0(alt((
96-
repeat1(alt((take_while1(WSCHAR), newline.value(&b"\n"[..])))).map(|()| ()),
97-
comment.value(()),
98-
)))
94+
repeat(
95+
0..,
96+
alt((
97+
repeat(
98+
1..,
99+
alt((take_while(1.., WSCHAR), newline.value(&b"\n"[..]))),
100+
)
101+
.map(|()| ()),
102+
comment.value(()),
103+
)),
104+
)
99105
.map(|()| ())
100106
.recognize()
101107
.parse_next(input)

0 commit comments

Comments
 (0)