Skip to content

Commit 9415da2

Browse files
committed
refactor(parser): Switch to ModalParser
1 parent 5dfa5b0 commit 9415da2

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

crates/toml_edit/src/parser/document.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::RawString;
3030
// ws )
3131
pub(crate) fn document<'s, 'i>(
3232
state_ref: &'s RefCell<ParseState>,
33-
) -> impl Parser<Input<'i>, (), ContextError> + 's {
33+
) -> impl ModalParser<Input<'i>, (), ContextError> + 's {
3434
move |i: &mut Input<'i>| {
3535
(
3636
// Remove BOM if present
@@ -54,7 +54,7 @@ pub(crate) fn document<'s, 'i>(
5454

5555
pub(crate) fn parse_comment<'s, 'i>(
5656
state: &'s RefCell<ParseState>,
57-
) -> impl Parser<Input<'i>, (), ContextError> + 's {
57+
) -> impl ModalParser<Input<'i>, (), ContextError> + 's {
5858
move |i: &mut Input<'i>| {
5959
(comment, line_ending)
6060
.span()
@@ -67,7 +67,7 @@ pub(crate) fn parse_comment<'s, 'i>(
6767

6868
pub(crate) fn parse_ws<'s, 'i>(
6969
state: &'s RefCell<ParseState>,
70-
) -> impl Parser<Input<'i>, (), ContextError> + 's {
70+
) -> impl ModalParser<Input<'i>, (), ContextError> + 's {
7171
move |i: &mut Input<'i>| {
7272
ws.span()
7373
.map(|span| state.borrow_mut().on_ws(span))
@@ -77,7 +77,7 @@ pub(crate) fn parse_ws<'s, 'i>(
7777

7878
pub(crate) fn parse_newline<'s, 'i>(
7979
state: &'s RefCell<ParseState>,
80-
) -> impl Parser<Input<'i>, (), ContextError> + 's {
80+
) -> impl ModalParser<Input<'i>, (), ContextError> + 's {
8181
move |i: &mut Input<'i>| {
8282
newline
8383
.span()
@@ -88,7 +88,7 @@ pub(crate) fn parse_newline<'s, 'i>(
8888

8989
pub(crate) fn keyval<'s, 'i>(
9090
state: &'s RefCell<ParseState>,
91-
) -> impl Parser<Input<'i>, (), ContextError> + 's {
91+
) -> impl ModalParser<Input<'i>, (), ContextError> + 's {
9292
move |i: &mut Input<'i>| {
9393
parse_keyval
9494
.try_map(|(p, kv)| state.borrow_mut().on_keyval(p, kv))

crates/toml_edit/src/parser/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ pub(crate) mod prelude {
8383
pub(crate) use winnow::error::FromExternalError;
8484
pub(crate) use winnow::error::StrContext;
8585
pub(crate) use winnow::error::StrContextValue;
86+
pub(crate) use winnow::ModalParser;
8687
pub(crate) use winnow::ModalResult;
87-
pub(crate) use winnow::Parser;
88+
pub(crate) use winnow::Parser as _;
8889

8990
pub(crate) type Input<'b> =
9091
winnow::Stateful<winnow::LocatingSlice<&'b winnow::BStr>, RecursionCheck>;
@@ -135,8 +136,8 @@ pub(crate) mod prelude {
135136
}
136137

137138
pub(crate) fn check_recursion<'b, O>(
138-
mut parser: impl Parser<Input<'b>, O, ContextError>,
139-
) -> impl Parser<Input<'b>, O, ContextError> {
139+
mut parser: impl ModalParser<Input<'b>, O, ContextError>,
140+
) -> impl ModalParser<Input<'b>, O, ContextError> {
140141
move |input: &mut Input<'b>| {
141142
input.state.enter().map_err(|err| {
142143
#[allow(deprecated)]

crates/toml_edit/src/parser/strings.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ fn mlb_content<'i>(input: &mut Input<'i>) -> ModalResult<Cow<'i, str>> {
212212

213213
// mlb-quotes = 1*2quotation-mark
214214
fn mlb_quotes<'i>(
215-
mut term: impl Parser<Input<'i>, (), ContextError>,
216-
) -> impl Parser<Input<'i>, &'i str, ContextError> {
215+
mut term: impl ModalParser<Input<'i>, (), ContextError>,
216+
) -> impl ModalParser<Input<'i>, &'i str, ContextError> {
217217
move |input: &mut Input<'i>| {
218218
let start = input.checkpoint();
219219
let res = terminated(b"\"\"", peek(term.by_ref()))
@@ -341,8 +341,8 @@ const MLL_CHAR: (
341341

342342
// mll-quotes = 1*2apostrophe
343343
fn mll_quotes<'i>(
344-
mut term: impl Parser<Input<'i>, (), ContextError>,
345-
) -> impl Parser<Input<'i>, &'i str, ContextError> {
344+
mut term: impl ModalParser<Input<'i>, (), ContextError>,
345+
) -> impl ModalParser<Input<'i>, &'i str, ContextError> {
346346
move |input: &mut Input<'i>| {
347347
let start = input.checkpoint();
348348
let res = terminated(b"''", peek(term.by_ref()))

crates/toml_edit/src/parser/table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const ARRAY_TABLE_CLOSE: &[u8] = b"]]";
2727
// std-table = std-table-open key *( table-key-sep key) std-table-close
2828
pub(crate) fn std_table<'s, 'i>(
2929
state: &'s RefCell<ParseState>,
30-
) -> impl Parser<Input<'i>, (), ContextError> + 's {
30+
) -> impl ModalParser<Input<'i>, (), ContextError> + 's {
3131
move |i: &mut Input<'i>| {
3232
(
3333
delimited(
@@ -52,7 +52,7 @@ pub(crate) fn std_table<'s, 'i>(
5252
// array-table = array-table-open key *( table-key-sep key) array-table-close
5353
pub(crate) fn array_table<'s, 'i>(
5454
state: &'s RefCell<ParseState>,
55-
) -> impl Parser<Input<'i>, (), ContextError> + 's {
55+
) -> impl ModalParser<Input<'i>, (), ContextError> + 's {
5656
move |i: &mut Input<'i>| {
5757
(
5858
delimited(
@@ -77,7 +77,7 @@ pub(crate) fn array_table<'s, 'i>(
7777
// table = std-table / array-table
7878
pub(crate) fn table<'s, 'i>(
7979
state: &'s RefCell<ParseState>,
80-
) -> impl Parser<Input<'i>, (), ContextError> + 's {
80+
) -> impl ModalParser<Input<'i>, (), ContextError> + 's {
8181
move |i: &mut Input<'i>| {
8282
dispatch!(peek::<_, &[u8],_,_>(take(2usize));
8383
b"[[" => array_table(state),

0 commit comments

Comments
 (0)