diff options
author | Jeff Vander Stoep <jeffv@google.com> | 2024-02-06 10:40:55 +0100 |
---|---|---|
committer | Jeff Vander Stoep <jeffv@google.com> | 2024-02-06 10:40:56 +0100 |
commit | 0c65325da3ac3393f0f225cb4d19c3f289fa3519 (patch) | |
tree | 919294d605d7361ac40c3deea144cdbcc5b9e114 /examples/json/parser.rs | |
parent | f6d664c3704dcfcacc50119bfa66f3602e65d0db (diff) | |
download | winnow-0c65325da3ac3393f0f225cb4d19c3f289fa3519.tar.gz |
Upgrade winnow to 0.5.37
This project was upgraded with external_updater.
Usage: tools/external_updater/updater.sh update external/rust/crates/winnow
For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
Test: TreeHugger
Change-Id: Id9853a0897914f6ee0f2fe4be69c89d907cbda01
Diffstat (limited to 'examples/json/parser.rs')
-rw-r--r-- | examples/json/parser.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/examples/json/parser.rs b/examples/json/parser.rs index 8aa3bd3..e8d9c8a 100644 --- a/examples/json/parser.rs +++ b/examples/json/parser.rs @@ -7,7 +7,7 @@ use winnow::{ combinator::alt, combinator::cut_err, combinator::{delimited, preceded, separated_pair, terminated}, - combinator::{fold_repeat, separated0}, + combinator::{repeat, separated}, error::{AddContext, ParserError}, token::{any, none_of, take, take_while}, }; @@ -87,7 +87,7 @@ fn string<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>> // right branch (since we found the `"` character) but encountered an error when // parsing the string cut_err(terminated( - fold_repeat(0.., character, String::new, |mut string, c| { + repeat(0.., character).fold(String::new, |mut string, c| { string.push(c); string }), @@ -153,7 +153,7 @@ fn u16_hex<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<u1 .parse_next(input) } -/// Some combinators, like `separated0` or `many0`, will call a parser repeatedly, +/// Some combinators, like `separated` or `repeat`, will call a parser repeatedly, /// accumulating results in a `Vec`, until it encounters an error. /// If you want more control on the parser application, check out the `iterator` /// combinator (cf `examples/iterator.rs`) @@ -162,7 +162,10 @@ fn array<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>( ) -> PResult<Vec<JsonValue>, E> { preceded( ('[', ws), - cut_err(terminated(separated0(json_value, (ws, ',', ws)), (ws, ']'))), + cut_err(terminated( + separated(0.., json_value, (ws, ',', ws)), + (ws, ']'), + )), ) .context("array") .parse_next(input) @@ -173,7 +176,10 @@ fn object<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>> ) -> PResult<HashMap<String, JsonValue>, E> { preceded( ('{', ws), - cut_err(terminated(separated0(key_value, (ws, ',', ws)), (ws, '}'))), + cut_err(terminated( + separated(0.., key_value, (ws, ',', ws)), + (ws, '}'), + )), ) .context("object") .parse_next(input) |