summaryrefslogtreecommitdiffstats
path: root/vendor/winnow
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /vendor/winnow
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/winnow')
-rw-r--r--vendor/winnow/.cargo-checksum.json2
-rw-r--r--vendor/winnow/Cargo.lock526
-rw-r--r--vendor/winnow/Cargo.toml20
-rw-r--r--vendor/winnow/benches/contains_token.rs28
-rw-r--r--vendor/winnow/benches/number.rs34
-rw-r--r--vendor/winnow/examples/arithmetic/bench.rs6
-rw-r--r--vendor/winnow/examples/arithmetic/parser.rs43
-rw-r--r--vendor/winnow/examples/arithmetic/parser_ast.rs64
-rw-r--r--vendor/winnow/examples/css/main.rs2
-rw-r--r--vendor/winnow/examples/css/parser.rs14
-rw-r--r--vendor/winnow/examples/custom_error.rs20
-rw-r--r--vendor/winnow/examples/http/parser.rs77
-rw-r--r--vendor/winnow/examples/http/parser_streaming.rs76
-rw-r--r--vendor/winnow/examples/ini/bench.rs10
-rw-r--r--vendor/winnow/examples/ini/parser.rs26
-rw-r--r--vendor/winnow/examples/ini/parser_str.rs48
-rw-r--r--vendor/winnow/examples/iterator.rs26
-rw-r--r--vendor/winnow/examples/json/bench.rs28
-rw-r--r--vendor/winnow/examples/json/main.rs46
-rw-r--r--vendor/winnow/examples/json/parser.rs101
-rw-r--r--vendor/winnow/examples/json/parser_dispatch.rs103
-rw-r--r--vendor/winnow/examples/json/parser_partial.rs108
-rw-r--r--vendor/winnow/examples/json_iterator.rs106
-rw-r--r--vendor/winnow/examples/ndjson/main.rs7
-rw-r--r--vendor/winnow/examples/ndjson/parser.rs100
-rw-r--r--vendor/winnow/examples/s_expression/parser.rs67
-rw-r--r--vendor/winnow/examples/string/parser.rs28
-rw-r--r--vendor/winnow/src/_topic/error.rs4
-rw-r--r--vendor/winnow/src/_topic/language.rs67
-rw-r--r--vendor/winnow/src/_topic/performance.rs10
-rw-r--r--vendor/winnow/src/_topic/stream.rs4
-rw-r--r--vendor/winnow/src/_tutorial/chapter_1.rs44
-rw-r--r--vendor/winnow/src/_tutorial/chapter_2.rs185
-rw-r--r--vendor/winnow/src/_tutorial/chapter_3.rs249
-rw-r--r--vendor/winnow/src/_tutorial/chapter_4.rs48
-rw-r--r--vendor/winnow/src/_tutorial/chapter_5.rs185
-rw-r--r--vendor/winnow/src/_tutorial/chapter_6.rs89
-rw-r--r--vendor/winnow/src/_tutorial/chapter_7.rs72
-rw-r--r--vendor/winnow/src/ascii/mod.rs1074
-rw-r--r--vendor/winnow/src/ascii/tests.rs660
-rw-r--r--vendor/winnow/src/binary/bits/mod.rs189
-rw-r--r--vendor/winnow/src/binary/bits/tests.rs55
-rw-r--r--vendor/winnow/src/binary/mod.rs734
-rw-r--r--vendor/winnow/src/binary/tests.rs460
-rw-r--r--vendor/winnow/src/bits.rs71
-rw-r--r--vendor/winnow/src/branch.rs10
-rw-r--r--vendor/winnow/src/bytes.rs26
-rw-r--r--vendor/winnow/src/character.rs342
-rw-r--r--vendor/winnow/src/combinator/branch.rs80
-rw-r--r--vendor/winnow/src/combinator/core.rs175
-rw-r--r--vendor/winnow/src/combinator/multi.rs454
-rw-r--r--vendor/winnow/src/combinator/parser.rs265
-rw-r--r--vendor/winnow/src/combinator/sequence.rs76
-rw-r--r--vendor/winnow/src/combinator/tests.rs268
-rw-r--r--vendor/winnow/src/error.rs827
-rw-r--r--vendor/winnow/src/lib.rs19
-rw-r--r--vendor/winnow/src/macros.rs10
-rw-r--r--vendor/winnow/src/multi.rs124
-rw-r--r--vendor/winnow/src/number.rs509
-rw-r--r--vendor/winnow/src/parser.rs394
-rw-r--r--vendor/winnow/src/sequence.rs9
-rw-r--r--vendor/winnow/src/stream/mod.rs621
-rw-r--r--vendor/winnow/src/stream/tests.rs26
-rw-r--r--vendor/winnow/src/token/mod.rs447
-rw-r--r--vendor/winnow/src/token/tests.rs123
-rw-r--r--vendor/winnow/src/trace/internals.rs12
-rw-r--r--vendor/winnow/src/trace/mod.rs29
67 files changed, 5241 insertions, 5521 deletions
diff --git a/vendor/winnow/.cargo-checksum.json b/vendor/winnow/.cargo-checksum.json
index e803852ff..fdb3c99e6 100644
--- a/vendor/winnow/.cargo-checksum.json
+++ b/vendor/winnow/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.lock":"a97963c07ee8bdbd7558cb03e7d5bb0c6a93d881782e67ab2e976b87889c2279","Cargo.toml":"ba95bb8977ffd618b27807e589aa2945401af603f4288322137510f0c46ab20f","LICENSE-MIT":"cb5aedb296c5246d1f22e9099f925a65146f9f0d6b4eebba97fd27a6cdbbab2d","README.md":"b66d0e430d8a5f5391f1f51b2d7959c3881fca59fdf76a075129591b396c1c62","benches/contains_token.rs":"66fbeef9130234573216a624c8753731aa517d8ca0aa5d26eff8b70706151ef2","benches/number.rs":"3007cf0c1f49c81e758bedf08dba7e273b7a17b6b5e4e6f8f09914e2d1e4e962","examples/arithmetic/bench.rs":"bee163fdb9573f53d24c95dbc187770efdaf17bf39917b91204b8ea38edab888","examples/arithmetic/main.rs":"aab0793c96add893bbaacea331bc05de8f6b59e47c5bccca67bfd30e924cd790","examples/arithmetic/parser.rs":"b298b04a8950d56f31653923a12aabca0f026a7e203b23778f6f29f053d7f2a4","examples/arithmetic/parser_ast.rs":"bb3f1a2721baf3f4eed22d996c97eb1bed4ea360295e286894d25a22465d127e","examples/css/main.rs":"0d74980404a118cc54871f4ad32bd9acc3aa5c0d6502760155399f66a57d4a0e","examples/css/parser.rs":"5716c470d41e3386a54e87e2d20e00bbe46cd121956c9bd28fa7aaca3a8549fb","examples/custom_error.rs":"b855f72e7ef33192f6be8ee761f59bc82249958f5f9279aa8ae6fafd0e97c711","examples/http/bench.rs":"b6d3e9e5833b53ac58f8336617cc42a2f3f4c5e5ce88feb23184fcdbb36843f6","examples/http/main.rs":"95d3c73953cd76ea462d886ade2ab34e987239bae3abb0349c434fb01b80467d","examples/http/parser.rs":"488ec918ac75307abe4f4a34f6fb119b317783b630fb2b6f0ed9075a962c4725","examples/http/parser_streaming.rs":"aa66a7383c440d229a60faf988bb6eacad04f2561fdb37f589cfb81bf3f5ccb2","examples/ini/bench.rs":"ddd4390f78cf9e44ec926caa5e15b673ac6da0faf35bb9939d42ffda7bbd07fd","examples/ini/main.rs":"d771aa8aae11e53f4f5453ac39e10ae3a1de210408dfd31ca7d1ce58d14c3fb9","examples/ini/parser.rs":"7e234914780ead1a8ac888075676831f6fd894004af01922eb5c370988b4b64f","examples/ini/parser_str.rs":"f0518209cb56650e30a6b0302cb3b4b06957206c89641b8bf7c5a4136e9913aa","examples/iterator.rs":"43e96c9e0a16911b51ba21092a05818485722b0c2d309e89a613b6d98096cff3","examples/json/bench.rs":"4fe77a79a9442c98eae9b0f808771763c71f61a191972955872dc2ebbfad8cfe","examples/json/json.rs":"48cf6c114098113c9767bebe430682f55f7c1a227e6486131ca58c00770711f2","examples/json/main.rs":"60c2be63c432f2c5da5c0c98ab7b2dfeae1851aa533dad67129dc5e0fa367130","examples/json/parser.rs":"b0e6198cb853ecf3f5b4e57bbabf7a5c12d7398572c1b317d12cb2740e85082b","examples/json/parser_dispatch.rs":"f8cff2899232d9634bb62cd7de6a1bfbea6db5f95ee16ac25fa387b51fb814a8","examples/json/parser_partial.rs":"457cc9f22596fece1aff9d7600960fa6c2683b32bd4339cc4546af8bfd820dba","examples/json_iterator.rs":"09066dc71939b9d92fec2bbec2e2df014a4a5444902fc38c510802df308d6155","examples/ndjson/example.ndjson":"c44c130731008bca76181348d40f46b183577949b5a4d229e0e1a56e1e405e5d","examples/ndjson/main.rs":"63ff8ad2311c1b10e436d9c4c5088493f6ed3359ba422028f388d1a5f9c94e66","examples/ndjson/parser.rs":"8cf135f44416dc90bb29b941fd026f47744d07dfa16f19912da944d5f70afa4f","examples/s_expression/main.rs":"5a2de0b477807c7d6ab8bb72579f03692e8f5ea89d5b6f3a8342cfdbe4d84b96","examples/s_expression/parser.rs":"f1cfe3a063aadce5e0969e8530778b9af4a20e345ed58cb38a10ce5b140ed421","examples/string/main.rs":"e6362f957d532d41bcd96476e55ac4c253eb04fa25ee88b48d872661a46a5bb5","examples/string/parser.rs":"a6cf23ab6adbc0a604074ef6763965f42195b96df21013479e0f47717bb33bac","src/_topic/arithmetic.rs":"94920a9572ed6deac58abb337a7be57b93cf37440f0cc3eaf514cb9ad9b9e077","src/_topic/error.rs":"e13463570e97b0ca2acea320fa721127b6e393328e798456dc2bbb6730b27a36","src/_topic/fromstr.rs":"01abdab296cd30067ae5f508b2b21ebe97c0571ace58e7817876eb2110e8d23a","src/_topic/http.rs":"19b9ec78a031fe5b3086fb34d04d6c13308c50b6e7bfe30229f5b682d3605ac8","src/_topic/ini.rs":"b2b04d48eac3158f4e26ee9dce748a699d02acaa0b12ae8d54421cad0fdc4ad7","src/_topic/json.rs":"bde39ee6b1c5fab2d2da480822b737674aed877f92c3f748d6932bec313b5661","src/_topic/language.rs":"231098363ae7d8f3b57ea7909298dd7ba680b8ad14a2d989e219ad928b9e6c7d","src/_topic/mod.rs":"7e871bc9f8838ab2b7bf35db6800e17a19bf8132675e305087cb6dd1e841cbec","src/_topic/partial.rs":"5b795d1a8f2fa5a378c4974f9862acd479392a645b93c5dc4da2c4b1384c0d0d","src/_topic/performance.rs":"3ce7c556c748d2b0298529c298ae70a921f4c7b1c7a5060abc334e64255a67a0","src/_topic/s_expression.rs":"6ca9a22a5c3344e120421f2ab353a1e822777aebfa1faa0acffc9632f7668cb2","src/_topic/stream.rs":"c156314777598d9facf0a2067854b3108d6e1a68f5bff67900075c29543ec547","src/_topic/why.rs":"5b425ff59f5bb0bbab87e63e4126161819a209fd9b316288ed3c58084012e5d7","src/_tutorial/chapter_0.rs":"2dd082fa014e8075e13524ce6a9ecf29adc380518764c487729d46e45463dc03","src/_tutorial/chapter_1.rs":"ed13f206d07fccec07ea6d2b14944f6620e7bbcc4b0fcec120f0015dc147a4fb","src/_tutorial/chapter_2.rs":"49f5a2935fa929da3ad0546c6232f693ce3abb99eb55734e08337a33559a4971","src/_tutorial/chapter_3.rs":"4be266c404276afb3dcfb421f2487bd633e8fee2dfa17fea064e758b7be579a4","src/_tutorial/chapter_4.rs":"f54201a391f081370c24ad755e34601c6d97fca6d3cd47463ae6bd4b29fdbe89","src/_tutorial/chapter_5.rs":"173f991399c6bb85bd9d09b60dd345ffa8d69fec355f2a889d949f1d9ee3d3ed","src/_tutorial/chapter_6.rs":"9b8e2e876cf544a82cdeb95e3ff4e7f14e9fb96c838626c44163e6ee7d9ba541","src/_tutorial/chapter_7.rs":"d00fe6adfe2ce74d63ff210148f1cbe9a7c02c22d2be6dbc48f009bcb1342aa2","src/_tutorial/mod.rs":"b69bb758ffcfbc1fa0c698ffc11d840ea6de3f8fa402ef8e170f3a0d6c3e190a","src/ascii/mod.rs":"cfcd370866aa68642d72f37b9e24256e8721860976afb1155d1661487c620241","src/ascii/tests.rs":"eee86d9cb6571f31ab8614a3aee38ea6c09845847718baa52a142baf090ce113","src/binary/bits/mod.rs":"353cb31b93085d75197266a28d7c0d8496fe7c259efd34da62eefcf7e31d48c7","src/binary/bits/tests.rs":"e558e1004932eae8fefad5fbce57fe9f95d7b42301e2e9abf305d85ce9d97838","src/binary/mod.rs":"886a425efbdfd0e3cda75790de0cfcaf4d111bdbcc6725468b4d48f837d453ee","src/binary/tests.rs":"f3987c943b2a99a439757d5afcd1e32e53dd0fa0a600bdd357a46929e8c67db9","src/bits.rs":"443351cafebab9dffa12d48a2780f8b9b8fe478b733f9a701c00a8319d2bf1c8","src/branch.rs":"86ba05809ec3712b4287d9bdb9c17c1c4267d2469805e9e26df39bd3e1c95224","src/bytes.rs":"6cc436c0142b7d5e022360a1174ef990971fbc1c30ac9f68dcba018db76a4993","src/character.rs":"c38a6c25ef7527a1164f1a871683bf09f5dc1de0effade3dfb258a05278a8cd3","src/combinator/branch.rs":"93cadba2e6a4be556c3b2df246095497e3652deb74b7c8d85055786b171c3d3c","src/combinator/core.rs":"659d8fb088ae7c6979580c5ec3c8d5d44787bc9974f3f9d70360d07a26157011","src/combinator/mod.rs":"03d3864d577c615b89d0266877090ee67422f83301ee130833c5dff8ff88767e","src/combinator/multi.rs":"f03fb501cabc55c0b35ace6e5b235c44d55f309da40e5fec162460abf50b7522","src/combinator/parser.rs":"f7e68c6bee62e515f79170a09850e2607f7c4c7fa6d9f4c701e85586caf1aae3","src/combinator/sequence.rs":"3a6e731d3ff3eab3fdfa31e4c81da63322446a614c56628a41c3765fb8d56e27","src/combinator/tests.rs":"7c2a843c85ef60a0fe958d47476d244049a0e077eb3f4593c2bd6a641c7864c4","src/error.rs":"97304e10f0804f92f9cec8fe514cddd9f53c688b3a101f2213d3f720ce2df0a5","src/lib.rs":"ea6b62c854fb9b1003002a34cf9cbfc9a535b88a0f8384a8ae22ac1dcc61605b","src/macros.rs":"485028be925e19eb7093c331982a483f2f0d16c5c0cb08b3395fa16805902705","src/multi.rs":"deaaae8788b3770771d77eb8235334363c2980a23c1ad5ee9d309dddaefd5c5f","src/number.rs":"17930f91d90f1331c8cade11ee310518fa9580152d32b68a03533649477203cd","src/parser.rs":"f5a231c07fb1801180ab35c0cac419ac957ecdbfa3ce355d15e25d7e7ac17e6b","src/sequence.rs":"5d3b618229289ad96c241f14a85b5fd4e940a03903cebb6ef551ddb664d2e861","src/stream/impls.rs":"99f69fdb8c32ad1f759bcc414ebfd2428eac5997887ce2b6946a2fcfcd174082","src/stream/mod.rs":"bbad16a321f14b1008b92b3ad28340f76e27163e0d84e4c7d7cc471fc4cbdc5d","src/stream/tests.rs":"24bbd9d6fbafc85e29effb7d5ec93afff3cebca7e0f4cf2a992f0245c3aafa40","src/token/mod.rs":"7e3adab3d657ada43ea8b7da64cc956c0c546df282f98227a74c8450c08cda7b","src/token/tests.rs":"831affa4e8531d62c324ae23da9b40547b09831862c5226a9538b7748a7acb31","src/trace/internals.rs":"c3446be9bea69ecafb17f7094d5312e6b963e90180694eb85127c9096aee3d63","src/trace/mod.rs":"718a42ef6142edc2648439e04ba75a769f296af60be84ff46f0b16c37a757201"},"package":"ca0ace3845f0d96209f0375e6d367e3eb87eb65d27d445bdc9f1843a26f39448"} \ No newline at end of file
+{"files":{"Cargo.lock":"7c65788ac9847ad91189d9bde88f490728377e9a1d22688c02d1432e40c92714","Cargo.toml":"e26ced242b413f24d8011cf68fed694f72efa78eb6795c6299f579e580234c7e","LICENSE-MIT":"cb5aedb296c5246d1f22e9099f925a65146f9f0d6b4eebba97fd27a6cdbbab2d","README.md":"b66d0e430d8a5f5391f1f51b2d7959c3881fca59fdf76a075129591b396c1c62","benches/contains_token.rs":"cd1ce72b8e1c92f8bd9539b1933e3337fedbc2e22f98959adb18b1a215f3cd70","benches/number.rs":"f4b54895ed523c462ce327a5205b0b99591eb7056fe9de9abe3f809eff287386","examples/arithmetic/bench.rs":"ff0220a18c6004cca8b56583072fbb7290f022cc069f2d24be132f261ac55f18","examples/arithmetic/main.rs":"aab0793c96add893bbaacea331bc05de8f6b59e47c5bccca67bfd30e924cd790","examples/arithmetic/parser.rs":"ddb86007e2c6be97acd08788f30a13083e0615bf5314a625d74e6a72d69da43f","examples/arithmetic/parser_ast.rs":"748d238fac2fe83b6ab9dfad5d6a2bb5f1863f6c2a2757e17271053291da3990","examples/css/main.rs":"3127f259af57aaaa8363bfa6e0a64c9719173cc1dcc5a293771a2c8a7f31982e","examples/css/parser.rs":"7175cfdc36d228b3130f0cfc8565063554167998045a07f62644bbd90c2772b2","examples/custom_error.rs":"5ebf88007ed2ce998fdb16cd4326b1573e83f0c420e2f6561c10b6dd8ebf69a2","examples/http/bench.rs":"b6d3e9e5833b53ac58f8336617cc42a2f3f4c5e5ce88feb23184fcdbb36843f6","examples/http/main.rs":"95d3c73953cd76ea462d886ade2ab34e987239bae3abb0349c434fb01b80467d","examples/http/parser.rs":"55a5894ab8e211a17f2eb9db72503579704d85376a6631a741eede2bfcd4bdbd","examples/http/parser_streaming.rs":"1300486af4dfcfe9b1b396436ef58927663624b0184b9c70a636e639c09c4552","examples/ini/bench.rs":"c8fd1aed25ce2878c0f440d765779d7877e83ca202cf071f8f4c57566596bf89","examples/ini/main.rs":"d771aa8aae11e53f4f5453ac39e10ae3a1de210408dfd31ca7d1ce58d14c3fb9","examples/ini/parser.rs":"c554286e8f2077f999d607902e7a63ce3945939118bccf830a68b22bfe24c775","examples/ini/parser_str.rs":"8f5bce75153ae98d5e76f884fec4746a73c44c4fb9a3c4c2efdf77913baf3bec","examples/iterator.rs":"21fb0480749116407689162f0d3e9957e3e7b6863f9dda08ee01af675409b06e","examples/json/bench.rs":"9479248ccef46e0741e0eebf9fb3b307b343ba665925481adc4554d8e65f9d39","examples/json/json.rs":"48cf6c114098113c9767bebe430682f55f7c1a227e6486131ca58c00770711f2","examples/json/main.rs":"7ab1f6eefd4eb61153cf05991e593fd10827ac09f66af45d3019f94c39c5b84e","examples/json/parser.rs":"6a49d300a323bfab9deb9221c92c44ea4b5738788077f712cc8d12d082583127","examples/json/parser_dispatch.rs":"370ae21b2c1f9fe848a8ca0d9f821109ab0995c78575d01a0abe32715429eb41","examples/json/parser_partial.rs":"4f944c45223161fcbb6025fb8e71306e549ab39bf62d26bcbf85c61d124b18e2","examples/json_iterator.rs":"070f7ade176b04b70b026b1915601a52fbb462ec0cc7b9d6684d1e0a04c2d031","examples/ndjson/example.ndjson":"c44c130731008bca76181348d40f46b183577949b5a4d229e0e1a56e1e405e5d","examples/ndjson/main.rs":"dc92dd5d76b5d43edf947b6455d552f0212e46d59c926d95f97f5d159b14e361","examples/ndjson/parser.rs":"e10c0940da97def0a9c628916433cb867ea1a8cc6ecc0dff58bc98d13ec47ccd","examples/s_expression/main.rs":"5a2de0b477807c7d6ab8bb72579f03692e8f5ea89d5b6f3a8342cfdbe4d84b96","examples/s_expression/parser.rs":"a98fa7a2230d3c2aa77206bed66d7c4167707464bdb790f2ab25d803813589e3","examples/string/main.rs":"e6362f957d532d41bcd96476e55ac4c253eb04fa25ee88b48d872661a46a5bb5","examples/string/parser.rs":"111c8b67d9e51eef8b980f4efb9264d76598cb09e820b74f9ea8dfec5176abb4","src/_topic/arithmetic.rs":"94920a9572ed6deac58abb337a7be57b93cf37440f0cc3eaf514cb9ad9b9e077","src/_topic/error.rs":"69c972c609a91e078ddb4e01da8f3d35f29d8dbcb077614e9b156c033c9f5dd7","src/_topic/fromstr.rs":"01abdab296cd30067ae5f508b2b21ebe97c0571ace58e7817876eb2110e8d23a","src/_topic/http.rs":"19b9ec78a031fe5b3086fb34d04d6c13308c50b6e7bfe30229f5b682d3605ac8","src/_topic/ini.rs":"b2b04d48eac3158f4e26ee9dce748a699d02acaa0b12ae8d54421cad0fdc4ad7","src/_topic/json.rs":"bde39ee6b1c5fab2d2da480822b737674aed877f92c3f748d6932bec313b5661","src/_topic/language.rs":"437814054d4a0a19ffccd74ff9189677e6a8e9df45dc395861fc75d5bd23719b","src/_topic/mod.rs":"7e871bc9f8838ab2b7bf35db6800e17a19bf8132675e305087cb6dd1e841cbec","src/_topic/partial.rs":"5b795d1a8f2fa5a378c4974f9862acd479392a645b93c5dc4da2c4b1384c0d0d","src/_topic/performance.rs":"4e3f606e979c2bc0df78a3e706ccae2b844918eceb955ecd9c8b81ce27e660e3","src/_topic/s_expression.rs":"6ca9a22a5c3344e120421f2ab353a1e822777aebfa1faa0acffc9632f7668cb2","src/_topic/stream.rs":"5ae58b8a53e7ffe60df4fbe862fbc2319f5c36f798767b7b650dd6441332042b","src/_topic/why.rs":"5b425ff59f5bb0bbab87e63e4126161819a209fd9b316288ed3c58084012e5d7","src/_tutorial/chapter_0.rs":"2dd082fa014e8075e13524ce6a9ecf29adc380518764c487729d46e45463dc03","src/_tutorial/chapter_1.rs":"ba83c8b7cf964314414b0e8f7bd500b1931a974bee48e3e78e9c4f96626983e8","src/_tutorial/chapter_2.rs":"e2bc77fe8a122ea1f53f77501d0fa73ffc6e9c050a402e4266950b124e05edba","src/_tutorial/chapter_3.rs":"c7264e2fac45255c5a1b5c891cdcbffff840ee723f254f3e8556d4b794c438cd","src/_tutorial/chapter_4.rs":"d3a937b7305eea326cb16c0cf7b0033866693af6f5aa6ff05d073c0be9c71a73","src/_tutorial/chapter_5.rs":"f1eb8a17f1b5d35be3f9f2f24838ad5057791538440079fa95c3c665909cf8e0","src/_tutorial/chapter_6.rs":"2deec40067e1d5cef944d3773adaa0fcd17746abbcd489de6fadd874d45a9af7","src/_tutorial/chapter_7.rs":"fd8bac691a830bf49b56ddbcf4df64ba3eaef5d67740862d00e0741b590596ed","src/_tutorial/mod.rs":"b69bb758ffcfbc1fa0c698ffc11d840ea6de3f8fa402ef8e170f3a0d6c3e190a","src/ascii/mod.rs":"9891ba592aa3a1ca188a2da3e1fb0bccf85b670f5a0a2cd154b546fa12e4a1e7","src/ascii/tests.rs":"cbd0d7db9eb795762de305fde5204ee70396cb384ac7826bde91bf9c69cbec74","src/binary/bits/mod.rs":"35e9fa4c97dd1dbbe99434a15ee81773c18744f847c7d5c1435cf67c88dd946f","src/binary/bits/tests.rs":"1ce1707a8ab2300d601f67fb3cb9c4b8ba7528564477e65ff25d8542c3e0f6e7","src/binary/mod.rs":"6447ddb0d1f87ee653c4cc629fbc60714228d236fb6dad68ff0994df2c239d84","src/binary/tests.rs":"bc8c383d345e9d63f09d3edb6e4ff76b8e6d422f2359f7e7b2b29c56082d3b93","src/combinator/branch.rs":"4111b409191755a6fd94c1cbd3b9d6ed9f955a2f04cfa2d316106cd55612f9b6","src/combinator/core.rs":"632201f917e732b80c8dbe88c43f33e868df5261449b22b18e60424a795e0f45","src/combinator/mod.rs":"03d3864d577c615b89d0266877090ee67422f83301ee130833c5dff8ff88767e","src/combinator/multi.rs":"7a7acdbb667617627c1af7fb601bf1ec48df589e89744023ea32ce0eff1e4eaa","src/combinator/parser.rs":"cb7761454ec3b874b2434e3b9cbc89232cd9b7e8c8f6c1c71c0a3ef12fa28809","src/combinator/sequence.rs":"f913aec935bbdb1fd496e76dbc14d697d8e7e48c163856e062c5ded2f3170905","src/combinator/tests.rs":"9e9765024fa58adb3455bfc3815b923c3f93acf123ab1ef3a22d5ee832e50a7c","src/error.rs":"2b4f4bf06b93832e00c0a1ea9297a5214a4adcca270861803707d4f7d608712a","src/lib.rs":"3436ea3a7ca6375c49a62c674ad348b3601eb5d969b7376aeb19d395a24d2c63","src/macros.rs":"321af97e0315ca11164064cadbca2a8c0a55bcf605d101d5a6a4f4bca66eedf6","src/parser.rs":"eedb8942ec451ca0c28780edee543f5db93306d3c1c6b04d2d054a24c934ce2c","src/stream/impls.rs":"99f69fdb8c32ad1f759bcc414ebfd2428eac5997887ce2b6946a2fcfcd174082","src/stream/mod.rs":"491eb5efec578cddc694f1a2c8f96a74329bd8d2b976d596c6c006fa0a301348","src/stream/tests.rs":"e351ea68ba3fbeaeeac147ac7c186d8ee3a17ff09c78c016dd294eb0719d54f2","src/token/mod.rs":"99689541315f795e57983566aab3c641ccf711492a2e397af15213a63b6cb702","src/token/tests.rs":"65819246fac1c10abe4abeeb79e30fb03b06a9a5ef6fde3edec003ad1f034f78","src/trace/internals.rs":"725fd32f904fee0b61188e816bd42da3d42ffff43cbb4077d9324acfd96fd409","src/trace/mod.rs":"c63934ae83d80f6d6c1be0b6960fb107d67f42c1fdca8a1d680f999cd74c4b5d"},"package":"81fac9742fd1ad1bd9643b991319f72dd031016d44b77039a26977eb667141e7"} \ No newline at end of file
diff --git a/vendor/winnow/Cargo.lock b/vendor/winnow/Cargo.lock
index 9d2e6f42b..660b2f4b7 100644
--- a/vendor/winnow/Cargo.lock
+++ b/vendor/winnow/Cargo.lock
@@ -3,10 +3,31 @@
version = 3
[[package]]
+name = "anstream"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
+dependencies = [
+ "anstyle 1.0.1",
+ "anstyle-parse 0.2.1",
+ "anstyle-query",
+ "anstyle-wincon 1.0.1",
+ "colorchoice",
+ "is-terminal",
+ "utf8parse",
+]
+
+[[package]]
name = "anstyle"
-version = "0.3.1"
+version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "80c697cc33851b02ab0c26b2e8a211684fbe627ff1cc506131f35026dd7686dd"
+checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2"
+
+[[package]]
+name = "anstyle"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd"
[[package]]
name = "anstyle-parse"
@@ -18,16 +39,34 @@ dependencies = [
]
[[package]]
+name = "anstyle-parse"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333"
+dependencies = [
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle-query"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
+dependencies = [
+ "windows-sys 0.48.0",
+]
+
+[[package]]
name = "anstyle-stream"
-version = "0.2.0"
+version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cb854bd007661547402bb1aeee4a00eda2cc9775afb43c9a5158f8706f448a2a"
+checksum = "1383966ba5bad155fe30bb239f7ca9eb149990674414aee2f8aef35a0a2dc9d0"
dependencies = [
- "anstyle",
- "anstyle-parse",
- "anstyle-wincon",
+ "anstyle 0.3.5",
+ "anstyle-parse 0.1.1",
+ "anstyle-wincon 0.2.0",
"concolor-override",
- "concolor-query 0.3.3",
+ "concolor-query",
"is-terminal",
"utf8parse",
]
@@ -38,11 +77,21 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa"
dependencies = [
- "anstyle",
+ "anstyle 0.3.5",
"windows-sys 0.45.0",
]
[[package]]
+name = "anstyle-wincon"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
+dependencies = [
+ "anstyle 1.0.1",
+ "windows-sys 0.48.0",
+]
+
+[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -90,22 +139,10 @@ dependencies = [
]
[[package]]
-name = "bstr"
-version = "0.2.17"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
-dependencies = [
- "lazy_static",
- "memchr",
- "regex-automata",
- "serde",
-]
-
-[[package]]
name = "bumpalo"
-version = "3.11.0"
+version = "3.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d"
+checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
[[package]]
name = "bytecount"
@@ -155,15 +192,10 @@ dependencies = [
]
[[package]]
-name = "concolor"
-version = "0.0.11"
+name = "colorchoice"
+version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "318d6c16e73b3a900eb212ad6a82fc7d298c5ab8184c7a9998646455bc474a16"
-dependencies = [
- "bitflags",
- "concolor-query 0.1.0",
- "is-terminal",
-]
+checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "concolor-override"
@@ -173,12 +205,6 @@ checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f"
[[package]]
name = "concolor-query"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "82a90734b3d5dcf656e7624cca6bce9c3a90ee11f900e80141a7427ccfb3d317"
-
-[[package]]
-name = "concolor-query"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf"
@@ -233,9 +259,9 @@ dependencies = [
[[package]]
name = "crossbeam-channel"
-version = "0.5.6"
+version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
+checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200"
dependencies = [
"cfg-if",
"crossbeam-utils",
@@ -243,9 +269,9 @@ dependencies = [
[[package]]
name = "crossbeam-deque"
-version = "0.8.2"
+version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc"
+checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
dependencies = [
"cfg-if",
"crossbeam-epoch",
@@ -254,9 +280,9 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
-version = "0.9.11"
+version = "0.9.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348"
+checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
dependencies = [
"autocfg",
"cfg-if",
@@ -267,9 +293,9 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
-version = "0.8.12"
+version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac"
+checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
dependencies = [
"cfg-if",
]
@@ -286,13 +312,12 @@ dependencies = [
[[package]]
name = "csv"
-version = "1.1.6"
+version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
+checksum = "626ae34994d3d8d668f4269922248239db4ae42d538b14c398b74a52208e8086"
dependencies = [
- "bstr",
"csv-core",
- "itoa 0.4.8",
+ "itoa",
"ryu",
"serde",
]
@@ -313,7 +338,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"
dependencies = [
"quote",
- "syn",
+ "syn 1.0.109",
]
[[package]]
@@ -340,19 +365,19 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "either"
-version = "1.8.0"
+version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
+checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]]
name = "errno"
-version = "0.2.8"
+version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
+checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a"
dependencies = [
"errno-dragonfly",
"libc",
- "winapi",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -379,9 +404,9 @@ dependencies = [
[[package]]
name = "fastrand"
-version = "1.8.0"
+version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
+checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be"
dependencies = [
"instant",
]
@@ -404,9 +429,9 @@ dependencies = [
[[package]]
name = "getrandom"
-version = "0.2.7"
+version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
+checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"cfg-if",
"libc",
@@ -444,6 +469,15 @@ dependencies = [
[[package]]
name = "hermit-abi"
+version = "0.2.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "hermit-abi"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
@@ -459,24 +493,25 @@ dependencies = [
[[package]]
name = "io-lifetimes"
-version = "1.0.5"
+version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3"
+checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
dependencies = [
+ "hermit-abi 0.3.1",
"libc",
- "windows-sys 0.45.0",
+ "windows-sys 0.48.0",
]
[[package]]
name = "is-terminal"
-version = "0.4.4"
+version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857"
+checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f"
dependencies = [
"hermit-abi 0.3.1",
"io-lifetimes",
"rustix",
- "windows-sys 0.45.0",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -490,21 +525,15 @@ dependencies = [
[[package]]
name = "itoa"
-version = "0.4.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
-
-[[package]]
-name = "itoa"
-version = "1.0.4"
+version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
+checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
[[package]]
name = "js-sys"
-version = "0.3.60"
+version = "0.3.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47"
+checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a"
dependencies = [
"wasm-bindgen",
]
@@ -523,24 +552,27 @@ checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"
[[package]]
name = "libc"
-version = "0.2.139"
+version = "0.2.147"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
+
+[[package]]
+name = "libm"
+version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
+checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4"
[[package]]
name = "linux-raw-sys"
-version = "0.1.4"
+version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
+checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
[[package]]
name = "log"
-version = "0.4.17"
+version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
-dependencies = [
- "cfg-if",
-]
+checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]]
name = "memchr"
@@ -550,9 +582,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "memoffset"
-version = "0.6.5"
+version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
+checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
dependencies = [
"autocfg",
]
@@ -570,23 +602,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
+ "libm",
]
[[package]]
name = "num_cpus"
-version = "1.13.1"
+version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
+checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
- "hermit-abi 0.1.19",
+ "hermit-abi 0.2.6",
"libc",
]
[[package]]
name = "once_cell"
-version = "1.15.0"
+version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
+checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "oorandom"
@@ -643,7 +676,7 @@ dependencies = [
"pest_meta",
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.109",
]
[[package]]
@@ -687,9 +720,9 @@ dependencies = [
[[package]]
name = "ppv-lite86"
-version = "0.2.16"
+version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
+checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "pretty_assertions"
@@ -705,31 +738,31 @@ dependencies = [
[[package]]
name = "proc-macro2"
-version = "1.0.46"
+version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b"
+checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb"
dependencies = [
"unicode-ident",
]
[[package]]
name = "proptest"
-version = "1.0.0"
+version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1e0d9cc07f18492d879586c92b485def06bc850da3118075cd45d50e9c95b0e5"
+checksum = "4e35c06b98bf36aba164cc17cb25f7e232f5c4aeea73baa14b8a9f0d92dbfa65"
dependencies = [
"bit-set",
"bitflags",
"byteorder",
"lazy_static",
"num-traits",
- "quick-error 2.0.1",
"rand",
"rand_chacha",
"rand_xorshift",
- "regex-syntax",
+ "regex-syntax 0.6.29",
"rusty-fork",
"tempfile",
+ "unarray",
]
[[package]]
@@ -739,12 +772,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
-name = "quick-error"
-version = "2.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
-
-[[package]]
name = "quick-xml"
version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -755,9 +782,9 @@ dependencies = [
[[package]]
name = "quote"
-version = "1.0.21"
+version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
+checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488"
dependencies = [
"proc-macro2",
]
@@ -803,21 +830,19 @@ dependencies = [
[[package]]
name = "rayon"
-version = "1.5.3"
+version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d"
+checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b"
dependencies = [
- "autocfg",
- "crossbeam-deque",
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
-version = "1.9.3"
+version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f"
+checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
@@ -827,55 +852,46 @@ dependencies = [
[[package]]
name = "redox_syscall"
-version = "0.2.16"
+version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
+checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
dependencies = [
"bitflags",
]
[[package]]
name = "regex"
-version = "1.6.0"
+version = "1.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
+checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f"
dependencies = [
- "regex-syntax",
+ "regex-syntax 0.7.2",
]
[[package]]
-name = "regex-automata"
-version = "0.1.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
-
-[[package]]
name = "regex-syntax"
-version = "0.6.27"
+version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
+checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
-name = "remove_dir_all"
-version = "0.5.3"
+name = "regex-syntax"
+version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
-dependencies = [
- "winapi",
-]
+checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]]
name = "rustix"
-version = "0.36.8"
+version = "0.37.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644"
+checksum = "b96e891d04aa506a6d1f318d2771bcb1c7dfda84e126660ace067c9b474bb2c0"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
- "windows-sys 0.45.0",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -885,16 +901,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f"
dependencies = [
"fnv",
- "quick-error 1.2.3",
+ "quick-error",
"tempfile",
"wait-timeout",
]
[[package]]
name = "ryu"
-version = "1.0.11"
+version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
+checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
[[package]]
name = "same-file"
@@ -913,9 +929,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
-version = "1.0.145"
+version = "1.0.164"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b"
+checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d"
dependencies = [
"serde_derive",
]
@@ -932,22 +948,22 @@ dependencies = [
[[package]]
name = "serde_derive"
-version = "1.0.145"
+version = "1.0.164"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c"
+checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.22",
]
[[package]]
name = "serde_json"
-version = "1.0.86"
+version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074"
+checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3"
dependencies = [
- "itoa 1.0.4",
+ "itoa",
"ryu",
"serde",
]
@@ -971,29 +987,43 @@ checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf"
[[package]]
name = "snapbox"
-version = "0.4.6"
+version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7329b93bf53198ce2aecd1b08a3752306cef932483521d9361ce87b40559031c"
+checksum = "f6bccd62078347f89a914e3004d94582e13824d4e3d8a816317862884c423835"
dependencies = [
- "concolor",
+ "anstream",
+ "anstyle 1.0.1",
"escargot",
"normalize-line-endings",
"similar",
"snapbox-macros",
- "yansi",
]
[[package]]
name = "snapbox-macros"
-version = "0.3.1"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eaaf09df9f0eeae82be96290918520214530e738a7fe5a351b0f24cf77c0ca31"
+dependencies = [
+ "anstream",
+]
+
+[[package]]
+name = "syn"
+version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "485e65c1203eb37244465e857d15a26d3a85a5410648ccb53b18bd44cb3a7336"
+checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
[[package]]
name = "syn"
-version = "1.0.102"
+version = "2.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1"
+checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616"
dependencies = [
"proc-macro2",
"quote",
@@ -1002,16 +1032,16 @@ dependencies = [
[[package]]
name = "tempfile"
-version = "3.3.0"
+version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
+checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6"
dependencies = [
+ "autocfg",
"cfg-if",
"fastrand",
- "libc",
"redox_syscall",
- "remove_dir_all",
- "winapi",
+ "rustix",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -1042,12 +1072,12 @@ dependencies = [
[[package]]
name = "terminal_size"
-version = "0.2.3"
+version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907"
+checksum = "8e6bf6f19e9f8ed8d4048dc22981458ebcf406d67e94cd422e5ecd73d63b3237"
dependencies = [
"rustix",
- "windows-sys 0.42.0",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -1076,7 +1106,7 @@ checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.109",
]
[[package]]
@@ -1102,10 +1132,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81"
[[package]]
+name = "unarray"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
+
+[[package]]
name = "unicode-ident"
-version = "1.0.5"
+version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
+checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0"
[[package]]
name = "unicode-width"
@@ -1136,12 +1172,11 @@ dependencies = [
[[package]]
name = "walkdir"
-version = "2.3.2"
+version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
+checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698"
dependencies = [
"same-file",
- "winapi",
"winapi-util",
]
@@ -1153,9 +1188,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
-version = "0.2.83"
+version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
+checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
@@ -1163,24 +1198,24 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
-version = "0.2.83"
+version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142"
+checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.22",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
-version = "0.2.83"
+version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810"
+checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -1188,28 +1223,28 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
-version = "0.2.83"
+version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
+checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.22",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
-version = "0.2.83"
+version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
+checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "web-sys"
-version = "0.3.60"
+version = "0.3.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f"
+checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b"
dependencies = [
"js-sys",
"wasm-bindgen",
@@ -1248,90 +1283,141 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
-version = "0.42.0"
+version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
+checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
- "windows_aarch64_gnullvm",
- "windows_aarch64_msvc",
- "windows_i686_gnu",
- "windows_i686_msvc",
- "windows_x86_64_gnu",
- "windows_x86_64_gnullvm",
- "windows_x86_64_msvc",
+ "windows-targets 0.42.2",
]
[[package]]
name = "windows-sys"
-version = "0.45.0"
+version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
+checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
- "windows-targets",
+ "windows-targets 0.48.1",
]
[[package]]
name = "windows-targets"
-version = "0.42.1"
+version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
+checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
dependencies = [
- "windows_aarch64_gnullvm",
- "windows_aarch64_msvc",
- "windows_i686_gnu",
- "windows_i686_msvc",
- "windows_x86_64_gnu",
- "windows_x86_64_gnullvm",
- "windows_x86_64_msvc",
+ "windows_aarch64_gnullvm 0.42.2",
+ "windows_aarch64_msvc 0.42.2",
+ "windows_i686_gnu 0.42.2",
+ "windows_i686_msvc 0.42.2",
+ "windows_x86_64_gnu 0.42.2",
+ "windows_x86_64_gnullvm 0.42.2",
+ "windows_x86_64_msvc 0.42.2",
]
[[package]]
+name = "windows-targets"
+version = "0.48.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f"
+dependencies = [
+ "windows_aarch64_gnullvm 0.48.0",
+ "windows_aarch64_msvc 0.48.0",
+ "windows_i686_gnu 0.48.0",
+ "windows_i686_msvc 0.48.0",
+ "windows_x86_64_gnu 0.48.0",
+ "windows_x86_64_gnullvm 0.48.0",
+ "windows_x86_64_msvc 0.48.0",
+]
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
+
+[[package]]
name = "windows_aarch64_gnullvm"
-version = "0.42.1"
+version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
+checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
[[package]]
name = "windows_aarch64_msvc"
-version = "0.42.1"
+version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
+checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.48.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
[[package]]
name = "windows_i686_gnu"
-version = "0.42.1"
+version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
+checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.48.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]]
name = "windows_i686_msvc"
-version = "0.42.1"
+version = "0.48.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
+checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]]
name = "windows_x86_64_gnu"
-version = "0.42.1"
+version = "0.48.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
+checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]]
name = "windows_x86_64_gnullvm"
-version = "0.42.1"
+version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
+checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
[[package]]
name = "windows_x86_64_msvc"
-version = "0.42.1"
+version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
+checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.48.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]]
name = "winnow"
-version = "0.4.7"
+version = "0.5.0"
dependencies = [
- "anstyle",
+ "anstyle 0.3.5",
"anstyle-stream",
"circular",
"criterion",
diff --git a/vendor/winnow/Cargo.toml b/vendor/winnow/Cargo.toml
index 8fcbb1225..760878da4 100644
--- a/vendor/winnow/Cargo.toml
+++ b/vendor/winnow/Cargo.toml
@@ -13,7 +13,7 @@
edition = "2021"
rust-version = "1.64.0"
name = "winnow"
-version = "0.4.7"
+version = "0.5.0"
include = [
"build.rs",
"src/**/*",
@@ -86,7 +86,7 @@ search = "<!-- next-url -->"
[profile.bench]
lto = true
codegen-units = 1
-debug = true
+debug = 2
[[example]]
name = "arithmetic"
@@ -169,31 +169,31 @@ harness = false
required-features = ["std"]
[dependencies.anstyle]
-version = "0.3.1"
+version = "0.3.5"
optional = true
[dependencies.anstyle-stream]
-version = "0.2.0"
+version = "0.2.2"
optional = true
[dependencies.is-terminal]
-version = "0.4.3"
+version = "0.4.7"
optional = true
[dependencies.memchr]
-version = "2.3"
+version = "2.5"
optional = true
default-features = false
[dependencies.terminal_size]
-version = "0.2.3"
+version = "0.2.6"
optional = true
[dev-dependencies.circular]
version = "0.3.0"
[dev-dependencies.criterion]
-version = "0.3.5"
+version = "0.3.6"
[dev-dependencies.doc-comment]
version = "0.3"
@@ -205,10 +205,10 @@ version = "0.5.7"
version = "0.3.0"
[dev-dependencies.proptest]
-version = "1.0.0"
+version = "1.2.0"
[dev-dependencies.snapbox]
-version = "0.4.6"
+version = "0.4.11"
features = ["examples"]
[dev-dependencies.term-transcript]
diff --git a/vendor/winnow/benches/contains_token.rs b/vendor/winnow/benches/contains_token.rs
index a35c1b2b1..2980ce6c8 100644
--- a/vendor/winnow/benches/contains_token.rs
+++ b/vendor/winnow/benches/contains_token.rs
@@ -17,23 +17,20 @@ fn contains_token(c: &mut criterion::Criterion) {
let len = sample.len();
group.throughput(criterion::Throughput::Bytes(len as u64));
- group.bench_with_input(criterion::BenchmarkId::new("str", name), &len, |b, _| {
- b.iter(|| black_box(parser_str.parse_next(black_box(sample)).unwrap()));
- });
group.bench_with_input(criterion::BenchmarkId::new("slice", name), &len, |b, _| {
- b.iter(|| black_box(parser_slice.parse_next(black_box(sample)).unwrap()));
+ b.iter(|| black_box(parser_slice.parse_peek(black_box(sample)).unwrap()));
});
group.bench_with_input(criterion::BenchmarkId::new("array", name), &len, |b, _| {
- b.iter(|| black_box(parser_array.parse_next(black_box(sample)).unwrap()));
+ b.iter(|| black_box(parser_array.parse_peek(black_box(sample)).unwrap()));
});
group.bench_with_input(criterion::BenchmarkId::new("tuple", name), &len, |b, _| {
- b.iter(|| black_box(parser_tuple.parse_next(black_box(sample)).unwrap()));
+ b.iter(|| black_box(parser_tuple.parse_peek(black_box(sample)).unwrap()));
});
group.bench_with_input(
criterion::BenchmarkId::new("closure-or", name),
&len,
|b, _| {
- b.iter(|| black_box(parser_closure_or.parse_next(black_box(sample)).unwrap()));
+ b.iter(|| black_box(parser_closure_or.parse_peek(black_box(sample)).unwrap()));
},
);
group.bench_with_input(
@@ -43,7 +40,7 @@ fn contains_token(c: &mut criterion::Criterion) {
b.iter(|| {
black_box(
parser_closure_matches
- .parse_next(black_box(sample))
+ .parse_peek(black_box(sample))
.unwrap(),
)
});
@@ -53,27 +50,22 @@ fn contains_token(c: &mut criterion::Criterion) {
group.finish();
}
-fn parser_str(input: &str) -> IResult<&str, usize> {
- let contains = "0123456789";
- repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
-}
-
-fn parser_slice(input: &str) -> IResult<&str, usize> {
+fn parser_slice(input: &mut &str) -> PResult<usize> {
let contains = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'][..];
repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
}
-fn parser_array(input: &str) -> IResult<&str, usize> {
+fn parser_array(input: &mut &str) -> PResult<usize> {
let contains = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
}
-fn parser_tuple(input: &str) -> IResult<&str, usize> {
+fn parser_tuple(input: &mut &str) -> PResult<usize> {
let contains = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
}
-fn parser_closure_or(input: &str) -> IResult<&str, usize> {
+fn parser_closure_or(input: &mut &str) -> PResult<usize> {
let contains = |c: char| {
c == '0'
|| c == '1'
@@ -89,7 +81,7 @@ fn parser_closure_or(input: &str) -> IResult<&str, usize> {
repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
}
-fn parser_closure_matches(input: &str) -> IResult<&str, usize> {
+fn parser_closure_matches(input: &mut &str) -> PResult<usize> {
let contains = |c: char| matches!(c, '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9');
repeat(0.., alt((take_while(1.., contains), take_till1(contains)))).parse_next(input)
}
diff --git a/vendor/winnow/benches/number.rs b/vendor/winnow/benches/number.rs
index b6c6fac57..d35d65c2e 100644
--- a/vendor/winnow/benches/number.rs
+++ b/vendor/winnow/benches/number.rs
@@ -6,63 +6,63 @@ use criterion::Criterion;
use winnow::ascii::float;
use winnow::binary::be_u64;
use winnow::error::ErrMode;
-use winnow::error::Error;
use winnow::error::ErrorKind;
+use winnow::error::InputError;
+use winnow::error::ParserError;
use winnow::prelude::*;
use winnow::stream::ParseSlice;
type Stream<'i> = &'i [u8];
-fn parser(i: Stream<'_>) -> IResult<Stream<'_>, u64> {
- be_u64(i)
+fn parser(i: &mut Stream<'_>) -> PResult<u64> {
+ be_u64.parse_next(i)
}
fn number(c: &mut Criterion) {
let data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
- parser(&data[..]).expect("should parse correctly");
+ parser
+ .parse_peek(&data[..])
+ .expect("should parse correctly");
c.bench_function("number", move |b| {
- b.iter(|| parser(&data[..]).unwrap());
+ b.iter(|| parser.parse_peek(&data[..]).unwrap());
});
}
fn float_bytes(c: &mut Criterion) {
println!(
"float_bytes result: {:?}",
- float::<_, f64, Error<_>>(&b"-1.234E-12"[..])
+ float::<_, f64, InputError<_>>.parse_peek(&b"-1.234E-12"[..])
);
c.bench_function("float bytes", |b| {
- b.iter(|| float::<_, f64, Error<_>>(&b"-1.234E-12"[..]));
+ b.iter(|| float::<_, f64, InputError<_>>.parse_peek(&b"-1.234E-12"[..]));
});
}
fn float_str(c: &mut Criterion) {
println!(
"float_str result: {:?}",
- float::<_, f64, Error<_>>("-1.234E-12")
+ float::<_, f64, InputError<_>>.parse_peek("-1.234E-12")
);
c.bench_function("float str", |b| {
- b.iter(|| float::<_, f64, Error<_>>("-1.234E-12"));
+ b.iter(|| float::<_, f64, InputError<_>>.parse_peek("-1.234E-12"));
});
}
-fn std_float(input: &[u8]) -> IResult<&[u8], f64, Error<&[u8]>> {
+fn std_float(input: &mut &[u8]) -> PResult<f64> {
match input.parse_slice() {
- Some(n) => Ok((&[], n)),
- None => Err(ErrMode::Backtrack(Error {
- input,
- kind: ErrorKind::Slice,
- })),
+ Some(n) => Ok(n),
+ None => Err(ErrMode::from_error_kind(input, ErrorKind::Slice)),
}
}
fn std_float_bytes(c: &mut Criterion) {
println!(
"std_float_bytes result: {:?}",
- std_float(&b"-1.234E-12"[..])
+ std_float.parse_peek(&b"-1.234E-12"[..])
);
c.bench_function("std_float bytes", |b| {
- b.iter(|| std_float(&b"-1.234E-12"[..]));
+ b.iter(|| std_float.parse_peek(&b"-1.234E-12"[..]));
});
}
diff --git a/vendor/winnow/examples/arithmetic/bench.rs b/vendor/winnow/examples/arithmetic/bench.rs
index 0f6ec8eef..6504454c4 100644
--- a/vendor/winnow/examples/arithmetic/bench.rs
+++ b/vendor/winnow/examples/arithmetic/bench.rs
@@ -1,5 +1,7 @@
mod parser;
+use winnow::prelude::*;
+
use parser::expr;
#[allow(clippy::eq_op, clippy::erasing_op)]
@@ -7,11 +9,11 @@ fn arithmetic(c: &mut criterion::Criterion) {
let data = " 2*2 / ( 5 - 1) + 3 / 4 * (2 - 7 + 567 *12 /2) + 3*(1+2*( 45 /2));";
assert_eq!(
- expr(data),
+ expr.parse_peek(data),
Ok((";", 2 * 2 / (5 - 1) + 3 * (1 + 2 * (45 / 2)),))
);
c.bench_function("arithmetic", |b| {
- b.iter(|| expr(data).unwrap());
+ b.iter(|| expr.parse_peek(data).unwrap());
});
}
diff --git a/vendor/winnow/examples/arithmetic/parser.rs b/vendor/winnow/examples/arithmetic/parser.rs
index ba6347a43..50ffbdbbb 100644
--- a/vendor/winnow/examples/arithmetic/parser.rs
+++ b/vendor/winnow/examples/arithmetic/parser.rs
@@ -7,17 +7,16 @@ use winnow::{
combinator::delimited,
combinator::fold_repeat,
token::one_of,
- IResult,
};
// Parser definition
-pub fn expr(i: &str) -> IResult<&str, i64> {
- let (i, init) = term(i)?;
+pub fn expr(i: &mut &str) -> PResult<i64> {
+ let init = term.parse_next(i)?;
fold_repeat(
0..,
- (one_of("+-"), term),
+ (one_of(['+', '-']), term),
move || init,
|acc, (op, val): (char, i64)| {
if op == '+' {
@@ -33,12 +32,12 @@ pub fn expr(i: &str) -> IResult<&str, i64> {
// We read an initial factor and for each time we find
// a * or / operator followed by another factor, we do
// the math by folding everything
-fn term(i: &str) -> IResult<&str, i64> {
- let (i, init) = factor(i)?;
+fn term(i: &mut &str) -> PResult<i64> {
+ let init = factor.parse_next(i)?;
fold_repeat(
0..,
- (one_of("*/"), factor),
+ (one_of(['*', '/']), factor),
move || init,
|acc, (op, val): (char, i64)| {
if op == '*' {
@@ -55,7 +54,7 @@ fn term(i: &str) -> IResult<&str, i64> {
// We look for a digit suite, and try to convert it.
// If either str::from_utf8 or FromStr::from_str fail,
// we fallback to the parens parser defined above
-fn factor(i: &str) -> IResult<&str, i64> {
+fn factor(i: &mut &str) -> PResult<i64> {
delimited(
spaces,
alt((
@@ -69,35 +68,35 @@ fn factor(i: &str) -> IResult<&str, i64> {
}
// We parse any expr surrounded by parens, ignoring all whitespaces around those
-fn parens(i: &str) -> IResult<&str, i64> {
+fn parens(i: &mut &str) -> PResult<i64> {
delimited('(', expr, ')').parse_next(i)
}
#[test]
fn factor_test() {
- assert_eq!(factor("3"), Ok(("", 3)));
- assert_eq!(factor(" 12"), Ok(("", 12)));
- assert_eq!(factor("537 "), Ok(("", 537)));
- assert_eq!(factor(" 24 "), Ok(("", 24)));
+ assert_eq!(factor.parse_peek("3"), Ok(("", 3)));
+ assert_eq!(factor.parse_peek(" 12"), Ok(("", 12)));
+ assert_eq!(factor.parse_peek("537 "), Ok(("", 537)));
+ assert_eq!(factor.parse_peek(" 24 "), Ok(("", 24)));
}
#[test]
fn term_test() {
- assert_eq!(term(" 12 *2 / 3"), Ok(("", 8)));
- assert_eq!(term(" 2* 3 *2 *2 / 3"), Ok(("", 8)));
- assert_eq!(term(" 48 / 3/2"), Ok(("", 8)));
+ assert_eq!(term.parse_peek(" 12 *2 / 3"), Ok(("", 8)));
+ assert_eq!(term.parse_peek(" 2* 3 *2 *2 / 3"), Ok(("", 8)));
+ assert_eq!(term.parse_peek(" 48 / 3/2"), Ok(("", 8)));
}
#[test]
fn expr_test() {
- assert_eq!(expr(" 1 + 2 "), Ok(("", 3)));
- assert_eq!(expr(" 12 + 6 - 4+ 3"), Ok(("", 17)));
- assert_eq!(expr(" 1 + 2*3 + 4"), Ok(("", 11)));
+ assert_eq!(expr.parse_peek(" 1 + 2 "), Ok(("", 3)));
+ assert_eq!(expr.parse_peek(" 12 + 6 - 4+ 3"), Ok(("", 17)));
+ assert_eq!(expr.parse_peek(" 1 + 2*3 + 4"), Ok(("", 11)));
}
#[test]
fn parens_test() {
- assert_eq!(expr(" ( 2 )"), Ok(("", 2)));
- assert_eq!(expr(" 2* ( 3 + 4 ) "), Ok(("", 14)));
- assert_eq!(expr(" 2*2 / ( 5 - 1) + 3"), Ok(("", 4)));
+ assert_eq!(expr.parse_peek(" ( 2 )"), Ok(("", 2)));
+ assert_eq!(expr.parse_peek(" 2* ( 3 + 4 ) "), Ok(("", 14)));
+ assert_eq!(expr.parse_peek(" 2*2 / ( 5 - 1) + 3"), Ok(("", 4)));
}
diff --git a/vendor/winnow/examples/arithmetic/parser_ast.rs b/vendor/winnow/examples/arithmetic/parser_ast.rs
index fcf897e34..5fb9847c0 100644
--- a/vendor/winnow/examples/arithmetic/parser_ast.rs
+++ b/vendor/winnow/examples/arithmetic/parser_ast.rs
@@ -9,7 +9,6 @@ use winnow::{
combinator::alt,
combinator::repeat,
combinator::{delimited, preceded},
- IResult,
};
#[derive(Debug)]
@@ -44,47 +43,47 @@ impl Display for Expr {
}
}
-pub fn expr(i: &str) -> IResult<&str, Expr> {
- let (i, initial) = term(i)?;
- let (i, remainder) = repeat(
+pub fn expr(i: &mut &str) -> PResult<Expr> {
+ let initial = term(i)?;
+ let remainder = repeat(
0..,
alt((
- |i| {
- let (i, add) = preceded("+", term).parse_next(i)?;
- Ok((i, (Oper::Add, add)))
+ |i: &mut &str| {
+ let add = preceded("+", term).parse_next(i)?;
+ Ok((Oper::Add, add))
},
- |i| {
- let (i, sub) = preceded("-", term).parse_next(i)?;
- Ok((i, (Oper::Sub, sub)))
+ |i: &mut &str| {
+ let sub = preceded("-", term).parse_next(i)?;
+ Ok((Oper::Sub, sub))
},
)),
)
.parse_next(i)?;
- Ok((i, fold_exprs(initial, remainder)))
+ Ok(fold_exprs(initial, remainder))
}
-fn term(i: &str) -> IResult<&str, Expr> {
- let (i, initial) = factor(i)?;
- let (i, remainder) = repeat(
+fn term(i: &mut &str) -> PResult<Expr> {
+ let initial = factor(i)?;
+ let remainder = repeat(
0..,
alt((
- |i| {
- let (i, mul) = preceded("*", factor).parse_next(i)?;
- Ok((i, (Oper::Mul, mul)))
+ |i: &mut &str| {
+ let mul = preceded("*", factor).parse_next(i)?;
+ Ok((Oper::Mul, mul))
},
- |i| {
- let (i, div) = preceded("/", factor).parse_next(i)?;
- Ok((i, (Oper::Div, div)))
+ |i: &mut &str| {
+ let div = preceded("/", factor).parse_next(i)?;
+ Ok((Oper::Div, div))
},
)),
)
.parse_next(i)?;
- Ok((i, fold_exprs(initial, remainder)))
+ Ok(fold_exprs(initial, remainder))
}
-fn factor(i: &str) -> IResult<&str, Expr> {
+fn factor(i: &mut &str) -> PResult<Expr> {
alt((
delimited(multispace, digit, multispace)
.try_map(FromStr::from_str)
@@ -94,7 +93,7 @@ fn factor(i: &str) -> IResult<&str, Expr> {
.parse_next(i)
}
-fn parens(i: &str) -> IResult<&str, Expr> {
+fn parens(i: &mut &str) -> PResult<Expr> {
delimited(
multispace,
delimited("(", expr.map(|e| Expr::Paren(Box::new(e))), ")"),
@@ -118,7 +117,9 @@ fn fold_exprs(initial: Expr, remainder: Vec<(Oper, Expr)>) -> Expr {
#[test]
fn factor_test() {
assert_eq!(
- factor(" 3 ").map(|(i, x)| (i, format!("{:?}", x))),
+ factor
+ .parse_peek(" 3 ")
+ .map(|(i, x)| (i, format!("{:?}", x))),
Ok(("", String::from("Value(3)")))
);
}
@@ -126,7 +127,8 @@ fn factor_test() {
#[test]
fn term_test() {
assert_eq!(
- term(" 3 * 5 ").map(|(i, x)| (i, format!("{:?}", x))),
+ term.parse_peek(" 3 * 5 ")
+ .map(|(i, x)| (i, format!("{:?}", x))),
Ok(("", String::from("Mul(Value(3), Value(5))")))
);
}
@@ -134,18 +136,21 @@ fn term_test() {
#[test]
fn expr_test() {
assert_eq!(
- expr(" 1 + 2 * 3 ").map(|(i, x)| (i, format!("{:?}", x))),
+ expr.parse_peek(" 1 + 2 * 3 ")
+ .map(|(i, x)| (i, format!("{:?}", x))),
Ok(("", String::from("Add(Value(1), Mul(Value(2), Value(3)))")))
);
assert_eq!(
- expr(" 1 + 2 * 3 / 4 - 5 ").map(|(i, x)| (i, format!("{:?}", x))),
+ expr.parse_peek(" 1 + 2 * 3 / 4 - 5 ")
+ .map(|(i, x)| (i, format!("{:?}", x))),
Ok((
"",
String::from("Sub(Add(Value(1), Div(Mul(Value(2), Value(3)), Value(4))), Value(5))")
))
);
assert_eq!(
- expr(" 72 / 2 / 3 ").map(|(i, x)| (i, format!("{:?}", x))),
+ expr.parse_peek(" 72 / 2 / 3 ")
+ .map(|(i, x)| (i, format!("{:?}", x))),
Ok(("", String::from("Div(Div(Value(72), Value(2)), Value(3))")))
);
}
@@ -153,7 +158,8 @@ fn expr_test() {
#[test]
fn parens_test() {
assert_eq!(
- expr(" ( 1 + 2 ) * 3 ").map(|(i, x)| (i, format!("{:?}", x))),
+ expr.parse_peek(" ( 1 + 2 ) * 3 ")
+ .map(|(i, x)| (i, format!("{:?}", x))),
Ok((
"",
String::from("Mul(Paren(Add(Value(1), Value(2))), Value(3))")
diff --git a/vendor/winnow/examples/css/main.rs b/vendor/winnow/examples/css/main.rs
index 26c1b9212..cf52adad2 100644
--- a/vendor/winnow/examples/css/main.rs
+++ b/vendor/winnow/examples/css/main.rs
@@ -49,7 +49,7 @@ impl Args {
#[test]
fn parse_color() {
assert_eq!(
- hex_color("#2F14DF"),
+ hex_color.parse_peek("#2F14DF"),
Ok((
"",
parser::Color {
diff --git a/vendor/winnow/examples/css/parser.rs b/vendor/winnow/examples/css/parser.rs
index 9b3238e2e..d31ed0b77 100644
--- a/vendor/winnow/examples/css/parser.rs
+++ b/vendor/winnow/examples/css/parser.rs
@@ -10,21 +10,21 @@ pub struct Color {
impl std::str::FromStr for Color {
// The error must be owned
- type Err = winnow::error::Error<String>;
+ type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
- hex_color.parse(s).map_err(winnow::error::Error::into_owned)
+ hex_color.parse(s).map_err(|e| e.to_string())
}
}
-pub fn hex_color(input: &str) -> IResult<&str, Color> {
- let (input, _) = "#".parse_next(input)?;
- let (input, (red, green, blue)) = (hex_primary, hex_primary, hex_primary).parse_next(input)?;
+pub fn hex_color(input: &mut &str) -> PResult<Color> {
+ let _ = "#".parse_next(input)?;
+ let (red, green, blue) = (hex_primary, hex_primary, hex_primary).parse_next(input)?;
- Ok((input, Color { red, green, blue }))
+ Ok(Color { red, green, blue })
}
-fn hex_primary(input: &str) -> IResult<&str, u8> {
+fn hex_primary(input: &mut &str) -> PResult<u8> {
take_while(2, |c: char| c.is_ascii_hexdigit())
.try_map(|input| u8::from_str_radix(input, 16))
.parse_next(input)
diff --git a/vendor/winnow/examples/custom_error.rs b/vendor/winnow/examples/custom_error.rs
index 954452a20..998e5ad65 100644
--- a/vendor/winnow/examples/custom_error.rs
+++ b/vendor/winnow/examples/custom_error.rs
@@ -1,7 +1,7 @@
use winnow::error::ErrMode;
use winnow::error::ErrorKind;
-use winnow::error::ParseError;
-use winnow::IResult;
+use winnow::error::ParserError;
+use winnow::prelude::*;
#[derive(Debug, PartialEq, Eq)]
pub enum CustomError<I> {
@@ -9,17 +9,17 @@ pub enum CustomError<I> {
Nom(I, ErrorKind),
}
-impl<I> ParseError<I> for CustomError<I> {
- fn from_error_kind(input: I, kind: ErrorKind) -> Self {
- CustomError::Nom(input, kind)
+impl<I: Clone> ParserError<I> for CustomError<I> {
+ fn from_error_kind(input: &I, kind: ErrorKind) -> Self {
+ CustomError::Nom(input.clone(), kind)
}
- fn append(self, _: I, _: ErrorKind) -> Self {
+ fn append(self, _: &I, _: ErrorKind) -> Self {
self
}
}
-pub fn parse(_input: &str) -> IResult<&str, &str, CustomError<&str>> {
+pub fn parse<'s>(_input: &mut &'s str) -> PResult<&'s str, CustomError<&'s str>> {
Err(ErrMode::Backtrack(CustomError::MyError))
}
@@ -27,13 +27,11 @@ fn main() {}
#[cfg(test)]
mod tests {
- use super::parse;
- use super::CustomError;
- use winnow::error::ErrMode;
+ use super::*;
#[test]
fn it_works() {
- let err = parse("").unwrap_err();
+ let err = parse.parse_next(&mut "").unwrap_err();
match err {
ErrMode::Backtrack(e) => assert_eq!(e, CustomError::MyError),
_ => panic!("Unexpected error: {:?}", err),
diff --git a/vendor/winnow/examples/http/parser.rs b/vendor/winnow/examples/http/parser.rs
index f03b77eb7..7f62c4447 100644
--- a/vendor/winnow/examples/http/parser.rs
+++ b/vendor/winnow/examples/http/parser.rs
@@ -1,4 +1,5 @@
-use winnow::{ascii::line_ending, combinator::repeat, token::take_while, IResult, Parser};
+use winnow::prelude::*;
+use winnow::{ascii::line_ending, combinator::repeat, token::take_while};
pub type Stream<'i> = &'i [u8];
@@ -22,12 +23,11 @@ pub fn parse(data: &[u8]) -> Option<Vec<(Request<'_>, Vec<Header<'_>>)>> {
let mut buf = data;
let mut v = Vec::new();
loop {
- match request(buf) {
- Ok((b, r)) => {
- buf = b;
+ match request(&mut buf) {
+ Ok(r) => {
v.push(r);
- if b.is_empty() {
+ if buf.is_empty() {
//println!("{}", i);
break;
}
@@ -42,53 +42,50 @@ pub fn parse(data: &[u8]) -> Option<Vec<(Request<'_>, Vec<Header<'_>>)>> {
Some(v)
}
-fn request(input: Stream<'_>) -> IResult<Stream<'_>, (Request<'_>, Vec<Header<'_>>)> {
- let (input, req) = request_line(input)?;
- let (input, h) = repeat(1.., message_header).parse_next(input)?;
- let (input, _) = line_ending(input)?;
+fn request<'s>(input: &mut Stream<'s>) -> PResult<(Request<'s>, Vec<Header<'s>>)> {
+ let req = request_line(input)?;
+ let h = repeat(1.., message_header).parse_next(input)?;
+ let _ = line_ending.parse_next(input)?;
- Ok((input, (req, h)))
+ Ok((req, h))
}
-fn request_line(input: Stream<'_>) -> IResult<Stream<'_>, Request<'_>> {
- let (input, method) = take_while(1.., is_token).parse_next(input)?;
- let (input, _) = take_while(1.., is_space).parse_next(input)?;
- let (input, uri) = take_while(1.., is_not_space).parse_next(input)?;
- let (input, _) = take_while(1.., is_space).parse_next(input)?;
- let (input, version) = http_version(input)?;
- let (input, _) = line_ending(input)?;
-
- Ok((
- input,
- Request {
- method,
- uri,
- version,
- },
- ))
+fn request_line<'s>(input: &mut Stream<'s>) -> PResult<Request<'s>> {
+ let method = take_while(1.., is_token).parse_next(input)?;
+ let _ = take_while(1.., is_space).parse_next(input)?;
+ let uri = take_while(1.., is_not_space).parse_next(input)?;
+ let _ = take_while(1.., is_space).parse_next(input)?;
+ let version = http_version(input)?;
+ let _ = line_ending.parse_next(input)?;
+
+ Ok(Request {
+ method,
+ uri,
+ version,
+ })
}
-fn http_version(input: Stream<'_>) -> IResult<Stream<'_>, &[u8]> {
- let (input, _) = "HTTP/".parse_next(input)?;
- let (input, version) = take_while(1.., is_version).parse_next(input)?;
+fn http_version<'s>(input: &mut Stream<'s>) -> PResult<&'s [u8]> {
+ let _ = "HTTP/".parse_next(input)?;
+ let version = take_while(1.., is_version).parse_next(input)?;
- Ok((input, version))
+ Ok(version)
}
-fn message_header_value(input: Stream<'_>) -> IResult<Stream<'_>, &[u8]> {
- let (input, _) = take_while(1.., is_horizontal_space).parse_next(input)?;
- let (input, data) = take_while(1.., not_line_ending).parse_next(input)?;
- let (input, _) = line_ending(input)?;
+fn message_header_value<'s>(input: &mut Stream<'s>) -> PResult<&'s [u8]> {
+ let _ = take_while(1.., is_horizontal_space).parse_next(input)?;
+ let data = take_while(1.., not_line_ending).parse_next(input)?;
+ let _ = line_ending.parse_next(input)?;
- Ok((input, data))
+ Ok(data)
}
-fn message_header(input: Stream<'_>) -> IResult<Stream<'_>, Header<'_>> {
- let (input, name) = take_while(1.., is_token).parse_next(input)?;
- let (input, _) = ':'.parse_next(input)?;
- let (input, value) = repeat(1.., message_header_value).parse_next(input)?;
+fn message_header<'s>(input: &mut Stream<'s>) -> PResult<Header<'s>> {
+ let name = take_while(1.., is_token).parse_next(input)?;
+ let _ = ':'.parse_next(input)?;
+ let value = repeat(1.., message_header_value).parse_next(input)?;
- Ok((input, Header { name, value }))
+ Ok(Header { name, value })
}
#[rustfmt::skip]
diff --git a/vendor/winnow/examples/http/parser_streaming.rs b/vendor/winnow/examples/http/parser_streaming.rs
index d3b2c4aaa..d59e6f8a9 100644
--- a/vendor/winnow/examples/http/parser_streaming.rs
+++ b/vendor/winnow/examples/http/parser_streaming.rs
@@ -1,5 +1,5 @@
use winnow::{
- ascii::line_ending, combinator::repeat, stream::Partial, token::take_while, IResult, Parser,
+ ascii::line_ending, combinator::repeat, prelude::*, stream::Partial, token::take_while,
};
pub type Stream<'i> = Partial<&'i [u8]>;
@@ -24,12 +24,11 @@ pub fn parse(data: &[u8]) -> Option<Vec<(Request<'_>, Vec<Header<'_>>)>> {
let mut buf = Partial::new(data);
let mut v = Vec::new();
loop {
- match request(buf) {
- Ok((b, r)) => {
- buf = b;
+ match request(&mut buf) {
+ Ok(r) => {
v.push(r);
- if b.is_empty() {
+ if buf.is_empty() {
//println!("{}", i);
break;
}
@@ -44,53 +43,50 @@ pub fn parse(data: &[u8]) -> Option<Vec<(Request<'_>, Vec<Header<'_>>)>> {
Some(v)
}
-fn request(input: Stream<'_>) -> IResult<Stream<'_>, (Request<'_>, Vec<Header<'_>>)> {
- let (input, req) = request_line(input)?;
- let (input, h) = repeat(1.., message_header).parse_next(input)?;
- let (input, _) = line_ending(input)?;
+fn request<'s>(input: &mut Stream<'s>) -> PResult<(Request<'s>, Vec<Header<'s>>)> {
+ let req = request_line(input)?;
+ let h = repeat(1.., message_header).parse_next(input)?;
+ let _ = line_ending.parse_next(input)?;
- Ok((input, (req, h)))
+ Ok((req, h))
}
-fn request_line(input: Stream<'_>) -> IResult<Stream<'_>, Request<'_>> {
- let (input, method) = take_while(1.., is_token).parse_next(input)?;
- let (input, _) = take_while(1.., is_space).parse_next(input)?;
- let (input, uri) = take_while(1.., is_not_space).parse_next(input)?;
- let (input, _) = take_while(1.., is_space).parse_next(input)?;
- let (input, version) = http_version(input)?;
- let (input, _) = line_ending(input)?;
-
- Ok((
- input,
- Request {
- method,
- uri,
- version,
- },
- ))
+fn request_line<'s>(input: &mut Stream<'s>) -> PResult<Request<'s>> {
+ let method = take_while(1.., is_token).parse_next(input)?;
+ let _ = take_while(1.., is_space).parse_next(input)?;
+ let uri = take_while(1.., is_not_space).parse_next(input)?;
+ let _ = take_while(1.., is_space).parse_next(input)?;
+ let version = http_version(input)?;
+ let _ = line_ending.parse_next(input)?;
+
+ Ok(Request {
+ method,
+ uri,
+ version,
+ })
}
-fn http_version(input: Stream<'_>) -> IResult<Stream<'_>, &[u8]> {
- let (input, _) = "HTTP/".parse_next(input)?;
- let (input, version) = take_while(1.., is_version).parse_next(input)?;
+fn http_version<'s>(input: &mut Stream<'s>) -> PResult<&'s [u8]> {
+ let _ = "HTTP/".parse_next(input)?;
+ let version = take_while(1.., is_version).parse_next(input)?;
- Ok((input, version))
+ Ok(version)
}
-fn message_header_value(input: Stream<'_>) -> IResult<Stream<'_>, &[u8]> {
- let (input, _) = take_while(1.., is_horizontal_space).parse_next(input)?;
- let (input, data) = take_while(1.., not_line_ending).parse_next(input)?;
- let (input, _) = line_ending(input)?;
+fn message_header_value<'s>(input: &mut Stream<'s>) -> PResult<&'s [u8]> {
+ let _ = take_while(1.., is_horizontal_space).parse_next(input)?;
+ let data = take_while(1.., not_line_ending).parse_next(input)?;
+ let _ = line_ending.parse_next(input)?;
- Ok((input, data))
+ Ok(data)
}
-fn message_header(input: Stream<'_>) -> IResult<Stream<'_>, Header<'_>> {
- let (input, name) = take_while(1.., is_token).parse_next(input)?;
- let (input, _) = ':'.parse_next(input)?;
- let (input, value) = repeat(1.., message_header_value).parse_next(input)?;
+fn message_header<'s>(input: &mut Stream<'s>) -> PResult<Header<'s>> {
+ let name = take_while(1.., is_token).parse_next(input)?;
+ let _ = ':'.parse_next(input)?;
+ let value = repeat(1.., message_header_value).parse_next(input)?;
- Ok((input, Header { name, value }))
+ Ok(Header { name, value })
}
#[rustfmt::skip]
diff --git a/vendor/winnow/examples/ini/bench.rs b/vendor/winnow/examples/ini/bench.rs
index cffea3b84..3c7eab8fa 100644
--- a/vendor/winnow/examples/ini/bench.rs
+++ b/vendor/winnow/examples/ini/bench.rs
@@ -18,10 +18,10 @@ file=payroll.dat
let mut group = c.benchmark_group("ini");
group.throughput(criterion::Throughput::Bytes(str.len() as u64));
group.bench_function(criterion::BenchmarkId::new("bytes", str.len()), |b| {
- b.iter(|| parser::categories(str.as_bytes()).unwrap());
+ b.iter(|| parser::categories.parse_peek(str.as_bytes()).unwrap());
});
group.bench_function(criterion::BenchmarkId::new("str", str.len()), |b| {
- b.iter(|| parser_str::categories(str).unwrap())
+ b.iter(|| parser_str::categories.parse_peek(str).unwrap())
});
}
@@ -31,14 +31,14 @@ port=143
file=payroll.dat
\0";
- fn acc(i: parser::Stream<'_>) -> IResult<parser::Stream<'_>, Vec<(&str, &str)>> {
+ fn acc<'s>(i: &mut parser::Stream<'s>) -> PResult<Vec<(&'s str, &'s str)>> {
repeat(0.., parser::key_value).parse_next(i)
}
let mut group = c.benchmark_group("ini keys and values");
group.throughput(criterion::Throughput::Bytes(str.len() as u64));
group.bench_function(criterion::BenchmarkId::new("bytes", str.len()), |b| {
- b.iter(|| acc(str.as_bytes()).unwrap());
+ b.iter(|| acc.parse_peek(str.as_bytes()).unwrap());
});
}
@@ -48,7 +48,7 @@ fn bench_ini_key_value(c: &mut criterion::Criterion) {
let mut group = c.benchmark_group("ini key value");
group.throughput(criterion::Throughput::Bytes(str.len() as u64));
group.bench_function(criterion::BenchmarkId::new("bytes", str.len()), |b| {
- b.iter(|| parser::key_value(str.as_bytes()).unwrap());
+ b.iter(|| parser::key_value.parse_peek(str.as_bytes()).unwrap());
});
}
diff --git a/vendor/winnow/examples/ini/parser.rs b/vendor/winnow/examples/ini/parser.rs
index 8852b6d30..a782d6e70 100644
--- a/vendor/winnow/examples/ini/parser.rs
+++ b/vendor/winnow/examples/ini/parser.rs
@@ -12,7 +12,7 @@ use winnow::{
pub type Stream<'i> = &'i [u8];
-pub fn categories(i: Stream<'_>) -> IResult<Stream<'_>, HashMap<&str, HashMap<&str, &str>>> {
+pub fn categories<'s>(i: &mut Stream<'s>) -> PResult<HashMap<&'s str, HashMap<&'s str, &'s str>>> {
repeat(
0..,
separated_pair(
@@ -24,20 +24,20 @@ pub fn categories(i: Stream<'_>) -> IResult<Stream<'_>, HashMap<&str, HashMap<&s
.parse_next(i)
}
-fn category(i: Stream<'_>) -> IResult<Stream<'_>, &str> {
+fn category<'s>(i: &mut Stream<'s>) -> PResult<&'s str> {
delimited('[', take_while(0.., |c| c != b']'), ']')
.try_map(str::from_utf8)
.parse_next(i)
}
-pub fn key_value(i: Stream<'_>) -> IResult<Stream<'_>, (&str, &str)> {
- let (i, key) = alphanumeric.try_map(str::from_utf8).parse_next(i)?;
- let (i, _) = (opt(space), '=', opt(space)).parse_next(i)?;
- let (i, val) = take_while(0.., |c| c != b'\n' && c != b';')
+pub fn key_value<'s>(i: &mut Stream<'s>) -> PResult<(&'s str, &'s str)> {
+ let key = alphanumeric.try_map(str::from_utf8).parse_next(i)?;
+ let _ = (opt(space), '=', opt(space)).parse_next(i)?;
+ let val = take_while(0.., |c| c != b'\n' && c != b';')
.try_map(str::from_utf8)
.parse_next(i)?;
- let (i, _) = opt((';', take_while(0.., |c| c != b'\n'))).parse_next(i)?;
- Ok((i, (key, val)))
+ let _ = opt((';', take_while(0.., |c| c != b'\n'))).parse_next(i)?;
+ Ok((key, val))
}
#[test]
@@ -50,7 +50,7 @@ key = value2"[..];
let ini_without_category = &b"\n\nparameter=value
key = value2"[..];
- let res = category(ini_file);
+ let res = category.parse_peek(ini_file);
println!("{:?}", res);
match res {
Ok((i, o)) => println!("i: {:?} | o: {:?}", str::from_utf8(i), o),
@@ -67,7 +67,7 @@ key = value2"[..];
let ini_without_key_value = &b"\nkey = value2"[..];
- let res = key_value(ini_file);
+ let res = key_value.parse_peek(ini_file);
println!("{:?}", res);
match res {
Ok((i, (o1, o2))) => println!("i: {:?} | o: ({:?},{:?})", str::from_utf8(i), o1, o2),
@@ -84,7 +84,7 @@ key = value2"[..];
let ini_without_key_value = &b"\nkey = value2"[..];
- let res = key_value(ini_file);
+ let res = key_value.parse_peek(ini_file);
println!("{:?}", res);
match res {
Ok((i, (o1, o2))) => println!("i: {:?} | o: ({:?},{:?})", str::from_utf8(i), o1, o2),
@@ -101,7 +101,7 @@ key = value2"[..];
let ini_without_key_value = &b"\nkey = value2"[..];
- let res = key_value(ini_file);
+ let res = key_value.parse_peek(ini_file);
println!("{:?}", res);
match res {
Ok((i, (o1, o2))) => println!("i: {:?} | o: ({:?},{:?})", str::from_utf8(i), o1, o2),
@@ -126,7 +126,7 @@ key4 = value4
let ini_after_parser = &b""[..];
- let res = categories(ini_file);
+ let res = categories.parse_peek(ini_file);
//println!("{:?}", res);
match res {
Ok((i, ref o)) => println!("i: {:?} | o: {:?}", str::from_utf8(i), o),
diff --git a/vendor/winnow/examples/ini/parser_str.rs b/vendor/winnow/examples/ini/parser_str.rs
index eb084a9b8..8f7b9cefc 100644
--- a/vendor/winnow/examples/ini/parser_str.rs
+++ b/vendor/winnow/examples/ini/parser_str.rs
@@ -11,47 +11,49 @@ use winnow::{
pub type Stream<'i> = &'i str;
-pub fn categories(input: Stream<'_>) -> IResult<Stream<'_>, HashMap<&str, HashMap<&str, &str>>> {
+pub fn categories<'s>(
+ input: &mut Stream<'s>,
+) -> PResult<HashMap<&'s str, HashMap<&'s str, &'s str>>> {
repeat(0.., category_and_keys).parse_next(input)
}
-fn category_and_keys(i: Stream<'_>) -> IResult<Stream<'_>, (&str, HashMap<&str, &str>)> {
+fn category_and_keys<'s>(i: &mut Stream<'s>) -> PResult<(&'s str, HashMap<&'s str, &'s str>)> {
(category, keys_and_values).parse_next(i)
}
-fn category(i: Stream<'_>) -> IResult<Stream<'_>, &str> {
+fn category<'s>(i: &mut Stream<'s>) -> PResult<&'s str> {
terminated(
delimited('[', take_while(0.., |c| c != ']'), ']'),
- opt(take_while(1.., " \r\n")),
+ opt(take_while(1.., [' ', '\r', '\n'])),
)
.parse_next(i)
}
-fn keys_and_values(input: Stream<'_>) -> IResult<Stream<'_>, HashMap<&str, &str>> {
+fn keys_and_values<'s>(input: &mut Stream<'s>) -> PResult<HashMap<&'s str, &'s str>> {
repeat(0.., key_value).parse_next(input)
}
-fn key_value(i: Stream<'_>) -> IResult<Stream<'_>, (&str, &str)> {
- let (i, key) = alphanumeric(i)?;
- let (i, _) = (opt(space), "=", opt(space)).parse_next(i)?;
- let (i, val) = take_till0(is_line_ending_or_comment).parse_next(i)?;
- let (i, _) = opt(space).parse_next(i)?;
- let (i, _) = opt((";", not_line_ending)).parse_next(i)?;
- let (i, _) = opt(space_or_line_ending).parse_next(i)?;
+fn key_value<'s>(i: &mut Stream<'s>) -> PResult<(&'s str, &'s str)> {
+ let key = alphanumeric.parse_next(i)?;
+ let _ = (opt(space), "=", opt(space)).parse_next(i)?;
+ let val = take_till0(is_line_ending_or_comment).parse_next(i)?;
+ let _ = opt(space).parse_next(i)?;
+ let _ = opt((";", not_line_ending)).parse_next(i)?;
+ let _ = opt(space_or_line_ending).parse_next(i)?;
- Ok((i, (key, val)))
+ Ok((key, val))
}
fn is_line_ending_or_comment(chr: char) -> bool {
chr == ';' || chr == '\n'
}
-fn not_line_ending(i: Stream<'_>) -> IResult<Stream<'_>, &str> {
+fn not_line_ending<'s>(i: &mut Stream<'s>) -> PResult<&'s str> {
take_while(0.., |c| c != '\r' && c != '\n').parse_next(i)
}
-fn space_or_line_ending(i: Stream<'_>) -> IResult<Stream<'_>, &str> {
- take_while(1.., " \r\n").parse_next(i)
+fn space_or_line_ending<'s>(i: &mut Stream<'s>) -> PResult<&'s str> {
+ take_while(1.., [' ', '\r', '\n']).parse_next(i)
}
#[test]
@@ -64,7 +66,7 @@ key = value2";
let ini_without_category = "parameter=value
key = value2";
- let res = category(ini_file);
+ let res = category.parse_peek(ini_file);
println!("{:?}", res);
match res {
Ok((i, o)) => println!("i: {} | o: {:?}", i, o),
@@ -81,7 +83,7 @@ key = value2";
let ini_without_key_value = "key = value2";
- let res = key_value(ini_file);
+ let res = key_value.parse_peek(ini_file);
println!("{:?}", res);
match res {
Ok((i, (o1, o2))) => println!("i: {} | o: ({:?},{:?})", i, o1, o2),
@@ -98,7 +100,7 @@ key = value2";
let ini_without_key_value = "key = value2";
- let res = key_value(ini_file);
+ let res = key_value.parse_peek(ini_file);
println!("{:?}", res);
match res {
Ok((i, (o1, o2))) => println!("i: {} | o: ({:?},{:?})", i, o1, o2),
@@ -115,7 +117,7 @@ key = value2";
let ini_without_key_value = "key = value2";
- let res = key_value(ini_file);
+ let res = key_value.parse_peek(ini_file);
println!("{:?}", res);
match res {
Ok((i, (o1, o2))) => println!("i: {} | o: ({:?},{:?})", i, o1, o2),
@@ -135,7 +137,7 @@ key = value2
let ini_without_key_value = "[category]";
- let res = keys_and_values(ini_file);
+ let res = keys_and_values.parse_peek(ini_file);
println!("{:?}", res);
match res {
Ok((i, ref o)) => println!("i: {} | o: {:?}", i, o),
@@ -160,7 +162,7 @@ key = value2
let ini_after_parser = "[category]";
- let res = category_and_keys(ini_file);
+ let res = category_and_keys.parse_peek(ini_file);
println!("{:?}", res);
match res {
Ok((i, ref o)) => println!("i: {} | o: {:?}", i, o),
@@ -186,7 +188,7 @@ parameter3=value3
key4 = value4
";
- let res = categories(ini_file);
+ let res = categories.parse_peek(ini_file);
//println!("{:?}", res);
match res {
Ok((i, ref o)) => println!("i: {} | o: {:?}", i, o),
diff --git a/vendor/winnow/examples/iterator.rs b/vendor/winnow/examples/iterator.rs
index 826eff3aa..5c8c7314d 100644
--- a/vendor/winnow/examples/iterator.rs
+++ b/vendor/winnow/examples/iterator.rs
@@ -9,22 +9,19 @@ use winnow::prelude::*;
fn main() {
let mut data = "abcabcabcabc";
- fn parser(i: &str) -> IResult<&str, &str> {
+ fn parser<'s>(i: &mut &'s str) -> PResult<&'s str> {
"abc".parse_next(i)
}
// `from_fn` (available from Rust 1.34) can create an iterator
// from a closure
let it = std::iter::from_fn(move || {
- match parser(data) {
+ match parser.parse_next(&mut data) {
// when successful, a parser returns a tuple of
// the remaining input and the output value.
// So we replace the captured input data with the
// remaining input, to be parsed on the next call
- Ok((i, o)) => {
- data = i;
- Some(o)
- }
+ Ok(o) => Some(o),
_ => None,
}
});
@@ -35,19 +32,18 @@ fn main() {
println!("\n********************\n");
- let data = "abcabcabcabc";
+ let mut data = "abcabcabcabc";
// if `from_fn` is not available, it is possible to fold
// over an iterator of functions
- let res = std::iter::repeat(parser).take(3).try_fold(
- (data, Vec::new()),
- |(data, mut acc), parser| {
- parser(data).map(|(i, o)| {
+ let res = std::iter::repeat(parser)
+ .take(3)
+ .try_fold(Vec::new(), |mut acc, mut parser| {
+ parser.parse_next(&mut data).map(|o| {
acc.push(o);
- (i, acc)
+ acc
})
- },
- );
+ });
// will print "parser iterator returned: Ok(("abc", ["abc", "abc", "abc"]))"
println!("\nparser iterator returned: {:?}", res);
@@ -70,7 +66,7 @@ fn main() {
.map(|(k, v)| (k.to_uppercase(), v))
.collect::<HashMap<_, _>>();
- let parser_result: IResult<_, _> = winnow_it.finish();
+ let parser_result: PResult<(_, _), ()> = winnow_it.finish();
let (remaining_input, ()) = parser_result.unwrap();
// will print "iterator returned {"key1": "value1", "key3": "value3", "key2": "value2"}, remaining input is ';'"
diff --git a/vendor/winnow/examples/json/bench.rs b/vendor/winnow/examples/json/bench.rs
index 0a2fd4ffa..d074ba52b 100644
--- a/vendor/winnow/examples/json/bench.rs
+++ b/vendor/winnow/examples/json/bench.rs
@@ -1,3 +1,4 @@
+use winnow::prelude::*;
use winnow::Partial;
mod json;
@@ -13,35 +14,44 @@ fn json_bench(c: &mut criterion::Criterion) {
group.throughput(criterion::Throughput::Bytes(len as u64));
group.bench_with_input(criterion::BenchmarkId::new("basic", name), &len, |b, _| {
- type Error<'i> = winnow::error::Error<parser::Stream<'i>>;
+ type Error<'i> = winnow::error::InputError<parser::Stream<'i>>;
- b.iter(|| parser::json::<Error>(sample).unwrap());
+ b.iter(|| parser::json::<Error>.parse_peek(sample).unwrap());
+ });
+ group.bench_with_input(criterion::BenchmarkId::new("unit", name), &len, |b, _| {
+ type Error<'i> = ();
+
+ b.iter(|| parser::json::<Error>.parse_peek(sample).unwrap());
});
group.bench_with_input(
- criterion::BenchmarkId::new("verbose", name),
+ criterion::BenchmarkId::new("context", name),
&len,
|b, _| {
- type Error<'i> = winnow::error::VerboseError<parser::Stream<'i>>;
+ type Error<'i> = winnow::error::ContextError<parser::Stream<'i>>;
- b.iter(|| parser::json::<Error>(sample).unwrap());
+ b.iter(|| parser::json::<Error>.parse_peek(sample).unwrap());
},
);
group.bench_with_input(
criterion::BenchmarkId::new("dispatch", name),
&len,
|b, _| {
- type Error<'i> = winnow::error::Error<parser::Stream<'i>>;
+ type Error<'i> = winnow::error::InputError<parser_dispatch::Stream<'i>>;
- b.iter(|| parser_dispatch::json::<Error>(sample).unwrap());
+ b.iter(|| parser_dispatch::json::<Error>.parse_peek(sample).unwrap());
},
);
group.bench_with_input(
criterion::BenchmarkId::new("streaming", name),
&len,
|b, _| {
- type Error<'i> = winnow::error::Error<parser_partial::Stream<'i>>;
+ type Error<'i> = winnow::error::InputError<parser_partial::Stream<'i>>;
- b.iter(|| parser_partial::json::<Error>(Partial::new(sample)).unwrap());
+ b.iter(|| {
+ parser_partial::json::<Error>
+ .parse_peek(Partial::new(sample))
+ .unwrap()
+ });
},
);
}
diff --git a/vendor/winnow/examples/json/main.rs b/vendor/winnow/examples/json/main.rs
index f738a1f05..be431e8c2 100644
--- a/vendor/winnow/examples/json/main.rs
+++ b/vendor/winnow/examples/json/main.rs
@@ -4,9 +4,7 @@ mod parser_dispatch;
#[allow(dead_code)]
mod parser_partial;
-use winnow::error::convert_error;
-use winnow::error::Error;
-use winnow::error::VerboseError;
+use winnow::error::ErrorKind;
use winnow::prelude::*;
fn main() -> Result<(), lexopt::Error> {
@@ -26,30 +24,19 @@ fn main() -> Result<(), lexopt::Error> {
} "
});
- if args.verbose {
- match parser::json::<VerboseError<&str>>.parse(data) {
- Ok(json) => {
- println!("{:#?}", json);
- }
- Err(err) => {
- if args.pretty {
- println!("{}", convert_error(data, err));
- } else {
- println!("{:#?}", err);
- }
- }
+ let result = match args.implementation {
+ Impl::Naive => parser::json::<ErrorKind>.parse(data),
+ Impl::Dispatch => parser_dispatch::json::<ErrorKind>.parse(data),
+ };
+ match result {
+ Ok(json) => {
+ println!("{:#?}", json);
}
- } else {
- let result = match args.implementation {
- Impl::Naive => parser::json::<Error<&str>>.parse(data),
- Impl::Dispatch => parser_dispatch::json::<Error<&str>>.parse(data),
- };
- match result {
- Ok(json) => {
- println!("{:#?}", json);
- }
- Err(err) => {
- println!("{:?}", err);
+ Err(err) => {
+ if args.pretty {
+ println!("{}", err);
+ } else {
+ println!("{:#?}", err);
}
}
}
@@ -61,7 +48,6 @@ fn main() -> Result<(), lexopt::Error> {
struct Args {
input: Option<String>,
invalid: bool,
- verbose: bool,
pretty: bool,
implementation: Impl,
}
@@ -89,13 +75,7 @@ impl Args {
Long("invalid") => {
res.invalid = true;
}
- Long("verbose") => {
- res.verbose = true;
- // Only case where verbose matters
- res.invalid = true;
- }
Long("pretty") => {
- res.verbose = true;
// Only case where pretty matters
res.pretty = true;
res.invalid = true;
diff --git a/vendor/winnow/examples/json/parser.rs b/vendor/winnow/examples/json/parser.rs
index 719dea5d9..8aa3bd387 100644
--- a/vendor/winnow/examples/json/parser.rs
+++ b/vendor/winnow/examples/json/parser.rs
@@ -8,7 +8,7 @@ use winnow::{
combinator::cut_err,
combinator::{delimited, preceded, separated_pair, terminated},
combinator::{fold_repeat, separated0},
- error::{ContextError, ParseError},
+ error::{AddContext, ParserError},
token::{any, none_of, take, take_while},
};
@@ -19,8 +19,8 @@ pub type Stream<'i> = &'i str;
/// The root element of a JSON parser is any value
///
/// A parser has the following signature:
-/// `Stream -> IResult<Stream, Output, Error>`, with `IResult` defined as:
-/// `type IResult<I, O, E = (I, ErrorKind)> = Result<(I, O), Err<E>>;`
+/// `&mut Stream -> PResult<Output, InputError>`, with `PResult` defined as:
+/// `type PResult<O, E = (I, ErrorKind)> = Result<O, Err<E>>;`
///
/// most of the times you can ignore the error type and use the default (but this
/// examples shows custom error types later on!)
@@ -28,17 +28,17 @@ pub type Stream<'i> = &'i str;
/// Here we use `&str` as input type, but parsers can be generic over
/// the input type, work directly with `&[u8]`, or any other type that
/// implements the required traits.
-pub fn json<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, JsonValue, E> {
+pub fn json<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<JsonValue, E> {
delimited(ws, json_value, ws).parse_next(input)
}
/// `alt` is a combinator that tries multiple parsers one by one, until
/// one of them succeeds
-fn json_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, JsonValue, E> {
+fn json_value<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<JsonValue, E> {
// `alt` combines the each value parser. It returns the result of the first
// successful parser, or an error
alt((
@@ -55,7 +55,7 @@ fn json_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static
/// `tag(string)` generates a parser that recognizes the argument string.
///
/// This also shows returning a sub-slice of the original input
-fn null<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
+fn null<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<&'i str, E> {
// This is a parser that returns `"null"` if it sees the string "null", and
// an error otherwise
"null".parse_next(input)
@@ -63,7 +63,7 @@ fn null<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>,
/// We can combine `tag` with other functions, like `value` which returns a given constant value on
/// success.
-fn boolean<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, bool, E> {
+fn boolean<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<bool, E> {
// This is a parser that returns `true` if it sees the string "true", and
// an error otherwise
let parse_true = "true".value(true);
@@ -77,9 +77,9 @@ fn boolean<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'
/// This parser gathers all `char`s up into a `String`with a parse to recognize the double quote
/// character, before the string (using `preceded`) and after the string (using `terminated`).
-fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, String, E> {
+fn string<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<String, E> {
preceded(
'\"',
// `cut_err` transforms an `ErrMode::Backtrack(e)` to `ErrMode::Cut(e)`, signaling to
@@ -102,8 +102,8 @@ fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
/// You can mix the above declarative parsing with an imperative style to handle more unique cases,
/// like escaping
-fn character<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, char, E> {
- let (input, c) = none_of("\"").parse_next(input)?;
+fn character<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<char, E> {
+ let c = none_of('\"').parse_next(input)?;
if c == '\\' {
alt((
any.verify_map(|c| {
@@ -121,13 +121,11 @@ fn character<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream
))
.parse_next(input)
} else {
- Ok((input, c))
+ Ok(c)
}
}
-fn unicode_escape<'i, E: ParseError<Stream<'i>>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, char, E> {
+fn unicode_escape<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<char, E> {
alt((
// Not a surrogate
u16_hex
@@ -149,7 +147,7 @@ fn unicode_escape<'i, E: ParseError<Stream<'i>>>(
.parse_next(input)
}
-fn u16_hex<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, u16, E> {
+fn u16_hex<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<u16, E> {
take(4usize)
.verify_map(|s| u16::from_str_radix(s, 16).ok())
.parse_next(input)
@@ -159,9 +157,9 @@ fn u16_hex<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'
/// 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`)
-fn array<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, Vec<JsonValue>, E> {
+fn array<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<Vec<JsonValue>, E> {
preceded(
('[', ws),
cut_err(terminated(separated0(json_value, (ws, ',', ws)), (ws, ']'))),
@@ -170,9 +168,9 @@ fn array<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>
.parse_next(input)
}
-fn object<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, HashMap<String, JsonValue>, E> {
+fn object<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<HashMap<String, JsonValue>, E> {
preceded(
('{', ws),
cut_err(terminated(separated0(key_value, (ws, ',', ws)), (ws, '}'))),
@@ -181,22 +179,22 @@ fn object<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
.parse_next(input)
}
-fn key_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, (String, JsonValue), E> {
+fn key_value<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<(String, JsonValue), E> {
separated_pair(string, cut_err((ws, ':', ws)), json_value).parse_next(input)
}
/// Parser combinators are constructed from the bottom up:
/// first we write parsers for the smallest elements (here a space character),
/// then we'll combine them in larger parsers
-fn ws<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
+fn ws<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<&'i str, E> {
// Combinators like `take_while` return a function. That function is the
// parser,to which we can pass the input
take_while(0.., WS).parse_next(input)
}
-const WS: &str = " \t\r\n";
+const WS: &[char] = &[' ', '\t', '\r', '\n'];
#[cfg(test)]
mod test {
@@ -206,28 +204,37 @@ mod test {
#[allow(clippy::useless_attribute)]
#[allow(dead_code)] // its dead for benches
- type Error<'i> = winnow::error::Error<&'i str>;
+ type Error<'i> = winnow::error::InputError<&'i str>;
#[test]
fn json_string() {
- assert_eq!(string::<Error<'_>>("\"\""), Ok(("", "".to_string())));
- assert_eq!(string::<Error<'_>>("\"abc\""), Ok(("", "abc".to_string())));
assert_eq!(
- string::<Error<'_>>("\"abc\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0001\\u2014\u{2014}def\""),
+ string::<Error<'_>>.parse_peek("\"\""),
+ Ok(("", "".to_string()))
+ );
+ assert_eq!(
+ string::<Error<'_>>.parse_peek("\"abc\""),
+ Ok(("", "abc".to_string()))
+ );
+ assert_eq!(
+ string::<Error<'_>>
+ .parse_peek("\"abc\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0001\\u2014\u{2014}def\""),
Ok(("", "abc\"\\/\x08\x0C\n\r\t\x01——def".to_string())),
);
assert_eq!(
- string::<Error<'_>>("\"\\uD83D\\uDE10\""),
+ string::<Error<'_>>.parse_peek("\"\\uD83D\\uDE10\""),
Ok(("", "😐".to_string()))
);
- assert!(string::<Error<'_>>("\"").is_err());
- assert!(string::<Error<'_>>("\"abc").is_err());
- assert!(string::<Error<'_>>("\"\\\"").is_err());
- assert!(string::<Error<'_>>("\"\\u123\"").is_err());
- assert!(string::<Error<'_>>("\"\\uD800\"").is_err());
- assert!(string::<Error<'_>>("\"\\uD800\\uD800\"").is_err());
- assert!(string::<Error<'_>>("\"\\uDC00\"").is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"").is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"abc").is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"\\\"").is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"\\u123\"").is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"\\uD800\"").is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek("\"\\uD800\\uD800\"")
+ .is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"\\uDC00\"").is_err());
}
#[test]
@@ -245,7 +252,7 @@ mod test {
.collect(),
);
- assert_eq!(json::<Error<'_>>(input), Ok(("", expected)));
+ assert_eq!(json::<Error<'_>>.parse_peek(input), Ok(("", expected)));
}
#[test]
@@ -256,7 +263,7 @@ mod test {
let expected = Array(vec![Num(42.0), Str("x".to_string())]);
- assert_eq!(json::<Error<'_>>(input), Ok(("", expected)));
+ assert_eq!(json::<Error<'_>>.parse_peek(input), Ok(("", expected)));
}
#[test]
@@ -278,7 +285,7 @@ mod test {
"#;
assert_eq!(
- json::<Error<'_>>(input),
+ json::<Error<'_>>.parse_peek(input),
Ok((
"",
Object(
diff --git a/vendor/winnow/examples/json/parser_dispatch.rs b/vendor/winnow/examples/json/parser_dispatch.rs
index 29d6d5f90..6fa722b45 100644
--- a/vendor/winnow/examples/json/parser_dispatch.rs
+++ b/vendor/winnow/examples/json/parser_dispatch.rs
@@ -11,7 +11,7 @@ use winnow::{
combinator::{alt, dispatch},
combinator::{delimited, preceded, separated_pair, terminated},
combinator::{fold_repeat, separated0},
- error::{ContextError, ParseError},
+ error::{AddContext, ParserError},
token::{any, none_of, take, take_while},
};
@@ -22,8 +22,8 @@ pub type Stream<'i> = &'i str;
/// The root element of a JSON parser is any value
///
/// A parser has the following signature:
-/// `Stream -> IResult<Stream, Output, Error>`, with `IResult` defined as:
-/// `type IResult<I, O, E = (I, ErrorKind)> = Result<(I, O), Err<E>>;`
+/// `&mut Stream -> PResult<Output, InputError>`, with `PResult` defined as:
+/// `type PResult<O, E = ErrorKind> = Result<O, ErrMode<E>>;`
///
/// most of the times you can ignore the error type and use the default (but this
/// examples shows custom error types later on!)
@@ -31,17 +31,17 @@ pub type Stream<'i> = &'i str;
/// Here we use `&str` as input type, but parsers can be generic over
/// the input type, work directly with `&[u8]`, or any other type that
/// implements the required traits.
-pub fn json<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, JsonValue, E> {
+pub fn json<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<JsonValue, E> {
delimited(ws, json_value, ws).parse_next(input)
}
/// `alt` is a combinator that tries multiple parsers one by one, until
/// one of them succeeds
-fn json_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, JsonValue, E> {
+fn json_value<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<JsonValue, E> {
// `dispatch` gives you `match`-like behavior compared to `alt` successively trying different
// implementations.
dispatch!(peek(any);
@@ -62,7 +62,7 @@ fn json_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static
/// `tag(string)` generates a parser that recognizes the argument string.
///
/// This also shows returning a sub-slice of the original input
-fn null<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
+fn null<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<&'i str, E> {
// This is a parser that returns `"null"` if it sees the string "null", and
// an error otherwise
"null".parse_next(input)
@@ -70,7 +70,7 @@ fn null<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>,
/// We can combine `tag` with other functions, like `value` which returns a given constant value on
/// success.
-fn true_<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, bool, E> {
+fn true_<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<bool, E> {
// This is a parser that returns `true` if it sees the string "true", and
// an error otherwise
"true".value(true).parse_next(input)
@@ -78,7 +78,7 @@ fn true_<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>
/// We can combine `tag` with other functions, like `value` which returns a given constant value on
/// success.
-fn false_<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, bool, E> {
+fn false_<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<bool, E> {
// This is a parser that returns `false` if it sees the string "false", and
// an error otherwise
"false".value(false).parse_next(input)
@@ -86,9 +86,9 @@ fn false_<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i
/// This parser gathers all `char`s up into a `String`with a parse to recognize the double quote
/// character, before the string (using `preceded`) and after the string (using `terminated`).
-fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, String, E> {
+fn string<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<String, E> {
preceded(
'\"',
// `cut_err` transforms an `ErrMode::Backtrack(e)` to `ErrMode::Cut(e)`, signaling to
@@ -111,8 +111,8 @@ fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
/// You can mix the above declarative parsing with an imperative style to handle more unique cases,
/// like escaping
-fn character<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, char, E> {
- let (input, c) = none_of("\"").parse_next(input)?;
+fn character<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<char, E> {
+ let c = none_of('\"').parse_next(input)?;
if c == '\\' {
dispatch!(any;
'"' => success('"'),
@@ -128,13 +128,11 @@ fn character<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream
)
.parse_next(input)
} else {
- Ok((input, c))
+ Ok(c)
}
}
-fn unicode_escape<'i, E: ParseError<Stream<'i>>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, char, E> {
+fn unicode_escape<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<char, E> {
alt((
// Not a surrogate
u16_hex
@@ -156,7 +154,7 @@ fn unicode_escape<'i, E: ParseError<Stream<'i>>>(
.parse_next(input)
}
-fn u16_hex<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, u16, E> {
+fn u16_hex<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<u16, E> {
take(4usize)
.verify_map(|s| u16::from_str_radix(s, 16).ok())
.parse_next(input)
@@ -166,9 +164,9 @@ fn u16_hex<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'
/// 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`)
-fn array<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, Vec<JsonValue>, E> {
+fn array<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<Vec<JsonValue>, E> {
preceded(
('[', ws),
cut_err(terminated(separated0(json_value, (ws, ',', ws)), (ws, ']'))),
@@ -177,9 +175,9 @@ fn array<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>
.parse_next(input)
}
-fn object<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, HashMap<String, JsonValue>, E> {
+fn object<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<HashMap<String, JsonValue>, E> {
preceded(
('{', ws),
cut_err(terminated(separated0(key_value, (ws, ',', ws)), (ws, '}'))),
@@ -188,22 +186,22 @@ fn object<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
.parse_next(input)
}
-fn key_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, (String, JsonValue), E> {
+fn key_value<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<(String, JsonValue), E> {
separated_pair(string, cut_err((ws, ':', ws)), json_value).parse_next(input)
}
/// Parser combinators are constructed from the bottom up:
/// first we write parsers for the smallest elements (here a space character),
/// then we'll combine them in larger parsers
-fn ws<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
+fn ws<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<&'i str, E> {
// Combinators like `take_while` return a function. That function is the
// parser,to which we can pass the input
take_while(0.., WS).parse_next(input)
}
-const WS: &str = " \t\r\n";
+const WS: &[char] = &[' ', '\t', '\r', '\n'];
#[cfg(test)]
mod test {
@@ -213,28 +211,37 @@ mod test {
#[allow(clippy::useless_attribute)]
#[allow(dead_code)] // its dead for benches
- type Error<'i> = winnow::error::Error<&'i str>;
+ type Error<'i> = winnow::error::InputError<&'i str>;
#[test]
fn json_string() {
- assert_eq!(string::<Error<'_>>("\"\""), Ok(("", "".to_string())));
- assert_eq!(string::<Error<'_>>("\"abc\""), Ok(("", "abc".to_string())));
assert_eq!(
- string::<Error<'_>>("\"abc\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0001\\u2014\u{2014}def\""),
+ string::<Error<'_>>.parse_peek("\"\""),
+ Ok(("", "".to_string()))
+ );
+ assert_eq!(
+ string::<Error<'_>>.parse_peek("\"abc\""),
+ Ok(("", "abc".to_string()))
+ );
+ assert_eq!(
+ string::<Error<'_>>
+ .parse_peek("\"abc\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0001\\u2014\u{2014}def\""),
Ok(("", "abc\"\\/\x08\x0C\n\r\t\x01——def".to_string())),
);
assert_eq!(
- string::<Error<'_>>("\"\\uD83D\\uDE10\""),
+ string::<Error<'_>>.parse_peek("\"\\uD83D\\uDE10\""),
Ok(("", "😐".to_string()))
);
- assert!(string::<Error<'_>>("\"").is_err());
- assert!(string::<Error<'_>>("\"abc").is_err());
- assert!(string::<Error<'_>>("\"\\\"").is_err());
- assert!(string::<Error<'_>>("\"\\u123\"").is_err());
- assert!(string::<Error<'_>>("\"\\uD800\"").is_err());
- assert!(string::<Error<'_>>("\"\\uD800\\uD800\"").is_err());
- assert!(string::<Error<'_>>("\"\\uDC00\"").is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"").is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"abc").is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"\\\"").is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"\\u123\"").is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"\\uD800\"").is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek("\"\\uD800\\uD800\"")
+ .is_err());
+ assert!(string::<Error<'_>>.parse_peek("\"\\uDC00\"").is_err());
}
#[test]
@@ -252,7 +259,7 @@ mod test {
.collect(),
);
- assert_eq!(json::<Error<'_>>(input), Ok(("", expected)));
+ assert_eq!(json::<Error<'_>>.parse_peek(input), Ok(("", expected)));
}
#[test]
@@ -263,7 +270,7 @@ mod test {
let expected = Array(vec![Num(42.0), Str("x".to_string())]);
- assert_eq!(json::<Error<'_>>(input), Ok(("", expected)));
+ assert_eq!(json::<Error<'_>>.parse_peek(input), Ok(("", expected)));
}
#[test]
@@ -285,7 +292,7 @@ mod test {
"#;
assert_eq!(
- json::<Error<'_>>(input),
+ json::<Error<'_>>.parse_peek(input),
Ok((
"",
Object(
diff --git a/vendor/winnow/examples/json/parser_partial.rs b/vendor/winnow/examples/json/parser_partial.rs
index 4b6d143f9..3538d8e13 100644
--- a/vendor/winnow/examples/json/parser_partial.rs
+++ b/vendor/winnow/examples/json/parser_partial.rs
@@ -8,7 +8,7 @@ use winnow::{
combinator::{cut_err, rest},
combinator::{delimited, preceded, separated_pair, terminated},
combinator::{fold_repeat, separated0},
- error::{ContextError, ParseError},
+ error::{AddContext, ParserError},
stream::Partial,
token::{any, none_of, take, take_while},
};
@@ -20,8 +20,8 @@ pub type Stream<'i> = Partial<&'i str>;
/// The root element of a JSON parser is any value
///
/// A parser has the following signature:
-/// `Stream -> IResult<Stream, Output, Error>`, with `IResult` defined as:
-/// `type IResult<I, O, E = (I, ErrorKind)> = Result<(I, O), Err<E>>;`
+/// `&mut Stream -> PResult<Output, InputError>`, with `PResult` defined as:
+/// `type PResult<O, E = ErrorKind> = Result<O, ErrMode<E>>;`
///
/// most of the times you can ignore the error type and use the default (but this
/// examples shows custom error types later on!)
@@ -29,17 +29,17 @@ pub type Stream<'i> = Partial<&'i str>;
/// Here we use `&str` as input type, but parsers can be generic over
/// the input type, work directly with `&[u8]`, or any other type that
/// implements the required traits.
-pub fn json<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, JsonValue, E> {
+pub fn json<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<JsonValue, E> {
delimited(ws, json_value, ws_or_eof).parse_next(input)
}
/// `alt` is a combinator that tries multiple parsers one by one, until
/// one of them succeeds
-fn json_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, JsonValue, E> {
+fn json_value<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<JsonValue, E> {
// `alt` combines the each value parser. It returns the result of the first
// successful parser, or an error
alt((
@@ -56,7 +56,7 @@ fn json_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static
/// `tag(string)` generates a parser that recognizes the argument string.
///
/// This also shows returning a sub-slice of the original input
-fn null<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
+fn null<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<&'i str, E> {
// This is a parser that returns `"null"` if it sees the string "null", and
// an error otherwise
"null".parse_next(input)
@@ -64,7 +64,7 @@ fn null<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>,
/// We can combine `tag` with other functions, like `value` which returns a given constant value on
/// success.
-fn boolean<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, bool, E> {
+fn boolean<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<bool, E> {
// This is a parser that returns `true` if it sees the string "true", and
// an error otherwise
let parse_true = "true".value(true);
@@ -78,9 +78,9 @@ fn boolean<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'
/// This parser gathers all `char`s up into a `String`with a parse to recognize the double quote
/// character, before the string (using `preceded`) and after the string (using `terminated`).
-fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, String, E> {
+fn string<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<String, E> {
preceded(
'\"',
// `cut_err` transforms an `ErrMode::Backtrack(e)` to `ErrMode::Cut(e)`, signaling to
@@ -103,8 +103,8 @@ fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
/// You can mix the above declarative parsing with an imperative style to handle more unique cases,
/// like escaping
-fn character<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, char, E> {
- let (input, c) = none_of("\"").parse_next(input)?;
+fn character<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<char, E> {
+ let c = none_of('\"').parse_next(input)?;
if c == '\\' {
alt((
any.verify_map(|c| {
@@ -122,13 +122,11 @@ fn character<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream
))
.parse_next(input)
} else {
- Ok((input, c))
+ Ok(c)
}
}
-fn unicode_escape<'i, E: ParseError<Stream<'i>>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, char, E> {
+fn unicode_escape<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<char, E> {
alt((
// Not a surrogate
u16_hex
@@ -150,7 +148,7 @@ fn unicode_escape<'i, E: ParseError<Stream<'i>>>(
.parse_next(input)
}
-fn u16_hex<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, u16, E> {
+fn u16_hex<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<u16, E> {
take(4usize)
.verify_map(|s| u16::from_str_radix(s, 16).ok())
.parse_next(input)
@@ -160,9 +158,9 @@ fn u16_hex<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'
/// 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`)
-fn array<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, Vec<JsonValue>, E> {
+fn array<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<Vec<JsonValue>, E> {
preceded(
('[', ws),
cut_err(terminated(separated0(json_value, (ws, ',', ws)), (ws, ']'))),
@@ -171,9 +169,9 @@ fn array<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>
.parse_next(input)
}
-fn object<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, HashMap<String, JsonValue>, E> {
+fn object<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<HashMap<String, JsonValue>, E> {
preceded(
('{', ws),
cut_err(terminated(separated0(key_value, (ws, ',', ws)), (ws, '}'))),
@@ -182,27 +180,27 @@ fn object<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
.parse_next(input)
}
-fn key_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, (String, JsonValue), E> {
+fn key_value<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<(String, JsonValue), E> {
separated_pair(string, cut_err((ws, ':', ws)), json_value).parse_next(input)
}
/// Parser combinators are constructed from the bottom up:
/// first we write parsers for the smallest elements (here a space character),
/// then we'll combine them in larger parsers
-fn ws<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
+fn ws<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<&'i str, E> {
// Combinators like `take_while` return a function. That function is the
// parser,to which we can pass the input
take_while(0.., WS).parse_next(input)
}
-fn ws_or_eof<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
- rest.verify(|s: &str| s.chars().all(|c| WS.contains(c)))
+fn ws_or_eof<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<&'i str, E> {
+ rest.verify(|s: &str| s.chars().all(|c| WS.contains(&c)))
.parse_next(input)
}
-const WS: &str = " \t\r\n";
+const WS: &[char] = &[' ', '\t', '\r', '\n'];
#[cfg(test)]
mod test {
@@ -212,20 +210,20 @@ mod test {
#[allow(clippy::useless_attribute)]
#[allow(dead_code)] // its dead for benches
- type Error<'i> = winnow::error::Error<Partial<&'i str>>;
+ type Error<'i> = winnow::error::InputError<Partial<&'i str>>;
#[test]
fn json_string() {
assert_eq!(
- string::<Error<'_>>(Partial::new("\"\"")),
+ string::<Error<'_>>.parse_peek(Partial::new("\"\"")),
Ok((Partial::new(""), "".to_string()))
);
assert_eq!(
- string::<Error<'_>>(Partial::new("\"abc\"")),
+ string::<Error<'_>>.parse_peek(Partial::new("\"abc\"")),
Ok((Partial::new(""), "abc".to_string()))
);
assert_eq!(
- string::<Error<'_>>(Partial::new(
+ string::<Error<'_>>.parse_peek(Partial::new(
"\"abc\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0001\\u2014\u{2014}def\""
)),
Ok((
@@ -234,17 +232,29 @@ mod test {
)),
);
assert_eq!(
- string::<Error<'_>>(Partial::new("\"\\uD83D\\uDE10\"")),
+ string::<Error<'_>>.parse_peek(Partial::new("\"\\uD83D\\uDE10\"")),
Ok((Partial::new(""), "😐".to_string()))
);
- assert!(string::<Error<'_>>(Partial::new("\"")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"abc")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"\\\"")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"\\u123\"")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"\\uD800\"")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"\\uD800\\uD800\"")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"\\uDC00\"")).is_err());
+ assert!(string::<Error<'_>>.parse_peek(Partial::new("\"")).is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"abc"))
+ .is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"\\\""))
+ .is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"\\u123\""))
+ .is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"\\uD800\""))
+ .is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"\\uD800\\uD800\""))
+ .is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"\\uDC00\""))
+ .is_err());
}
#[test]
@@ -263,7 +273,7 @@ mod test {
);
assert_eq!(
- json::<Error<'_>>(Partial::new(input)),
+ json::<Error<'_>>.parse_peek(Partial::new(input)),
Ok((Partial::new(""), expected))
);
}
@@ -277,7 +287,7 @@ mod test {
let expected = Array(vec![Num(42.0), Str("x".to_string())]);
assert_eq!(
- json::<Error<'_>>(Partial::new(input)),
+ json::<Error<'_>>.parse_peek(Partial::new(input)),
Ok((Partial::new(""), expected))
);
}
@@ -301,7 +311,7 @@ mod test {
"#;
assert_eq!(
- json::<Error<'_>>(Partial::new(input)),
+ json::<Error<'_>>.parse_peek(Partial::new(input)),
Ok((
Partial::new(""),
Object(
diff --git a/vendor/winnow/examples/json_iterator.rs b/vendor/winnow/examples/json_iterator.rs
index f4d8ead2a..b8b46f39c 100644
--- a/vendor/winnow/examples/json_iterator.rs
+++ b/vendor/winnow/examples/json_iterator.rs
@@ -7,10 +7,11 @@ use winnow::{
combinator::cut_err,
combinator::separated0,
combinator::{preceded, separated_pair, terminated},
- error::ParseError,
+ error::ParserError,
+ error::StrContext,
+ stream::Offset,
token::one_of,
token::{tag, take_while},
- IResult,
};
use std::cell::Cell;
@@ -28,7 +29,7 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
}
pub fn offset(&self, input: &'a str) {
- let offset = input.as_ptr() as usize - self.input.as_ptr() as usize;
+ let offset = input.offset_from(&self.input);
self.offset.set(offset);
}
@@ -38,9 +39,10 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
pub fn string(&self) -> Option<&'a str> {
println!("string()");
- match string(self.data()) {
- Ok((i, s)) => {
- self.offset(i);
+ let mut data = self.data();
+ match string(&mut data) {
+ Ok(s) => {
+ self.offset(data);
println!("-> {}", s);
Some(s)
}
@@ -50,9 +52,10 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
pub fn boolean(&self) -> Option<bool> {
println!("boolean()");
- match boolean(self.data()) {
- Ok((i, o)) => {
- self.offset(i);
+ let mut data = self.data();
+ match boolean(&mut data) {
+ Ok(o) => {
+ self.offset(data);
println!("-> {}", o);
Some(o)
}
@@ -62,9 +65,10 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
pub fn number(&self) -> Option<f64> {
println!("number()");
- match float::<_, _, ()>(self.data()) {
- Ok((i, o)) => {
- self.offset(i);
+ let mut data = self.data();
+ match float::<_, _, ()>.parse_next(&mut data) {
+ Ok(o) => {
+ self.offset(data);
println!("-> {}", o);
Some(o)
}
@@ -75,11 +79,12 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
pub fn array(&self) -> Option<impl Iterator<Item = JsonValue<'a, 'b>>> {
println!("array()");
- match tag::<_, _, ()>("[").parse_next(self.data()) {
+ let mut data = self.data();
+ match tag::<_, _, ()>("[").parse_next(&mut data) {
Err(_) => None,
- Ok((i, _)) => {
+ Ok(_) => {
println!("[");
- self.offset(i);
+ self.offset(data);
let mut first = true;
let mut done = false;
let mut previous = std::usize::MAX;
@@ -94,14 +99,14 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
// if we ignored one of the items, skip over the value
if v.offset.get() == previous {
println!("skipping value");
- if let Ok((i, _)) = value(v.data()) {
- v.offset(i);
+ if value(&mut data).is_ok() {
+ v.offset(data);
}
}
- if let Ok((i, _)) = tag::<_, _, ()>("]").parse_next(v.data()) {
+ if tag::<_, _, ()>("]").parse_next(&mut data).is_ok() {
println!("]");
- v.offset(i);
+ v.offset(data);
done = true;
return None;
}
@@ -109,10 +114,10 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
if first {
first = false;
} else {
- match tag::<_, _, ()>(",").parse_next(v.data()) {
- Ok((i, _)) => {
+ match tag::<_, _, ()>(",").parse_next(&mut data) {
+ Ok(_) => {
println!(",");
- v.offset(i);
+ v.offset(data);
}
Err(_) => {
done = true;
@@ -131,10 +136,11 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
pub fn object(&self) -> Option<impl Iterator<Item = (&'a str, JsonValue<'a, 'b>)>> {
println!("object()");
- match tag::<_, _, ()>("{").parse_next(self.data()) {
+ let mut data = self.data();
+ match tag::<_, _, ()>("{").parse_next(&mut data) {
Err(_) => None,
- Ok((i, _)) => {
- self.offset(i);
+ Ok(_) => {
+ self.offset(data);
println!("{{");
@@ -152,14 +158,14 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
// if we ignored one of the items, skip over the value
if v.offset.get() == previous {
println!("skipping value");
- if let Ok((i, _)) = value(v.data()) {
- v.offset(i);
+ if value(&mut data).is_ok() {
+ v.offset(data);
}
}
- if let Ok((i, _)) = tag::<_, _, ()>("}").parse_next(v.data()) {
+ if tag::<_, _, ()>("}").parse_next(&mut data).is_ok() {
println!("}}");
- v.offset(i);
+ v.offset(data);
done = true;
return None;
}
@@ -167,10 +173,10 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
if first {
first = false;
} else {
- match tag::<_, _, ()>(",").parse_next(v.data()) {
- Ok((i, _)) => {
+ match tag::<_, _, ()>(",").parse_next(&mut data) {
+ Ok(_) => {
println!(",");
- v.offset(i);
+ v.offset(data);
}
Err(_) => {
done = true;
@@ -179,14 +185,14 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
}
}
- match string(v.data()) {
- Ok((i, key)) => {
- v.offset(i);
+ match string(&mut data) {
+ Ok(key) => {
+ v.offset(data);
- match tag::<_, _, ()>(":").parse_next(v.data()) {
+ match tag::<_, _, ()>(":").parse_next(&mut data) {
Err(_) => None,
- Ok((i, _)) => {
- v.offset(i);
+ Ok(_) => {
+ v.offset(data);
previous = v.offset.get();
@@ -203,27 +209,27 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
}
}
-fn sp<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, &'a str, E> {
+fn sp<'a, E: ParserError<&'a str>>(i: &mut &'a str) -> PResult<&'a str, E> {
let chars = " \t\r\n";
take_while(0.., move |c| chars.contains(c)).parse_next(i)
}
-fn parse_str<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, &'a str, E> {
- escaped(alphanumeric, '\\', one_of("\"n\\")).parse_next(i)
+fn parse_str<'a, E: ParserError<&'a str>>(i: &mut &'a str) -> PResult<&'a str, E> {
+ escaped(alphanumeric, '\\', one_of(['"', 'n', '\\'])).parse_next(i)
}
-fn string(i: &str) -> IResult<&str, &str> {
+fn string<'s>(i: &mut &'s str) -> PResult<&'s str> {
preceded('\"', cut_err(terminated(parse_str, '\"')))
- .context("string")
+ .context(StrContext::Label("string"))
.parse_next(i)
}
-fn boolean(input: &str) -> IResult<&str, bool> {
+fn boolean(input: &mut &str) -> PResult<bool> {
alt(("false".map(|_| false), "true".map(|_| true))).parse_next(input)
}
-fn array(i: &str) -> IResult<&str, ()> {
+fn array(i: &mut &str) -> PResult<()> {
preceded(
'[',
cut_err(terminated(
@@ -231,15 +237,15 @@ fn array(i: &str) -> IResult<&str, ()> {
preceded(sp, ']'),
)),
)
- .context("array")
+ .context(StrContext::Label("array"))
.parse_next(i)
}
-fn key_value(i: &str) -> IResult<&str, (&str, ())> {
+fn key_value<'s>(i: &mut &'s str) -> PResult<(&'s str, ())> {
separated_pair(preceded(sp, string), cut_err(preceded(sp, ':')), value).parse_next(i)
}
-fn hash(i: &str) -> IResult<&str, ()> {
+fn hash(i: &mut &str) -> PResult<()> {
preceded(
'{',
cut_err(terminated(
@@ -247,11 +253,11 @@ fn hash(i: &str) -> IResult<&str, ()> {
preceded(sp, '}'),
)),
)
- .context("map")
+ .context(StrContext::Label("map"))
.parse_next(i)
}
-fn value(i: &str) -> IResult<&str, ()> {
+fn value(i: &mut &str) -> PResult<()> {
preceded(
sp,
alt((
diff --git a/vendor/winnow/examples/ndjson/main.rs b/vendor/winnow/examples/ndjson/main.rs
index d81b6900f..6b2a716c7 100644
--- a/vendor/winnow/examples/ndjson/main.rs
+++ b/vendor/winnow/examples/ndjson/main.rs
@@ -3,8 +3,9 @@ mod parser;
use std::io::Read;
use winnow::error::ErrMode;
-use winnow::error::Error;
+use winnow::error::InputError;
use winnow::error::Needed;
+use winnow::prelude::*;
use winnow::stream::Offset;
fn main() -> Result<(), lexopt::Error> {
@@ -38,12 +39,12 @@ fn main() -> Result<(), lexopt::Error> {
loop {
let input = parser::Stream::new(std::str::from_utf8(buffer.data()).map_err(to_lexopt)?);
- match parser::ndjson::<Error<parser::Stream>>(input) {
+ match parser::ndjson::<InputError<parser::Stream>>.parse_peek(input) {
Ok((remainder, value)) => {
println!("{:?}", value);
println!();
// Tell the buffer how much we read
- let consumed = input.offset_to(&remainder);
+ let consumed = remainder.offset_from(&input);
buffer.consume(consumed);
}
Err(ErrMode::Backtrack(e)) | Err(ErrMode::Cut(e)) => {
diff --git a/vendor/winnow/examples/ndjson/parser.rs b/vendor/winnow/examples/ndjson/parser.rs
index 2a60952e3..aaa5c9346 100644
--- a/vendor/winnow/examples/ndjson/parser.rs
+++ b/vendor/winnow/examples/ndjson/parser.rs
@@ -9,7 +9,7 @@ use winnow::{
combinator::cut_err,
combinator::{delimited, preceded, separated_pair, terminated},
combinator::{fold_repeat, separated0},
- error::{ContextError, ParseError},
+ error::{AddContext, ParserError},
stream::Partial,
token::{any, none_of, take, take_while},
};
@@ -27,9 +27,9 @@ pub enum JsonValue {
/// Use `Partial` to cause `ErrMode::Incomplete` while parsing
pub type Stream<'i> = Partial<&'i str>;
-pub fn ndjson<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, Option<JsonValue>, E> {
+pub fn ndjson<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<Option<JsonValue>, E> {
alt((
terminated(delimited(ws, json_value, ws), line_ending).map(Some),
line_ending.value(None),
@@ -41,9 +41,9 @@ pub fn ndjson<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static
/// `alt` is a combinator that tries multiple parsers one by one, until
/// one of them succeeds
-fn json_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, JsonValue, E> {
+fn json_value<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<JsonValue, E> {
// `alt` combines the each value parser. It returns the result of the first
// successful parser, or an error
alt((
@@ -60,7 +60,7 @@ fn json_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static
/// `tag(string)` generates a parser that recognizes the argument string.
///
/// This also shows returning a sub-slice of the original input
-fn null<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
+fn null<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<&'i str, E> {
// This is a parser that returns `"null"` if it sees the string "null", and
// an error otherwise
"null".parse_next(input)
@@ -68,7 +68,7 @@ fn null<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>,
/// We can combine `tag` with other functions, like `value` which returns a given constant value on
/// success.
-fn boolean<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, bool, E> {
+fn boolean<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<bool, E> {
// This is a parser that returns `true` if it sees the string "true", and
// an error otherwise
let parse_true = "true".value(true);
@@ -82,9 +82,9 @@ fn boolean<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'
/// This parser gathers all `char`s up into a `String`with a parse to recognize the double quote
/// character, before the string (using `preceded`) and after the string (using `terminated`).
-fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, String, E> {
+fn string<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<String, E> {
preceded(
'\"',
// `cut_err` transforms an `ErrMode::Backtrack(e)` to `ErrMode::Cut(e)`, signaling to
@@ -107,8 +107,8 @@ fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
/// You can mix the above declarative parsing with an imperative style to handle more unique cases,
/// like escaping
-fn character<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, char, E> {
- let (input, c) = none_of("\"").parse_next(input)?;
+fn character<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<char, E> {
+ let c = none_of('"').parse_next(input)?;
if c == '\\' {
alt((
any.verify_map(|c| {
@@ -126,13 +126,11 @@ fn character<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream
))
.parse_next(input)
} else {
- Ok((input, c))
+ Ok(c)
}
}
-fn unicode_escape<'i, E: ParseError<Stream<'i>>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, char, E> {
+fn unicode_escape<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<char, E> {
alt((
// Not a surrogate
u16_hex
@@ -154,7 +152,7 @@ fn unicode_escape<'i, E: ParseError<Stream<'i>>>(
.parse_next(input)
}
-fn u16_hex<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, u16, E> {
+fn u16_hex<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<u16, E> {
take(4usize)
.verify_map(|s| u16::from_str_radix(s, 16).ok())
.parse_next(input)
@@ -164,9 +162,9 @@ fn u16_hex<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'
/// 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`)
-fn array<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, Vec<JsonValue>, E> {
+fn array<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<Vec<JsonValue>, E> {
preceded(
('[', ws),
cut_err(terminated(separated0(json_value, (ws, ',', ws)), (ws, ']'))),
@@ -175,9 +173,9 @@ fn array<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>
.parse_next(input)
}
-fn object<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, HashMap<String, JsonValue>, E> {
+fn object<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<HashMap<String, JsonValue>, E> {
preceded(
('{', ws),
cut_err(terminated(separated0(key_value, (ws, ',', ws)), (ws, '}'))),
@@ -186,22 +184,22 @@ fn object<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
.parse_next(input)
}
-fn key_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>>(
- input: Stream<'i>,
-) -> IResult<Stream<'i>, (String, JsonValue), E> {
+fn key_value<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, &'static str>>(
+ input: &mut Stream<'i>,
+) -> PResult<(String, JsonValue), E> {
separated_pair(string, cut_err((ws, ':', ws)), json_value).parse_next(input)
}
/// Parser combinators are constructed from the bottom up:
/// first we write parsers for the smallest elements (here a space character),
/// then we'll combine them in larger parsers
-fn ws<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
+fn ws<'i, E: ParserError<Stream<'i>>>(input: &mut Stream<'i>) -> PResult<&'i str, E> {
// Combinators like `take_while` return a function. That function is the
// parser,to which we can pass the input
take_while(0.., WS).parse_next(input)
}
-const WS: &str = " \t";
+const WS: &[char] = &[' ', '\t'];
#[cfg(test)]
mod test {
@@ -211,20 +209,20 @@ mod test {
#[allow(clippy::useless_attribute)]
#[allow(dead_code)] // its dead for benches
- type Error<'i> = winnow::error::Error<Partial<&'i str>>;
+ type Error<'i> = winnow::error::InputError<Partial<&'i str>>;
#[test]
fn json_string() {
assert_eq!(
- string::<Error<'_>>(Partial::new("\"\"")),
+ string::<Error<'_>>.parse_peek(Partial::new("\"\"")),
Ok((Partial::new(""), "".to_string()))
);
assert_eq!(
- string::<Error<'_>>(Partial::new("\"abc\"")),
+ string::<Error<'_>>.parse_peek(Partial::new("\"abc\"")),
Ok((Partial::new(""), "abc".to_string()))
);
assert_eq!(
- string::<Error<'_>>(Partial::new(
+ string::<Error<'_>>.parse_peek(Partial::new(
"\"abc\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0001\\u2014\u{2014}def\""
)),
Ok((
@@ -233,17 +231,29 @@ mod test {
)),
);
assert_eq!(
- string::<Error<'_>>(Partial::new("\"\\uD83D\\uDE10\"")),
+ string::<Error<'_>>.parse_peek(Partial::new("\"\\uD83D\\uDE10\"")),
Ok((Partial::new(""), "😐".to_string()))
);
- assert!(string::<Error<'_>>(Partial::new("\"")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"abc")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"\\\"")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"\\u123\"")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"\\uD800\"")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"\\uD800\\uD800\"")).is_err());
- assert!(string::<Error<'_>>(Partial::new("\"\\uDC00\"")).is_err());
+ assert!(string::<Error<'_>>.parse_peek(Partial::new("\"")).is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"abc"))
+ .is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"\\\""))
+ .is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"\\u123\""))
+ .is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"\\uD800\""))
+ .is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"\\uD800\\uD800\""))
+ .is_err());
+ assert!(string::<Error<'_>>
+ .parse_peek(Partial::new("\"\\uDC00\""))
+ .is_err());
}
#[test]
@@ -263,7 +273,7 @@ mod test {
);
assert_eq!(
- ndjson::<Error<'_>>(Partial::new(input)),
+ ndjson::<Error<'_>>.parse_peek(Partial::new(input)),
Ok((Partial::new(""), Some(expected)))
);
}
@@ -278,7 +288,7 @@ mod test {
let expected = Array(vec![Num(42.0), Str("x".to_string())]);
assert_eq!(
- ndjson::<Error<'_>>(Partial::new(input)),
+ ndjson::<Error<'_>>.parse_peek(Partial::new(input)),
Ok((Partial::new(""), Some(expected)))
);
}
@@ -291,7 +301,7 @@ mod test {
"#;
assert_eq!(
- ndjson::<Error<'_>>(Partial::new(input)),
+ ndjson::<Error<'_>>.parse_peek(Partial::new(input)),
Ok((
Partial::new(""),
Some(Object(
diff --git a/vendor/winnow/examples/s_expression/parser.rs b/vendor/winnow/examples/s_expression/parser.rs
index 9a1686e1c..919dcf430 100644
--- a/vendor/winnow/examples/s_expression/parser.rs
+++ b/vendor/winnow/examples/s_expression/parser.rs
@@ -8,17 +8,19 @@ use winnow::{
combinator::repeat,
combinator::{cut_err, opt},
combinator::{delimited, preceded, terminated},
- error::VerboseError,
+ error::ContextError,
+ error::StrContext,
+ prelude::*,
token::one_of,
- IResult, Parser,
};
/// We start with a top-level function to tie everything together, letting
/// us call eval on a string directly
pub fn eval_from_str(src: &str) -> Result<Expr, String> {
- parse_expr(src)
- .map_err(|e: winnow::error::ErrMode<VerboseError<&str>>| format!("{:#?}", e))
- .and_then(|(_, exp)| eval_expression(exp).ok_or_else(|| "Eval failed".to_string()))
+ parse_expr
+ .parse(src)
+ .map_err(|e| e.to_string())
+ .and_then(|exp| eval_expression(exp).ok_or_else(|| "Eval failed".to_string()))
}
/// For parsing, we start by defining the types that define the shape of data that we want.
@@ -68,7 +70,7 @@ pub enum BuiltIn {
}
/// With types defined, we move onto the top-level expression parser!
-fn parse_expr(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
+fn parse_expr(i: &mut &'_ str) -> PResult<Expr> {
preceded(
multispace0,
alt((parse_constant, parse_application, parse_if, parse_quote)),
@@ -77,13 +79,13 @@ fn parse_expr(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
}
/// We then add the Expr layer on top
-fn parse_constant(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
+fn parse_constant(i: &mut &'_ str) -> PResult<Expr> {
parse_atom.map(Expr::Constant).parse_next(i)
}
/// Now we take all these simple parsers and connect them.
/// We can now parse half of our language!
-fn parse_atom(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
+fn parse_atom(i: &mut &'_ str) -> PResult<Atom> {
alt((
parse_num,
parse_bool,
@@ -95,7 +97,7 @@ fn parse_atom(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
/// Next up is number parsing. We're keeping it simple here by accepting any number (> 1)
/// of digits but ending the program if it doesn't fit into an i32.
-fn parse_num(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
+fn parse_num(i: &mut &'_ str) -> PResult<Atom> {
alt((
digit1.try_map(|digit_str: &str| digit_str.parse::<i32>().map(Atom::Num)),
preceded("-", digit1).map(|digit_str: &str| Atom::Num(-digit_str.parse::<i32>().unwrap())),
@@ -104,7 +106,7 @@ fn parse_num(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
}
/// Our boolean values are also constant, so we can do it the same way
-fn parse_bool(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
+fn parse_bool(i: &mut &'_ str) -> PResult<Atom> {
alt((
"#t".map(|_| Atom::Boolean(true)),
"#f".map(|_| Atom::Boolean(false)),
@@ -112,7 +114,7 @@ fn parse_bool(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
.parse_next(i)
}
-fn parse_builtin(i: &str) -> IResult<&str, BuiltIn, VerboseError<&str>> {
+fn parse_builtin(i: &mut &'_ str) -> PResult<BuiltIn> {
// alt gives us the result of first parser that succeeds, of the series of
// parsers we give it
alt((
@@ -126,23 +128,20 @@ fn parse_builtin(i: &str) -> IResult<&str, BuiltIn, VerboseError<&str>> {
/// Continuing the trend of starting from the simplest piece and building up,
/// we start by creating a parser for the built-in operator functions.
-fn parse_builtin_op(i: &str) -> IResult<&str, BuiltIn, VerboseError<&str>> {
+fn parse_builtin_op(i: &mut &'_ str) -> PResult<BuiltIn> {
// one_of matches one of the characters we give it
- let (i, t) = one_of("+-*/=").parse_next(i)?;
+ let t = one_of(['+', '-', '*', '/', '=']).parse_next(i)?;
// because we are matching single character tokens, we can do the matching logic
// on the returned value
- Ok((
- i,
- match t {
- '+' => BuiltIn::Plus,
- '-' => BuiltIn::Minus,
- '*' => BuiltIn::Times,
- '/' => BuiltIn::Divide,
- '=' => BuiltIn::Equal,
- _ => unreachable!(),
- },
- ))
+ Ok(match t {
+ '+' => BuiltIn::Plus,
+ '-' => BuiltIn::Minus,
+ '*' => BuiltIn::Times,
+ '/' => BuiltIn::Divide,
+ '=' => BuiltIn::Equal,
+ _ => unreachable!(),
+ })
}
/// The next easiest thing to parse are keywords.
@@ -151,9 +150,9 @@ fn parse_builtin_op(i: &str) -> IResult<&str, BuiltIn, VerboseError<&str>> {
///
/// Put plainly: `preceded(":", cut_err(alpha1))` means that once we see the `:`
/// character, we have to see one or more alphabetic characters or the input is invalid.
-fn parse_keyword(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
+fn parse_keyword(i: &mut &'_ str) -> PResult<Atom> {
preceded(":", cut_err(alpha1))
- .context("keyword")
+ .context(StrContext::Label("keyword"))
.map(|sym_str: &str| Atom::Keyword(sym_str.to_string()))
.parse_next(i)
}
@@ -167,7 +166,7 @@ fn parse_keyword(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
///
/// tuples are themselves a parser, used to sequence parsers together, so we can translate this
/// directly and then map over it to transform the output into an `Expr::Application`
-fn parse_application(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
+fn parse_application(i: &mut &'_ str) -> PResult<Expr> {
let application_inner = (parse_expr, repeat(0.., parse_expr))
.map(|(head, tail)| Expr::Application(Box::new(head), tail));
// finally, we wrap it in an s-expression
@@ -180,7 +179,7 @@ fn parse_application(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
///
/// In fact, we define our parser as if `Expr::If` was defined with an Option in it,
/// we have the `opt` combinator which fits very nicely here.
-fn parse_if(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
+fn parse_if(i: &mut &'_ str) -> PResult<Expr> {
let if_inner = preceded(
// here to avoid ambiguity with other names starting with `if`, if we added
// variables to our language, we say that if must be terminated by at least
@@ -199,7 +198,7 @@ fn parse_if(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
Expr::If(Box::new(pred), Box::new(true_branch))
}
})
- .context("if expression");
+ .context(StrContext::Label("if expression"));
s_exp(if_inner).parse_next(i)
}
@@ -208,12 +207,12 @@ fn parse_if(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
/// This example doesn't have the symbol atom, but by adding variables and changing
/// the definition of quote to not always be around an S-expression, we'd get them
/// naturally.
-fn parse_quote(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
+fn parse_quote(i: &mut &'_ str) -> PResult<Expr> {
// this should look very straight-forward after all we've done:
// we find the `'` (quote) character, use cut_err to say that we're unambiguously
// looking for an s-expression of 0 or more expressions, and then parse them
preceded("'", cut_err(s_exp(repeat(0.., parse_expr))))
- .context("quote")
+ .context(StrContext::Label("quote"))
.map(Expr::Quote)
.parse_next(i)
}
@@ -225,14 +224,14 @@ fn parse_quote(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
//.parse_next/
/// Unlike the previous functions, this function doesn't take or consume input, instead it
/// takes a parsing function and returns a new parsing function.
-fn s_exp<'a, O1, F>(inner: F) -> impl Parser<&'a str, O1, VerboseError<&'a str>>
+fn s_exp<'a, O1, F>(inner: F) -> impl Parser<&'a str, O1, ContextError>
where
- F: Parser<&'a str, O1, VerboseError<&'a str>>,
+ F: Parser<&'a str, O1, ContextError>,
{
delimited(
'(',
preceded(multispace0, inner),
- cut_err(preceded(multispace0, ')')).context("closing paren"),
+ cut_err(preceded(multispace0, ')')).context(StrContext::Label("closing paren")),
)
}
diff --git a/vendor/winnow/examples/string/parser.rs b/vendor/winnow/examples/string/parser.rs
index dcd87f272..6b6345807 100644
--- a/vendor/winnow/examples/string/parser.rs
+++ b/vendor/winnow/examples/string/parser.rs
@@ -13,15 +13,15 @@ use winnow::ascii::multispace1;
use winnow::combinator::alt;
use winnow::combinator::fold_repeat;
use winnow::combinator::{delimited, preceded};
-use winnow::error::{FromExternalError, ParseError};
+use winnow::error::{FromExternalError, ParserError};
use winnow::prelude::*;
use winnow::token::{take_till1, take_while};
/// Parse a string. Use a loop of `parse_fragment` and push all of the fragments
/// into an output string.
-pub fn parse_string<'a, E>(input: &'a str) -> IResult<&'a str, String, E>
+pub fn parse_string<'a, E>(input: &mut &'a str) -> PResult<String, E>
where
- E: ParseError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>,
+ E: ParserError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>,
{
// fold_repeat is the equivalent of iterator::fold. It runs a parser in a loop,
// and for each output value, calls a folding function on each output value.
@@ -62,9 +62,9 @@ enum StringFragment<'a> {
/// Combine `parse_literal`, `parse_escaped_whitespace`, and `parse_escaped_char`
/// into a `StringFragment`.
-fn parse_fragment<'a, E>(input: &'a str) -> IResult<&'a str, StringFragment<'a>, E>
+fn parse_fragment<'a, E>(input: &mut &'a str) -> PResult<StringFragment<'a>, E>
where
- E: ParseError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>,
+ E: ParserError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>,
{
alt((
// The `map` combinator runs a parser, then applies a function to the output
@@ -77,10 +77,10 @@ where
}
/// Parse a non-empty block of text that doesn't include \ or "
-fn parse_literal<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str, E> {
+fn parse_literal<'a, E: ParserError<&'a str>>(input: &mut &'a str) -> PResult<&'a str, E> {
// `take_till1` parses a string of 0 or more characters that aren't one of the
// given characters.
- let not_quote_slash = take_till1("\"\\");
+ let not_quote_slash = take_till1(['"', '\\']);
// `verify` runs a parser, then runs a verification function on the output of
// the parser. The verification function accepts the output only if it
@@ -96,9 +96,9 @@ fn parse_literal<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str,
// then combine them into larger parsers.
/// Parse an escaped character: \n, \t, \r, \u{00AC}, etc.
-fn parse_escaped_char<'a, E>(input: &'a str) -> IResult<&'a str, char, E>
+fn parse_escaped_char<'a, E>(input: &mut &'a str) -> PResult<char, E>
where
- E: ParseError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>,
+ E: ParserError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>,
{
preceded(
'\\',
@@ -126,9 +126,9 @@ where
/// Parse a unicode sequence, of the form u{XXXX}, where XXXX is 1 to 6
/// hexadecimal numerals. We will combine this later with `parse_escaped_char`
/// to parse sequences like \u{00AC}.
-fn parse_unicode<'a, E>(input: &'a str) -> IResult<&'a str, char, E>
+fn parse_unicode<'a, E>(input: &mut &'a str) -> PResult<char, E>
where
- E: ParseError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>,
+ E: ParserError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>,
{
// `take_while` parses between `m` and `n` bytes (inclusive) that match
// a predicate. `parse_hex` here parses between 1 and 6 hexadecimal numerals.
@@ -158,8 +158,8 @@ where
/// Parse a backslash, followed by any amount of whitespace. This is used later
/// to discard any escaped whitespace.
-fn parse_escaped_whitespace<'a, E: ParseError<&'a str>>(
- input: &'a str,
-) -> IResult<&'a str, &'a str, E> {
+fn parse_escaped_whitespace<'a, E: ParserError<&'a str>>(
+ input: &mut &'a str,
+) -> PResult<&'a str, E> {
preceded('\\', multispace1).parse_next(input)
}
diff --git a/vendor/winnow/src/_topic/error.rs b/vendor/winnow/src/_topic/error.rs
index abf2f8dbb..c5374b4a8 100644
--- a/vendor/winnow/src/_topic/error.rs
+++ b/vendor/winnow/src/_topic/error.rs
@@ -1,9 +1,9 @@
//! # Custom Errors
//!
-//! The most basic error type is [`ParseError`][crate::error::ParseError]
+//! The most basic error type is [`ParserError`][crate::error::ParserError]
//!
//! Optional traits include:
-//! - [`ContextError`][crate::error::ContextError]
+//! - [`AddContext`][crate::error::AddContext]
//! - [`FromExternalError`][crate::error::FromExternalError]
//!
//! # Example
diff --git a/vendor/winnow/src/_topic/language.rs b/vendor/winnow/src/_topic/language.rs
index 245bab4c7..0cebc99b7 100644
--- a/vendor/winnow/src/_topic/language.rs
+++ b/vendor/winnow/src/_topic/language.rs
@@ -27,14 +27,14 @@
//! ```rust
//! use winnow::prelude::*;
//! use winnow::{
-//! error::ParseError,
+//! error::ParserError,
//! combinator::delimited,
//! ascii::multispace0,
//! };
//!
//! /// A combinator that takes a parser `inner` and produces a parser that also consumes both leading and
//! /// trailing whitespace, returning the output of `inner`.
-//! fn ws<'a, F, O, E: ParseError<&'a str>>(inner: F) -> impl Parser<&'a str, O, E>
+//! fn ws<'a, F, O, E: ParserError<&'a str>>(inner: F) -> impl Parser<&'a str, O, E>
//! where
//! F: Parser<&'a str, O, E>,
//! {
@@ -61,13 +61,13 @@
//! ```rust
//! use winnow::prelude::*;
//! use winnow::{
-//! error::ParseError,
+//! error::ParserError,
//! token::take_till1,
//! };
//!
-//! pub fn peol_comment<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (), E>
+//! pub fn peol_comment<'a, E: ParserError<&'a str>>(i: &mut &'a str) -> PResult<(), E>
//! {
-//! ('%', take_till1("\n\r"))
+//! ('%', take_till1(['\n', '\r']))
//! .void() // Output is thrown away.
//! .parse_next(i)
//! }
@@ -81,11 +81,11 @@
//! ```rust
//! use winnow::prelude::*;
//! use winnow::{
-//! error::ParseError,
+//! error::ParserError,
//! token::{tag, take_until0},
//! };
//!
-//! pub fn pinline_comment<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (), E> {
+//! pub fn pinline_comment<'a, E: ParserError<&'a str>>(i: &mut &'a str) -> PResult<(), E> {
//! (
//! "(*",
//! take_until0("*)"),
@@ -111,7 +111,7 @@
//! token::one_of,
//! };
//!
-//! pub fn identifier(input: &str) -> IResult<&str, &str> {
+//! pub fn identifier<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! (
//! one_of(|c: char| c.is_alpha() || c == '_'),
//! take_while(0.., |c: char| c.is_alphanum() || c == '_')
@@ -136,6 +136,8 @@
#![doc = include_str!("../../examples/string/parser.rs")]
//! ```
//!
+//! See also [`escaped`] and [`escaped_transform`].
+//!
//! ### Integers
//!
//! The following recipes all return string slices rather than integer values. How to obtain an
@@ -160,11 +162,11 @@
//! token::tag,
//! };
//!
-//! fn hexadecimal(input: &str) -> IResult<&str, &str> { // <'a, E: ParseError<&'a str>>
+//! fn hexadecimal<'s>(input: &mut &'s str) -> PResult<&'s str> { // <'a, E: ParserError<&'a str>>
//! preceded(
//! alt(("0x", "0X")),
//! repeat(1..,
-//! terminated(one_of("0123456789abcdefABCDEF"), repeat(0.., '_').map(|()| ()))
+//! terminated(one_of(('0'..='9', 'a'..='f', 'A'..='F')), repeat(0.., '_').map(|()| ()))
//! ).map(|()| ()).recognize()
//! ).parse_next(input)
//! }
@@ -182,11 +184,11 @@
//! token::tag,
//! };
//!
-//! fn hexadecimal_value(input: &str) -> IResult<&str, i64> {
+//! fn hexadecimal_value(input: &mut &str) -> PResult<i64> {
//! preceded(
//! alt(("0x", "0X")),
//! repeat(1..,
-//! terminated(one_of("0123456789abcdefABCDEF"), repeat(0.., '_').map(|()| ()))
+//! terminated(one_of(('0'..='9', 'a'..='f', 'A'..='F')), repeat(0.., '_').map(|()| ()))
//! ).map(|()| ()).recognize()
//! ).try_map(
//! |out: &str| i64::from_str_radix(&str::replace(&out, "_", ""), 16)
@@ -194,6 +196,8 @@
//! }
//! ```
//!
+//! See also [`hex_uint`]
+//!
//! #### Octal
//!
//! ```rust
@@ -206,11 +210,11 @@
//! token::tag,
//! };
//!
-//! fn octal(input: &str) -> IResult<&str, &str> {
+//! fn octal<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! preceded(
//! alt(("0o", "0O")),
//! repeat(1..,
-//! terminated(one_of("01234567"), repeat(0.., '_').map(|()| ()))
+//! terminated(one_of('0'..='7'), repeat(0.., '_').map(|()| ()))
//! ).map(|()| ()).recognize()
//! ).parse_next(input)
//! }
@@ -228,11 +232,11 @@
//! token::tag,
//! };
//!
-//! fn binary(input: &str) -> IResult<&str, &str> {
+//! fn binary<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! preceded(
//! alt(("0b", "0B")),
//! repeat(1..,
-//! terminated(one_of("01"), repeat(0.., '_').map(|()| ()))
+//! terminated(one_of('0'..='1'), repeat(0.., '_').map(|()| ()))
//! ).map(|()| ()).recognize()
//! ).parse_next(input)
//! }
@@ -243,21 +247,22 @@
//! ```rust
//! use winnow::prelude::*;
//! use winnow::{
-//! IResult,
//! combinator::{repeat},
//! combinator::terminated,
//! token::one_of,
//! };
//!
-//! fn decimal(input: &str) -> IResult<&str, &str> {
+//! fn decimal<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! repeat(1..,
-//! terminated(one_of("0123456789"), repeat(0.., '_').map(|()| ()))
+//! terminated(one_of('0'..='9'), repeat(0.., '_').map(|()| ()))
//! ).map(|()| ())
//! .recognize()
//! .parse_next(input)
//! }
//! ```
//!
+//! See also [`dec_uint`] and [`dec_int`]
+//!
//! ### Floating Point Numbers
//!
//! The following is adapted from [the Python parser by Valentin Lorentz](https://github.com/ProgVal/rust-python-parser/blob/master/src/numbers.rs).
@@ -272,15 +277,15 @@
//! token::one_of,
//! };
//!
-//! fn float(input: &str) -> IResult<&str, &str> {
+//! fn float<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! alt((
//! // Case one: .42
//! (
//! '.',
//! decimal,
//! opt((
-//! one_of("eE"),
-//! opt(one_of("+-")),
+//! one_of(['e', 'E']),
+//! opt(one_of(['+', '-'])),
//! decimal
//! ))
//! ).recognize()
@@ -291,8 +296,8 @@
//! '.',
//! decimal,
//! )),
-//! one_of("eE"),
-//! opt(one_of("+-")),
+//! one_of(['e', 'E']),
+//! opt(one_of(['+', '-'])),
//! decimal
//! ).recognize()
//! , // Case three: 42. and 42.42
@@ -304,12 +309,22 @@
//! )).parse_next(input)
//! }
//!
-//! fn decimal(input: &str) -> IResult<&str, &str> {
+//! fn decimal<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! repeat(1..,
-//! terminated(one_of("0123456789"), repeat(0.., '_').map(|()| ()))
+//! terminated(one_of('0'..='9'), repeat(0.., '_').map(|()| ()))
//! ).
//! map(|()| ())
//! .recognize()
//! .parse_next(input)
//! }
//! ```
+//!
+//! See also [`float`]
+
+#![allow(unused_imports)]
+use crate::ascii::dec_int;
+use crate::ascii::dec_uint;
+use crate::ascii::escaped;
+use crate::ascii::escaped_transform;
+use crate::ascii::float;
+use crate::ascii::hex_uint;
diff --git a/vendor/winnow/src/_topic/performance.rs b/vendor/winnow/src/_topic/performance.rs
index fac12da4c..5bda958ee 100644
--- a/vendor/winnow/src/_topic/performance.rs
+++ b/vendor/winnow/src/_topic/performance.rs
@@ -6,7 +6,7 @@
//!
//! Tips
//! - When enough cases of an [`alt`] have unique prefixes, prefer [`dispatch`]
-//! - When parsing text, try to parse is as bytes (`u8`) rather than `char`s ([`BStr`] can make
+//! - When parsing text, try to parse as bytes (`u8`) rather than `char`s ([`BStr`] can make
//! debugging easier)
//! - Find simplified subsets of the grammar to parse, falling back to the full grammar when it
//! doesn't work. For example, when parsing json strings, parse them without support for escapes,
@@ -14,7 +14,7 @@
//! - Watch for large return types. A surprising place these can show up is when chaining parsers
//! with a tuple.
//!
-//! ## Built-time Performance
+//! ## Build-time Performance
//!
//! Returning complex types as `impl Trait` can negatively impact build times. This can hit in
//! surprising cases like:
@@ -24,7 +24,7 @@
//! # where
//! # I: winnow::stream::Stream<Token=O>,
//! # I: winnow::stream::StreamIsPartial,
-//! # E: winnow::error::ParseError<I>,
+//! # E: winnow::error::ParserError<I>,
//! {
//! // ...some chained combinators...
//! # winnow::token::any
@@ -38,9 +38,9 @@
//! # where
//! # I: winnow::stream::Stream<Token=O>,
//! # I: winnow::stream::StreamIsPartial,
-//! # E: winnow::error::ParseError<I>,
+//! # E: winnow::error::ParserError<I>,
//! {
-//! move |input: I| {
+//! move |input: &mut I| {
//! // ...some chained combinators...
//! # winnow::token::any
//! .parse_next(input)
diff --git a/vendor/winnow/src/_topic/stream.rs b/vendor/winnow/src/_topic/stream.rs
index 7455e185b..4f94a94b9 100644
--- a/vendor/winnow/src/_topic/stream.rs
+++ b/vendor/winnow/src/_topic/stream.rs
@@ -13,14 +13,14 @@
//! ## Implementing a custom stream
//!
//! Let's assume we have an input type we'll call `MyStream`. `MyStream` is a sequence of `MyItem` type.
-//! The goal is to define parsers with this signature: `MyStream -> IResult<MyStream, Output>`.
+//! The goal is to define parsers with this signature: `&mut MyStream -> PResult<Output>`.
//!
//! ```rust
//! # use winnow::prelude::*;
//! # use winnow::token::tag;
//! # type MyStream<'i> = &'i str;
//! # type Output<'i> = &'i str;
-//! fn parser(i: MyStream<'_>) -> IResult<MyStream<'_>, Output<'_>> {
+//! fn parser<'s>(i: &mut MyStream<'s>) -> PResult<Output<'s>> {
//! "test".parse_next(i)
//! }
//! ```
diff --git a/vendor/winnow/src/_tutorial/chapter_1.rs b/vendor/winnow/src/_tutorial/chapter_1.rs
index d6a45c8b7..1bf146bec 100644
--- a/vendor/winnow/src/_tutorial/chapter_1.rs
+++ b/vendor/winnow/src/_tutorial/chapter_1.rs
@@ -9,51 +9,47 @@
//! - `Ok` indicates the parser successfully found what it was looking for; or
//! - `Err` indicates the parser could not find what it was looking for.
//!
-//! Parsers do more than just return a binary "success"/"failure" code. If
-//! the parser was successful, then it will return a tuple where the first field
-//! will contain everything the parser did not process. The second will contain
-//! everything the parser processed. The idea is that a parser can happily parse the first
-//! *part* of an input, without being able to parse the whole thing.
+//! Parsers do more than just return a binary "success"/"failure" code.
+//! On success, the parser will return the processed data. The input will be left pointing to
+//! data that still needs processing
//!
//! If the parser failed, then there are multiple errors that could be returned.
//! For simplicity, however, in the next chapters we will leave these unexplored.
//!
//! ```text
-//! ┌─► Ok(
-//! │ what the parser didn't touch,
-//! │ what matched the parser
-//! │ )
+//! ┌─► Ok(what matched the parser)
//! ┌─────────┐ │
//! my input───►│my parser├──►either──┤
//! └─────────┘ └─► Err(...)
//! ```
//!
//!
-//! To represent this model of the world, winnow uses the [`IResult<I, O>`] type.
-//! The `Ok` variant has a tuple of `(remainder: I, output: O)`;
+//! To represent this model of the world, winnow uses the [`PResult<O>`] type.
+//! The `Ok` variant has `output: O`;
//! whereas the `Err` variant stores an error.
//!
//! You can import that from:
//!
//! ```rust
-//! use winnow::IResult;
+//! use winnow::PResult;
//! ```
//!
+//! To combine parsers, we need a common way to refer to them which is where the [`Parser<I, O, E>`]
+//! trait comes in with [`Parser::parse_next`] being the primary way to drive
+//! parsing forward.
+//!
//! You'll note that `I` and `O` are parameterized -- while most of the examples in this book
//! will be with `&str` (i.e. parsing a string); they do not have to be strings; nor do they
//! have to be the same type (consider the simple example where `I = &str`, and `O = u64` -- this
//! parses a string into an unsigned integer.)
//!
-//! To combine parsers, we need a common way to refer to them which is where the [`Parser`]
-//! trait comes in with [`Parser::parse_next`] being the primary way to drive
-//! parsing forward.
//!
//! # Let's write our first parser!
//!
//! The simplest parser we can write is one which successfully does nothing.
//!
//! To make it easier to implement a [`Parser`], the trait is implemented for
-//! functions of the form `Fn(I) -> IResult<I, O>`.
+//! functions of the form `Fn(&mut I) -> PResult<O>`.
//!
//! This parser function should take in a `&str`:
//!
@@ -62,27 +58,27 @@
//! - Since it doesn't parse anything, it also should just return an empty string.
//!
//! ```rust
-//! use winnow::IResult;
+//! use winnow::PResult;
//! use winnow::Parser;
//!
-//! pub fn do_nothing_parser(input: &str) -> IResult<&str, &str> {
-//! Ok((input, ""))
+//! pub fn do_nothing_parser<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! Ok("")
//! }
//!
//! fn main() {
-//! let input = "0x1a2b Hello";
+//! let mut input = "0x1a2b Hello";
//!
-//! let (remainder, output) = do_nothing_parser.parse_next(input).unwrap();
+//! let output = do_nothing_parser.parse_next(&mut input).unwrap();
//! // Same as:
-//! // let (remainder, output) = do_nothing_parser(input).unwrap();
+//! // let output = do_nothing_parser(&mut input).unwrap();
//!
-//! assert_eq!(remainder, "0x1a2b Hello");
+//! assert_eq!(input, "0x1a2b Hello");
//! assert_eq!(output, "");
//! }
//! ```
#![allow(unused_imports)]
-use crate::IResult;
+use crate::PResult;
use crate::Parser;
pub use super::chapter_0 as previous;
diff --git a/vendor/winnow/src/_tutorial/chapter_2.rs b/vendor/winnow/src/_tutorial/chapter_2.rs
index 49b61f3f4..b0daedc74 100644
--- a/vendor/winnow/src/_tutorial/chapter_2.rs
+++ b/vendor/winnow/src/_tutorial/chapter_2.rs
@@ -4,54 +4,139 @@
//!
//! ## Tokens
//!
-//! Matching a single token literal is common enough that `Parser` is implemented for
-//! `char`.
-//!
+//! [`Stream`] provides some core operations to help with parsing. For example, to process a
+//! single token, you can do:
//! ```rust
//! # use winnow::Parser;
-//! # use winnow::IResult;
-//! #
-//! fn parse_prefix(input: &str) -> IResult<&str, char> {
-//! '0'.parse_next(input)
+//! # use winnow::PResult;
+//! use winnow::stream::Stream;
+//! use winnow::error::ParserError;
+//! use winnow::error::ErrorKind;
+//! use winnow::error::ErrMode;
+//!
+//! fn parse_prefix(input: &mut &str) -> PResult<char> {
+//! let c = input.next_token().ok_or_else(|| {
+//! ErrMode::from_error_kind(input, ErrorKind::Token)
+//! })?;
+//! if c != '0' {
+//! return Err(ErrMode::from_error_kind(input, ErrorKind::Verify));
+//! }
+//! Ok(c)
//! }
//!
//! fn main() {
-//! let input = "0x1a2b Hello";
+//! let mut input = "0x1a2b Hello";
//!
-//! let (remainder, output) = parse_prefix.parse_next(input).unwrap();
+//! let output = parse_prefix.parse_next(&mut input).unwrap();
//!
-//! assert_eq!(remainder, "x1a2b Hello");
+//! assert_eq!(input, "x1a2b Hello");
//! assert_eq!(output, '0');
//!
-//! assert!(parse_prefix("d").is_err());
+//! assert!(parse_prefix.parse_next(&mut "d").is_err());
//! }
//! ```
//!
-//! ## Tags
+//! [`any`] and [`Parser::verify`] are [`Parser`] building blocks on top of [`Stream`]:
+//! ```rust
+//! # use winnow::PResult;
+//! use winnow::Parser;
+//! use winnow::token::any;
//!
-//! One of the most frequent way of matching a token is when they are combined into a string.
-//! Again, this is common enough that `Parser` is implemented for `&str`:
+//! fn parse_prefix(input: &mut &str) -> PResult<char> {
+//! any.verify(|c| *c == '0').parse_next(input)
+//! }
+//! #
+//! # fn main() {
+//! # let mut input = "0x1a2b Hello";
+//! #
+//! # let output = parse_prefix.parse_next(&mut input).unwrap();
+//! #
+//! # assert_eq!(input, "x1a2b Hello");
+//! # assert_eq!(output, '0');
+//! #
+//! # assert!(parse_prefix.parse_next(&mut "d").is_err());
+//! # }
+//! ```
+//!
+//! Matching a single token literal is common enough that [`Parser`] is implemented for
+//! `char`.
//!
//! ```rust
-//! # use winnow::Parser;
-//! # use winnow::IResult;
+//! # use winnow::PResult;
+//! use winnow::Parser;
+//!
+//! fn parse_prefix(input: &mut &str) -> PResult<char> {
+//! '0'.parse_next(input)
+//! }
//! #
-//! fn parse_prefix(input: &str) -> IResult<&str, &str> {
-//! "0x".parse_next(input)
+//! # fn main() {
+//! # let mut input = "0x1a2b Hello";
+//! #
+//! # let output = parse_prefix.parse_next(&mut input).unwrap();
+//! #
+//! # assert_eq!(input, "x1a2b Hello");
+//! # assert_eq!(output, '0');
+//! #
+//! # assert!(parse_prefix.parse_next(&mut "d").is_err());
+//! # }
+//! ```
+//!
+//! ## Tags
+//!
+//! [`Stream`] also supports processing slices of tokens:
+//! ```rust
+//! # use winnow::Parser;
+//! # use winnow::PResult;
+//! use winnow::stream::Stream;
+//! use winnow::error::ParserError;
+//! use winnow::error::ErrorKind;
+//! use winnow::error::ErrMode;
+//!
+//! fn parse_prefix<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! let expected = "0x";
+//! if input.len() < expected.len() {
+//! return Err(ErrMode::from_error_kind(input, ErrorKind::Slice));
+//! }
+//! let actual = input.next_slice(expected.len());
+//! if actual != expected {
+//! return Err(ErrMode::from_error_kind(input, ErrorKind::Verify));
+//! }
+//! Ok(actual)
//! }
//!
//! fn main() {
-//! let input = "0x1a2b Hello";
+//! let mut input = "0x1a2b Hello";
//!
-//! let (remainder, output) = parse_prefix.parse_next(input).unwrap();
-//! assert_eq!(remainder, "1a2b Hello");
+//! let output = parse_prefix.parse_next(&mut input).unwrap();
+//! assert_eq!(input, "1a2b Hello");
//! assert_eq!(output, "0x");
//!
-//! assert!(parse_prefix("0o123").is_err());
+//! assert!(parse_prefix.parse_next(&mut "0o123").is_err());
//! }
//! ```
//!
-//! In `winnow`, we call this type of parser a [`tag`].
+//! Again, matching a literal is common enough that [`Parser`] is implemented for `&str`:
+//! ```rust
+//! # use winnow::PResult;
+//! use winnow::Parser;
+//!
+//! fn parse_prefix<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! "0x".parse_next(input)
+//! }
+//! #
+//! # fn main() {
+//! # let mut input = "0x1a2b Hello";
+//! #
+//! # let output = parse_prefix.parse_next(&mut input).unwrap();
+//! # assert_eq!(input, "1a2b Hello");
+//! # assert_eq!(output, "0x");
+//! #
+//! # assert!(parse_prefix.parse_next(&mut "0o123").is_err());
+//! # }
+//! ```
+//!
+//! In `winnow`, we call this type of parser a [`tag`]. See [`token`] for additional individual
+//! and token-slice parsers.
//!
//! ## Character Classes
//!
@@ -60,21 +145,21 @@
//!
//! ```rust
//! # use winnow::Parser;
-//! # use winnow::IResult;
+//! # use winnow::PResult;
//! use winnow::token::one_of;
//!
-//! fn parse_digits(input: &str) -> IResult<&str, char> {
-//! one_of("0123456789abcdefgABCDEFG").parse_next(input)
+//! fn parse_digits(input: &mut &str) -> PResult<char> {
+//! one_of(('0'..='9', 'a'..='f', 'A'..='F')).parse_next(input)
//! }
//!
//! fn main() {
-//! let input = "1a2b Hello";
+//! let mut input = "1a2b Hello";
//!
-//! let (remainder, output) = parse_digits.parse_next(input).unwrap();
-//! assert_eq!(remainder, "a2b Hello");
+//! let output = parse_digits.parse_next(&mut input).unwrap();
+//! assert_eq!(input, "a2b Hello");
//! assert_eq!(output, '1');
//!
-//! assert!(parse_digits("Z").is_err());
+//! assert!(parse_digits.parse_next(&mut "Z").is_err());
//! }
//! ```
//!
@@ -82,10 +167,10 @@
//! > Let's look at it more closely as its used above (resolving all generic parameters):
//! > ```rust
//! > # use winnow::prelude::*;
-//! > # use winnow::error::Error;
+//! > # use winnow::error::InputError;
//! > pub fn one_of<'i>(
-//! > list: &'static str
-//! > ) -> impl Parser<&'i str, char, Error<&'i str>> {
+//! > list: &'static [char]
+//! > ) -> impl Parser<&'i str, char, InputError<&'i str>> {
//! > // ...
//! > # winnow::token::one_of(list)
//! > }
@@ -93,7 +178,7 @@
//! > If you have not programmed in a language where functions are values, the type signature of the
//! > [`one_of`] function might be a surprise.
//! > The function [`one_of`] *returns a function*. The function it returns is a
-//! > `Parser`, taking a `&str` and returning an `IResult`. This is a common pattern in winnow for
+//! > `Parser`, taking a `&str` and returning an `PResult`. This is a common pattern in winnow for
//! > configurable or stateful parsers.
//!
//! Some of character classes are common enough that a named parser is provided, like with:
@@ -104,48 +189,54 @@
//! You can then capture sequences of these characters with parsers like [`take_while`].
//! ```rust
//! # use winnow::Parser;
-//! # use winnow::IResult;
+//! # use winnow::PResult;
//! use winnow::token::take_while;
//!
-//! fn parse_digits(input: &str) -> IResult<&str, &str> {
-//! take_while(1.., "0123456789abcdefgABCDEFG").parse_next(input)
+//! fn parse_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! take_while(1.., ('0'..='9', 'a'..='f', 'A'..='F')).parse_next(input)
//! }
//!
//! fn main() {
-//! let input = "1a2b Hello";
+//! let mut input = "1a2b Hello";
//!
-//! let (remainder, output) = parse_digits.parse_next(input).unwrap();
-//! assert_eq!(remainder, " Hello");
+//! let output = parse_digits.parse_next(&mut input).unwrap();
+//! assert_eq!(input, " Hello");
//! assert_eq!(output, "1a2b");
//!
-//! assert!(parse_digits("Z").is_err());
+//! assert!(parse_digits.parse_next(&mut "Z").is_err());
//! }
//! ```
//!
//! We could simplify this further with by using one of the built-in character classes, [`hex_digit1`]:
//! ```rust
//! # use winnow::Parser;
-//! # use winnow::IResult;
+//! # use winnow::PResult;
//! use winnow::ascii::hex_digit1;
//!
-//! fn parse_digits(input: &str) -> IResult<&str, &str> {
+//! fn parse_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! hex_digit1.parse_next(input)
//! }
//!
//! fn main() {
-//! let input = "1a2b Hello";
+//! let mut input = "1a2b Hello";
//!
-//! let (remainder, output) = parse_digits.parse_next(input).unwrap();
-//! assert_eq!(remainder, " Hello");
+//! let output = parse_digits.parse_next(&mut input).unwrap();
+//! assert_eq!(input, " Hello");
//! assert_eq!(output, "1a2b");
//!
-//! assert!(parse_digits("Z").is_err());
+//! assert!(parse_digits.parse_next(&mut "Z").is_err());
//! }
//! ```
+//!
+//! See [`ascii`] for more text-based parsers.
#![allow(unused_imports)]
+use crate::ascii;
use crate::ascii::hex_digit1;
use crate::stream::ContainsToken;
+use crate::stream::Stream;
+use crate::token;
+use crate::token::any;
use crate::token::one_of;
use crate::token::tag;
use crate::token::take_while;
diff --git a/vendor/winnow/src/_tutorial/chapter_3.rs b/vendor/winnow/src/_tutorial/chapter_3.rs
index 8d307e324..83714f4d7 100644
--- a/vendor/winnow/src/_tutorial/chapter_3.rs
+++ b/vendor/winnow/src/_tutorial/chapter_3.rs
@@ -10,15 +10,14 @@
//! Now that we can create more interesting parsers, we can sequence them together, like:
//!
//! ```rust
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
-//! # use winnow::Parser;
-//! # use winnow::IResult;
//! #
-//! fn parse_prefix(input: &str) -> IResult<&str, &str> {
+//! fn parse_prefix<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! "0x".parse_next(input)
//! }
//!
-//! fn parse_digits(input: &str) -> IResult<&str, &str> {
+//! fn parse_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! take_while(1.., (
//! ('0'..='9'),
//! ('A'..='F'),
@@ -27,28 +26,27 @@
//! }
//!
//! fn main() {
-//! let input = "0x1a2b Hello";
+//! let mut input = "0x1a2b Hello";
//!
-//! let (remainder, prefix) = parse_prefix.parse_next(input).unwrap();
-//! let (remainder, digits) = parse_digits.parse_next(remainder).unwrap();
+//! let prefix = parse_prefix.parse_next(&mut input).unwrap();
+//! let digits = parse_digits.parse_next(&mut input).unwrap();
//!
//! assert_eq!(prefix, "0x");
//! assert_eq!(digits, "1a2b");
-//! assert_eq!(remainder, " Hello");
+//! assert_eq!(input, " Hello");
//! }
//! ```
//!
//! To sequence these together, you can just put them in a tuple:
//! ```rust
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
-//! # use winnow::Parser;
-//! # use winnow::IResult;
//! #
-//! # fn parse_prefix(input: &str) -> IResult<&str, &str> {
+//! # fn parse_prefix<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # "0x".parse_next(input)
//! # }
//! #
-//! # fn parse_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # ('A'..='F'),
@@ -59,32 +57,31 @@
//! //...
//!
//! fn main() {
-//! let input = "0x1a2b Hello";
+//! let mut input = "0x1a2b Hello";
//!
-//! let (remainder, (prefix, digits)) = (
+//! let (prefix, digits) = (
//! parse_prefix,
//! parse_digits
-//! ).parse_next(input).unwrap();
+//! ).parse_next(&mut input).unwrap();
//!
//! assert_eq!(prefix, "0x");
//! assert_eq!(digits, "1a2b");
-//! assert_eq!(remainder, " Hello");
+//! assert_eq!(input, " Hello");
//! }
//! ```
//!
//! Frequently, you won't care about the tag and you can instead use one of the provided combinators,
//! like [`preceded`]:
//! ```rust
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
-//! # use winnow::Parser;
-//! # use winnow::IResult;
//! use winnow::combinator::preceded;
//!
-//! # fn parse_prefix(input: &str) -> IResult<&str, &str> {
+//! # fn parse_prefix<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # "0x".parse_next(input)
//! # }
//! #
-//! # fn parse_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # ('A'..='F'),
@@ -95,63 +92,72 @@
//! //...
//!
//! fn main() {
-//! let input = "0x1a2b Hello";
+//! let mut input = "0x1a2b Hello";
//!
-//! let (remainder, digits) = preceded(
+//! let digits = preceded(
//! parse_prefix,
//! parse_digits
-//! ).parse_next(input).unwrap();
+//! ).parse_next(&mut input).unwrap();
//!
//! assert_eq!(digits, "1a2b");
-//! assert_eq!(remainder, " Hello");
+//! assert_eq!(input, " Hello");
//! }
//! ```
//!
+//! See [`combinator`] for more sequencing parsers.
+//!
//! ## Alternatives
//!
//! Sometimes, we might want to choose between two parsers; and we're happy with
//! either being used.
//!
-//! The de facto way to do this in winnow is with the [`alt()`] combinator which will execute each
-//! parser in a tuple until it finds one that does not error. If all error, then by default you are
-//! given the error from the last parser.
-//!
-//! We can see a basic example of `alt()` below.
+//! [`Stream::checkpoint`] helps us to retry parsing:
//! ```rust
-//! # use winnow::IResult;
-//! # use winnow::Parser;
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
-//! use winnow::combinator::alt;
+//! use winnow::stream::Stream;
//!
-//! fn parse_digits(input: &str) -> IResult<&str, (&str, &str)> {
-//! alt((
-//! ("0b", parse_bin_digits),
-//! ("0o", parse_oct_digits),
-//! ("0d", parse_dec_digits),
-//! ("0x", parse_hex_digits),
-//! )).parse_next(input)
+//! fn parse_digits<'s>(input: &mut &'s str) -> PResult<(&'s str, &'s str)> {
+//! let start = input.checkpoint();
+//!
+//! if let Ok(output) = ("0b", parse_bin_digits).parse_next(input) {
+//! return Ok(output);
+//! }
+//!
+//! input.reset(start);
+//! if let Ok(output) = ("0o", parse_oct_digits).parse_next(input) {
+//! return Ok(output);
+//! }
+//!
+//! input.reset(start);
+//! if let Ok(output) = ("0d", parse_dec_digits).parse_next(input) {
+//! return Ok(output);
+//! }
+//!
+//! input.reset(start);
+//! ("0x", parse_hex_digits).parse_next(input)
//! }
//!
//! // ...
-//! # fn parse_bin_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_oct_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_dec_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_hex_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # ('A'..='F'),
@@ -160,31 +166,147 @@
//! # }
//!
//! fn main() {
-//! let input = "0x1a2b Hello";
+//! let mut input = "0x1a2b Hello";
//!
-//! let (remainder, (prefix, digits)) = parse_digits.parse_next(input).unwrap();
+//! let (prefix, digits) = parse_digits.parse_next(&mut input).unwrap();
//!
-//! assert_eq!(remainder, " Hello");
+//! assert_eq!(input, " Hello");
//! assert_eq!(prefix, "0x");
//! assert_eq!(digits, "1a2b");
//!
-//! assert!(parse_digits("ghiWorld").is_err());
+//! assert!(parse_digits(&mut "ghiWorld").is_err());
//! }
//! ```
//!
+//! > **Warning:** the above example is for illustrative purposes and relying on `Result::Ok` or
+//! > `Result::Err` can lead to incorrect behavior. This will be clarified in later when covering
+//! > [error handling][`chapter_6`#errmode]
+//!
+//! [`opt`] is a basic building block for correctly handling retrying parsing:
+//! ```rust
+//! # use winnow::prelude::*;
+//! # use winnow::token::take_while;
+//! use winnow::combinator::opt;
+//!
+//! fn parse_digits<'s>(input: &mut &'s str) -> PResult<(&'s str, &'s str)> {
+//! if let Some(output) = opt(("0b", parse_bin_digits)).parse_next(input)? {
+//! Ok(output)
+//! } else if let Some(output) = opt(("0o", parse_oct_digits)).parse_next(input)? {
+//! Ok(output)
+//! } else if let Some(output) = opt(("0d", parse_dec_digits)).parse_next(input)? {
+//! Ok(output)
+//! } else {
+//! ("0x", parse_hex_digits).parse_next(input)
+//! }
+//! }
+//! #
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='7'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='7'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='9'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='9'),
+//! # ('A'..='F'),
+//! # ('a'..='f'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn main() {
+//! # let mut input = "0x1a2b Hello";
+//! #
+//! # let (prefix, digits) = parse_digits.parse_next(&mut input).unwrap();
+//! #
+//! # assert_eq!(input, " Hello");
+//! # assert_eq!(prefix, "0x");
+//! # assert_eq!(digits, "1a2b");
+//! #
+//! # assert!(parse_digits(&mut "ghiWorld").is_err());
+//! # }
+//! ```
+//!
+//! [`alt`] encapsulates this if/else-if ladder pattern, with the last case being the `else`:
+//! ```rust
+//! # use winnow::prelude::*;
+//! # use winnow::token::take_while;
+//! use winnow::combinator::alt;
+//!
+//! fn parse_digits<'s>(input: &mut &'s str) -> PResult<(&'s str, &'s str)> {
+//! alt((
+//! ("0b", parse_bin_digits),
+//! ("0o", parse_oct_digits),
+//! ("0d", parse_dec_digits),
+//! ("0x", parse_hex_digits),
+//! )).parse_next(input)
+//! }
+//! #
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='7'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='7'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='9'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='9'),
+//! # ('A'..='F'),
+//! # ('a'..='f'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn main() {
+//! # let mut input = "0x1a2b Hello";
+//! #
+//! # let (prefix, digits) = parse_digits.parse_next(&mut input).unwrap();
+//! #
+//! # assert_eq!(input, " Hello");
+//! # assert_eq!(prefix, "0x");
+//! # assert_eq!(digits, "1a2b");
+//! #
+//! # assert!(parse_digits(&mut "ghiWorld").is_err());
+//! # }
+//! ```
+//!
+//! > **Note:** [`success`] and [`fail`] are parsers that might be useful in the `else` case.
+//!
//! Sometimes a giant if/else-if ladder can be slow and you'd rather have a `match` statement for
//! branches of your parser that have unique prefixes. In this case, you can use the
//! [`dispatch`][crate::combinator::dispatch] macro:
//!
//! ```rust
-//! # use winnow::IResult;
-//! # use winnow::Parser;
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
//! use winnow::combinator::dispatch;
//! use winnow::token::take;
//! use winnow::combinator::fail;
//!
-//! fn parse_digits(input: &str) -> IResult<&str, &str> {
+//! fn parse_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! dispatch!(take(2usize);
//! "0b" => parse_bin_digits,
//! "0o" => parse_oct_digits,
@@ -195,25 +317,25 @@
//! }
//!
//! // ...
-//! # fn parse_bin_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_oct_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_dec_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_hex_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # ('A'..='F'),
@@ -222,21 +344,32 @@
//! # }
//!
//! fn main() {
-//! let input = "0x1a2b Hello";
+//! let mut input = "0x1a2b Hello";
//!
-//! let (remainder, digits) = parse_digits.parse_next(input).unwrap();
+//! let digits = parse_digits.parse_next(&mut input).unwrap();
//!
-//! assert_eq!(remainder, " Hello");
+//! assert_eq!(input, " Hello");
//! assert_eq!(digits, "1a2b");
//!
-//! assert!(parse_digits("ghiWorld").is_err());
+//! assert!(parse_digits(&mut "ghiWorld").is_err());
//! }
//! ```
+//!
+//! > **Note:** [`peek`] may be useful when [`dispatch`]ing from hints from each case's parser.
+//!
+//! See [`combinator`] for more alternative parsers.
#![allow(unused_imports)]
+use super::chapter_6;
+use crate::combinator;
use crate::combinator::alt;
use crate::combinator::dispatch;
+use crate::combinator::fail;
+use crate::combinator::opt;
+use crate::combinator::peek;
use crate::combinator::preceded;
+use crate::combinator::success;
+use crate::stream::Stream;
pub use super::chapter_2 as previous;
pub use super::chapter_4 as next;
diff --git a/vendor/winnow/src/_tutorial/chapter_4.rs b/vendor/winnow/src/_tutorial/chapter_4.rs
index 315d185ba..fb14613f3 100644
--- a/vendor/winnow/src/_tutorial/chapter_4.rs
+++ b/vendor/winnow/src/_tutorial/chapter_4.rs
@@ -1,18 +1,18 @@
//! # Chapter 4: Parsers With Custom Return Types
//!
//! So far, we have seen mostly functions that take an `&str`, and return a
-//! `IResult<&str, &str>`. Splitting strings into smaller strings and characters is certainly
+//! `PResult<&str>`. Splitting strings into smaller strings and characters is certainly
//! useful, but it's not the only thing winnow is capable of!
//!
//! A useful operation when parsing is to convert between types; for example
//! parsing from `&str` to another primitive, like [`usize`].
//!
//! All we need to do for our parser to return a different type is to change
-//! the second type parameter of [`IResult`] to the desired return type.
-//! For example, to return a `usize`, return a `IResult<&str, usize>`.
-//! Recall that the first type parameter of the `IResult` is the input
+//! the type parameter of [`PResult`] to the desired return type.
+//! For example, to return a `usize`, return a `PResult<usize>`.
+//! Recall that the type parameter of the `PResult` is the input
//! type, so even if you're returning something different, if your input
-//! is a `&str`, the first type argument of `IResult` should be also.
+//! is a `&str`, the type argument of `PResult` should be also.
//!
//! One winnow-native way of doing a type conversion is to use the
//! [`Parser::parse_to`] combinator
@@ -20,38 +20,36 @@
//!
//! The following code converts from a string containing a number to `usize`:
//! ```rust
-//! # use winnow::Parser;
-//! # use winnow::IResult;
+//! # use winnow::prelude::*;
//! # use winnow::ascii::digit1;
//! #
-//! fn parse_digits(input: &str) -> IResult<&str, usize> {
+//! fn parse_digits(input: &mut &str) -> PResult<usize> {
//! digit1
//! .parse_to()
//! .parse_next(input)
//! }
//!
//! fn main() {
-//! let input = "1024 Hello";
+//! let mut input = "1024 Hello";
//!
-//! let (remainder, output) = parse_digits.parse_next(input).unwrap();
-//! assert_eq!(remainder, " Hello");
+//! let output = parse_digits.parse_next(&mut input).unwrap();
+//! assert_eq!(input, " Hello");
//! assert_eq!(output, 1024);
//!
-//! assert!(parse_digits("Z").is_err());
+//! assert!(parse_digits(&mut "Z").is_err());
//! }
//! ```
//!
//! `Parser::parse_to` is just a convenient form of [`Parser::try_map`] which we can use to handle
//! all radices of numbers:
//! ```rust
-//! # use winnow::IResult;
-//! # use winnow::Parser;
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
//! use winnow::combinator::dispatch;
//! use winnow::token::take;
//! use winnow::combinator::fail;
//!
-//! fn parse_digits(input: &str) -> IResult<&str, usize> {
+//! fn parse_digits(input: &mut &str) -> PResult<usize> {
//! dispatch!(take(2usize);
//! "0b" => parse_bin_digits.try_map(|s| usize::from_str_radix(s, 2)),
//! "0o" => parse_oct_digits.try_map(|s| usize::from_str_radix(s, 8)),
@@ -62,25 +60,25 @@
//! }
//!
//! // ...
-//! # fn parse_bin_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_oct_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_dec_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_hex_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # ('A'..='F'),
@@ -89,19 +87,21 @@
//! # }
//!
//! fn main() {
-//! let input = "0x1a2b Hello";
+//! let mut input = "0x1a2b Hello";
//!
-//! let (remainder, digits) = parse_digits.parse_next(input).unwrap();
+//! let digits = parse_digits.parse_next(&mut input).unwrap();
//!
-//! assert_eq!(remainder, " Hello");
+//! assert_eq!(input, " Hello");
//! assert_eq!(digits, 0x1a2b);
//!
-//! assert!(parse_digits("ghiWorld").is_err());
+//! assert!(parse_digits(&mut "ghiWorld").is_err());
//! }
//! ```
+//!
+//! See also [`Parser`] for more output-modifying parsers.
#![allow(unused_imports)]
-use crate::IResult;
+use crate::PResult;
use crate::Parser;
use std::str::FromStr;
diff --git a/vendor/winnow/src/_tutorial/chapter_5.rs b/vendor/winnow/src/_tutorial/chapter_5.rs
index 3a4be4b32..95a89dc8c 100644
--- a/vendor/winnow/src/_tutorial/chapter_5.rs
+++ b/vendor/winnow/src/_tutorial/chapter_5.rs
@@ -1,12 +1,11 @@
//! # Chapter 5: Repetition
//!
//! In [`chapter_3`], we covered how to sequence different parsers into a tuple but sometimes you need to run a
-//! single parser multiple times, collecting the result into a [`Vec`].
+//! single parser multiple times, collecting the result into a container, like [`Vec`].
//!
-//! Let's take our `parse_digits` and collect a list of them with [`repeat`]:
+//! Let's collect the result of `parse_digits`:
//! ```rust
-//! # use winnow::IResult;
-//! # use winnow::Parser;
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
//! # use winnow::combinator::dispatch;
//! # use winnow::token::take;
@@ -15,40 +14,44 @@
//! use winnow::combinator::repeat;
//! use winnow::combinator::terminated;
//!
-//! fn parse_list(input: &str) -> IResult<&str, Vec<usize>> {
-//! repeat(0.., terminated(parse_digits, opt(','))).parse_next(input)
+//! fn parse_list(input: &mut &str) -> PResult<Vec<usize>> {
+//! let mut list = Vec::new();
+//! while let Some(output) = opt(terminated(parse_digits, opt(','))).parse_next(input)? {
+//! list.push(output);
+//! }
+//! Ok(list)
//! }
//!
//! // ...
-//! # fn parse_digits(input: &str) -> IResult<&str, usize> {
+//! # fn parse_digits(input: &mut &str) -> PResult<usize> {
//! # dispatch!(take(2usize);
-//! # "0b" => parse_bin_digits.try_map(|s| usize::from_str_radix(s, 2)),
-//! # "0o" => parse_oct_digits.try_map(|s| usize::from_str_radix(s, 8)),
-//! # "0d" => parse_dec_digits.try_map(|s| usize::from_str_radix(s, 10)),
-//! # "0x" => parse_hex_digits.try_map(|s| usize::from_str_radix(s, 16)),
-//! # _ => fail,
-//! # ).parse_next(input)
+//! # "0b" => parse_bin_digits.try_map(|s| usize::from_str_radix(s, 2)),
+//! # "0o" => parse_oct_digits.try_map(|s| usize::from_str_radix(s, 8)),
+//! # "0d" => parse_dec_digits.try_map(|s| usize::from_str_radix(s, 10)),
+//! # "0x" => parse_hex_digits.try_map(|s| usize::from_str_radix(s, 16)),
+//! # _ => fail,
+//! # ).parse_next(input)
//! # }
//! #
-//! # fn parse_bin_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_oct_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_dec_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_hex_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # ('A'..='F'),
@@ -57,62 +60,126 @@
//! # }
//!
//! fn main() {
-//! let input = "0x1a2b,0x3c4d,0x5e6f Hello";
+//! let mut input = "0x1a2b,0x3c4d,0x5e6f Hello";
//!
-//! let (remainder, digits) = parse_list.parse_next(input).unwrap();
+//! let digits = parse_list.parse_next(&mut input).unwrap();
//!
-//! assert_eq!(remainder, " Hello");
+//! assert_eq!(input, " Hello");
//! assert_eq!(digits, vec![0x1a2b, 0x3c4d, 0x5e6f]);
//!
-//! assert!(parse_digits("ghiWorld").is_err());
+//! assert!(parse_digits(&mut "ghiWorld").is_err());
//! }
//! ```
//!
+//! We can implement this declaratively with [`repeat`]:
+//! ```rust
+//! # use winnow::prelude::*;
+//! # use winnow::token::take_while;
+//! # use winnow::combinator::dispatch;
+//! # use winnow::token::take;
+//! # use winnow::combinator::fail;
+//! use winnow::combinator::opt;
+//! use winnow::combinator::repeat;
+//! use winnow::combinator::terminated;
+//!
+//! fn parse_list(input: &mut &str) -> PResult<Vec<usize>> {
+//! repeat(0..,
+//! terminated(parse_digits, opt(','))
+//! ).parse_next(input)
+//! }
+//! #
+//! # fn parse_digits(input: &mut &str) -> PResult<usize> {
+//! # dispatch!(take(2usize);
+//! # "0b" => parse_bin_digits.try_map(|s| usize::from_str_radix(s, 2)),
+//! # "0o" => parse_oct_digits.try_map(|s| usize::from_str_radix(s, 8)),
+//! # "0d" => parse_dec_digits.try_map(|s| usize::from_str_radix(s, 10)),
+//! # "0x" => parse_hex_digits.try_map(|s| usize::from_str_radix(s, 16)),
+//! # _ => fail,
+//! # ).parse_next(input)
+//! # }
+//! #
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='7'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='7'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='9'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! # take_while(1.., (
+//! # ('0'..='9'),
+//! # ('A'..='F'),
+//! # ('a'..='f'),
+//! # )).parse_next(input)
+//! # }
+//! #
+//! # fn main() {
+//! # let mut input = "0x1a2b,0x3c4d,0x5e6f Hello";
+//! #
+//! # let digits = parse_list.parse_next(&mut input).unwrap();
+//! #
+//! # assert_eq!(input, " Hello");
+//! # assert_eq!(digits, vec![0x1a2b, 0x3c4d, 0x5e6f]);
+//! #
+//! # assert!(parse_digits(&mut "ghiWorld").is_err());
+//! # }
+//! ```
+//!
//! You'll notice that the above allows trailing `,` when we intended to not support that. We can
//! easily fix this by using [`separated0`]:
//! ```rust
-//! # use winnow::IResult;
-//! # use winnow::Parser;
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
//! # use winnow::combinator::dispatch;
//! # use winnow::token::take;
//! # use winnow::combinator::fail;
//! use winnow::combinator::separated0;
//!
-//! fn parse_list(input: &str) -> IResult<&str, Vec<usize>> {
+//! fn parse_list(input: &mut &str) -> PResult<Vec<usize>> {
//! separated0(parse_digits, ",").parse_next(input)
//! }
//!
//! // ...
-//! # fn parse_digits(input: &str) -> IResult<&str, usize> {
+//! # fn parse_digits(input: &mut &str) -> PResult<usize> {
//! # dispatch!(take(2usize);
-//! # "0b" => parse_bin_digits.try_map(|s| usize::from_str_radix(s, 2)),
-//! # "0o" => parse_oct_digits.try_map(|s| usize::from_str_radix(s, 8)),
-//! # "0d" => parse_dec_digits.try_map(|s| usize::from_str_radix(s, 10)),
-//! # "0x" => parse_hex_digits.try_map(|s| usize::from_str_radix(s, 16)),
-//! # _ => fail,
-//! # ).parse_next(input)
+//! # "0b" => parse_bin_digits.try_map(|s| usize::from_str_radix(s, 2)),
+//! # "0o" => parse_oct_digits.try_map(|s| usize::from_str_radix(s, 8)),
+//! # "0d" => parse_dec_digits.try_map(|s| usize::from_str_radix(s, 10)),
+//! # "0x" => parse_hex_digits.try_map(|s| usize::from_str_radix(s, 16)),
+//! # _ => fail,
+//! # ).parse_next(input)
//! # }
//! #
-//! # fn parse_bin_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_oct_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_dec_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_hex_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # ('A'..='F'),
@@ -121,14 +188,14 @@
//! # }
//!
//! fn main() {
-//! let input = "0x1a2b,0x3c4d,0x5e6f Hello";
+//! let mut input = "0x1a2b,0x3c4d,0x5e6f Hello";
//!
-//! let (remainder, digits) = parse_list.parse_next(input).unwrap();
+//! let digits = parse_list.parse_next(&mut input).unwrap();
//!
-//! assert_eq!(remainder, " Hello");
+//! assert_eq!(input, " Hello");
//! assert_eq!(digits, vec![0x1a2b, 0x3c4d, 0x5e6f]);
//!
-//! assert!(parse_digits("ghiWorld").is_err());
+//! assert!(parse_digits(&mut "ghiWorld").is_err());
//! }
//! ```
//!
@@ -136,52 +203,50 @@
//! [`Accumulate`] to gather the results. This let's us make more complex parsers than we did in
//! [`chapter_2`] by accumulating the results into a `()` and [`recognize`][Parser::recognize]-ing the captured input:
//! ```rust
-//! # use winnow::IResult;
-//! # use winnow::Parser;
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
//! # use winnow::combinator::dispatch;
//! # use winnow::token::take;
//! # use winnow::combinator::fail;
//! # use winnow::combinator::separated0;
//! #
-//! fn recognize_list(input: &str) -> IResult<&str, &str> {
+//! fn recognize_list<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! parse_list.recognize().parse_next(input)
//! }
//!
-//! fn parse_list(input: &str) -> IResult<&str, ()> {
+//! fn parse_list(input: &mut &str) -> PResult<()> {
//! separated0(parse_digits, ",").parse_next(input)
//! }
//!
-//! // ...
-//! # fn parse_digits(input: &str) -> IResult<&str, usize> {
+//! # fn parse_digits(input: &mut &str) -> PResult<usize> {
//! # dispatch!(take(2usize);
-//! # "0b" => parse_bin_digits.try_map(|s| usize::from_str_radix(s, 2)),
-//! # "0o" => parse_oct_digits.try_map(|s| usize::from_str_radix(s, 8)),
-//! # "0d" => parse_dec_digits.try_map(|s| usize::from_str_radix(s, 10)),
-//! # "0x" => parse_hex_digits.try_map(|s| usize::from_str_radix(s, 16)),
-//! # _ => fail,
-//! # ).parse_next(input)
+//! # "0b" => parse_bin_digits.try_map(|s| usize::from_str_radix(s, 2)),
+//! # "0o" => parse_oct_digits.try_map(|s| usize::from_str_radix(s, 8)),
+//! # "0d" => parse_dec_digits.try_map(|s| usize::from_str_radix(s, 10)),
+//! # "0x" => parse_hex_digits.try_map(|s| usize::from_str_radix(s, 16)),
+//! # _ => fail,
+//! # ).parse_next(input)
//! # }
//! #
-//! # fn parse_bin_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_oct_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_dec_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_hex_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # ('A'..='F'),
@@ -190,20 +255,22 @@
//! # }
//!
//! fn main() {
-//! let input = "0x1a2b,0x3c4d,0x5e6f Hello";
+//! let mut input = "0x1a2b,0x3c4d,0x5e6f Hello";
//!
-//! let (remainder, digits) = recognize_list.parse_next(input).unwrap();
+//! let digits = recognize_list.parse_next(&mut input).unwrap();
//!
-//! assert_eq!(remainder, " Hello");
+//! assert_eq!(input, " Hello");
//! assert_eq!(digits, "0x1a2b,0x3c4d,0x5e6f");
//!
-//! assert!(parse_digits("ghiWorld").is_err());
+//! assert!(parse_digits(&mut "ghiWorld").is_err());
//! }
//! ```
+//! See [`combinator`] for more repetition parsers.
#![allow(unused_imports)]
use super::chapter_2;
use super::chapter_3;
+use crate::combinator;
use crate::combinator::repeat;
use crate::combinator::separated0;
use crate::stream::Accumulate;
diff --git a/vendor/winnow/src/_tutorial/chapter_6.rs b/vendor/winnow/src/_tutorial/chapter_6.rs
index 268e38a31..d7d2c9fc8 100644
--- a/vendor/winnow/src/_tutorial/chapter_6.rs
+++ b/vendor/winnow/src/_tutorial/chapter_6.rs
@@ -2,51 +2,48 @@
//!
//! ## `Error`
//!
-//! Back in [`chapter_1`], we glossed over the `Err` side of [`IResult`]. `IResult<I, O>` is
-//! actually short for `IResult<I, O, E=Error>` where [`Error`] is a cheap, universal error type
-//! for getting started. When humans are producing the file, like with `toml`, you might want to
-//! sacrifice some performance for providing more details on how to resolve the problem
+//! Back in [`chapter_1`], we glossed over the `Err` side of [`PResult`]. `PResult<O>` is
+//! actually short for `PResult<O, E=ContextError>` where [`ContextError`] is a relatively cheap
+//! way of building up reasonable errors for humans.
//!
-//! winnow includes [`VerboseError`] for this but you can [customize the error as you
-//! wish][_topic::error]. You can use [`Parser::context`] to annotate the error with custom types
+//! You can use [`Parser::context`] to annotate the error with custom types
//! while unwinding to further improve the error quality.
//!
//! ```rust
-//! # use winnow::IResult;
-//! # use winnow::Parser;
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
//! # use winnow::combinator::alt;
-//! use winnow::error::VerboseError;
+//! use winnow::error::StrContext;
//!
-//! fn parse_digits(input: &str) -> IResult<&str, (&str, &str), VerboseError<&str>> {
+//! fn parse_digits<'s>(input: &mut &'s str) -> PResult<(&'s str, &'s str)> {
//! alt((
-//! ("0b", parse_bin_digits).context("binary"),
-//! ("0o", parse_oct_digits).context("octal"),
-//! ("0d", parse_dec_digits).context("decimal"),
-//! ("0x", parse_hex_digits).context("hexadecimal"),
+//! ("0b", parse_bin_digits).context(StrContext::Label("binary")),
+//! ("0o", parse_oct_digits).context(StrContext::Label("octal")),
+//! ("0d", parse_dec_digits).context(StrContext::Label("decimal")),
+//! ("0x", parse_hex_digits).context(StrContext::Label("hexadecimal")),
//! )).parse_next(input)
//! }
//!
//! // ...
-//! # fn parse_bin_digits(input: &str) -> IResult<&str, &str, VerboseError<&str>> {
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_oct_digits(input: &str) -> IResult<&str, &str, VerboseError<&str>> {
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_dec_digits(input: &str) -> IResult<&str, &str, VerboseError<&str>> {
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_hex_digits(input: &str) -> IResult<&str, &str, VerboseError<&str>> {
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # ('A'..='F'),
@@ -55,11 +52,11 @@
//! # }
//!
//! fn main() {
-//! let input = "0x1a2b Hello";
+//! let mut input = "0x1a2b Hello";
//!
-//! let (remainder, (prefix, digits)) = parse_digits.parse_next(input).unwrap();
+//! let (prefix, digits) = parse_digits.parse_next(&mut input).unwrap();
//!
-//! assert_eq!(remainder, " Hello");
+//! assert_eq!(input, " Hello");
//! assert_eq!(prefix, "0x");
//! assert_eq!(digits, "1a2b");
//! }
@@ -71,58 +68,57 @@
//!
//! ## `ErrMode`
//!
-//! Let's break down `IResult<I, O, E>` one step further:
+//! Let's break down `PResult<O, E>` one step further:
//! ```rust
-//! # use winnow::error::Error;
+//! # use winnow::error::ErrorKind;
//! # use winnow::error::ErrMode;
-//! pub type IResult<I, O, E = Error<I>> = Result<(I, O), ErrMode<E>>;
+//! pub type OResult<O, E = ErrorKind> = Result<O, ErrMode<E>>;
//! ```
-//! `IResult` is just a fancy wrapper around `Result` that wraps our error in an [`ErrMode`]
+//! [`PResult`] is just a fancy wrapper around `Result` that wraps our error in an [`ErrMode`]
//! type.
//!
-//! `ErrMode` is an enum with `Backtrack` and `Cut` variants (ignore `Incomplete` as its only
-//! relevant for [streaming][_topic::stream]). By default, errors are `Backtrack`, meaning that
-//! other parsing branches will be attempted on failure, like the next case of an `alt`. `Cut`
+//! [`ErrMode`] is an enum with [`Backtrack`] and [`Cut`] variants (ignore [`Incomplete`] as its only
+//! relevant for [streaming][_topic::stream]). By default, errors are [`Backtrack`], meaning that
+//! other parsing branches will be attempted on failure, like the next case of an [`alt`]. [`Cut`]
//! shortcircuits all other branches, immediately reporting the error.
//!
//! So we can get the correct `context` by modifying the above example with [`cut_err`]:
//! ```rust
-//! # use winnow::IResult;
-//! # use winnow::Parser;
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
//! # use winnow::combinator::alt;
-//! # use winnow::error::VerboseError;
+//! # use winnow::error::StrContext;
//! use winnow::combinator::cut_err;
//!
-//! fn parse_digits(input: &str) -> IResult<&str, (&str, &str), VerboseError<&str>> {
+//! fn parse_digits<'s>(input: &mut &'s str) -> PResult<(&'s str, &'s str)> {
//! alt((
-//! ("0b", cut_err(parse_bin_digits)).context("binary"),
-//! ("0o", cut_err(parse_oct_digits)).context("octal"),
-//! ("0d", cut_err(parse_dec_digits)).context("decimal"),
-//! ("0x", cut_err(parse_hex_digits)).context("hexadecimal"),
+//! ("0b", cut_err(parse_bin_digits)).context(StrContext::Label("binary")),
+//! ("0o", cut_err(parse_oct_digits)).context(StrContext::Label("octal")),
+//! ("0d", cut_err(parse_dec_digits)).context(StrContext::Label("decimal")),
+//! ("0x", cut_err(parse_hex_digits)).context(StrContext::Label("hexadecimal")),
//! )).parse_next(input)
//! }
//!
//! // ...
-//! # fn parse_bin_digits(input: &str) -> IResult<&str, &str, VerboseError<&str>> {
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_oct_digits(input: &str) -> IResult<&str, &str, VerboseError<&str>> {
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_dec_digits(input: &str) -> IResult<&str, &str, VerboseError<&str>> {
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_hex_digits(input: &str) -> IResult<&str, &str, VerboseError<&str>> {
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # ('A'..='F'),
@@ -131,11 +127,11 @@
//! # }
//!
//! fn main() {
-//! let input = "0x1a2b Hello";
+//! let mut input = "0x1a2b Hello";
//!
-//! let (remainder, (prefix, digits)) = parse_digits.parse_next(input).unwrap();
+//! let (prefix, digits) = parse_digits.parse_next(&mut input).unwrap();
//!
-//! assert_eq!(remainder, " Hello");
+//! assert_eq!(input, " Hello");
//! assert_eq!(prefix, "0x");
//! assert_eq!(digits, "1a2b");
//! }
@@ -147,10 +143,11 @@ use super::chapter_1;
use super::chapter_3;
use crate::combinator::alt;
use crate::combinator::cut_err;
+use crate::error::ContextError;
use crate::error::ErrMode;
-use crate::error::Error;
-use crate::error::VerboseError;
-use crate::IResult;
+use crate::error::ErrMode::*;
+use crate::error::ErrorKind;
+use crate::PResult;
use crate::Parser;
use crate::_topic;
diff --git a/vendor/winnow/src/_tutorial/chapter_7.rs b/vendor/winnow/src/_tutorial/chapter_7.rs
index c20607c36..45f2d2d2a 100644
--- a/vendor/winnow/src/_tutorial/chapter_7.rs
+++ b/vendor/winnow/src/_tutorial/chapter_7.rs
@@ -3,53 +3,62 @@
//! So far, we've highlighted how to incrementally parse, but how do we bring this all together
//! into our application?
//!
-//! The type we've been working with looks like:
+//! Parsers we've been working with look like:
//! ```rust
-//! # use winnow::error::VerboseError;
+//! # use winnow::error::ContextError;
//! # use winnow::error::ErrMode;
-//! type IResult<'i, O> = Result<
-//! (&'i str, O),
-//! ErrMode<
-//! VerboseError<&'i str>
-//! >
+//! # use winnow::Parser;
+//! #
+//! pub fn parser<'s>(input: &mut &'s str) -> PResult<&'s str> {
+//! // ...
+//! # Ok("")
+//! }
+//!
+//! type PResult<O> = Result<
+//! O,
+//! ErrMode<ContextError>
//! >;
//! ```
-//! 1. We have to decide what to do about the `remainder` of the input.
-//! 2. The error type is not compatible with the rest of the Rust ecosystem
+//! 1. We have to decide what to do about the "remainder" of the `input`.
+//! 2. The [`ErrMode<ContextError>`] is not compatible with the rest of the Rust ecosystem.
+//! Normally, Rust applications want errors that are `std::error::Error + Send + Sync + 'static`
+//! meaning:
+//! - They implement the [`std::error::Error`] trait
+//! - They can be sent across threads
+//! - They are safe to be referenced across threads
+//! - They do not borrow
//!
-//! Normally, Rust applications want errors that are `std::error::Error + Send + Sync + 'static`
-//! meaning:
-//! - They implement the [`std::error::Error`] trait
-//! - They can be sent across threads
-//! - They are safe to be referenced across threads
-//! - They do not borrow
-//!
-//! winnow provides some helpers for this:
+//! winnow provides [`Parser::parse`] to help with this:
+//! - Ensures we hit [`eof`]
+//! - Removes the [`ErrMode`] wrapper
+//! - Wraps the error in [`ParseError`]
+//! - Provides access to the original [`input`][ParseError::input] with the
+//! [`offset`][ParseError::offset] of where it failed
+//! - Provides a default renderer (via [`std::fmt::Display`])
//! ```rust
-//! # use winnow::IResult;
+//! # use winnow::prelude::*;
//! # use winnow::token::take_while;
//! # use winnow::combinator::dispatch;
//! # use winnow::token::take;
//! # use winnow::combinator::fail;
//! use winnow::Parser;
-//! use winnow::error::Error;
//!
//! #[derive(Debug, PartialEq, Eq)]
//! pub struct Hex(usize);
//!
//! impl std::str::FromStr for Hex {
-//! type Err = Error<String>;
+//! type Err = String;
//!
//! fn from_str(input: &str) -> Result<Self, Self::Err> {
//! parse_digits
//! .map(Hex)
//! .parse(input)
-//! .map_err(|e| e.into_owned())
+//! .map_err(|e| e.to_string())
//! }
//! }
//!
//! // ...
-//! # fn parse_digits(input: &str) -> IResult<&str, usize> {
+//! # fn parse_digits<'s>(input: &mut &'s str) -> PResult<usize> {
//! # dispatch!(take(2usize);
//! # "0b" => parse_bin_digits.try_map(|s| usize::from_str_radix(s, 2)),
//! # "0o" => parse_oct_digits.try_map(|s| usize::from_str_radix(s, 8)),
@@ -59,25 +68,25 @@
//! # ).parse_next(input)
//! # }
//! #
-//! # fn parse_bin_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_bin_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_oct_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_oct_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='7'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_dec_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_dec_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # )).parse_next(input)
//! # }
//! #
-//! # fn parse_hex_digits(input: &str) -> IResult<&str, &str> {
+//! # fn parse_hex_digits<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! # take_while(1.., (
//! # ('0'..='9'),
//! # ('A'..='F'),
@@ -95,17 +104,14 @@
//! assert!(input.parse::<Hex>().is_err());
//! }
//! ```
-//! - Ensures we hit [`eof`]
-//! - Removes the [`ErrMode`] wrapper
-//!
-//! [`Error::into_owned`]:
-//! - Converts the `&str` in `Error` to `String` which enables support for [`std::error::Error`]
#![allow(unused_imports)]
use super::chapter_1;
use crate::combinator::eof;
use crate::error::ErrMode;
-use crate::error::Error;
-use crate::IResult;
+use crate::error::InputError;
+use crate::error::ParseError;
+use crate::PResult;
+use crate::Parser;
pub use super::chapter_6 as previous;
diff --git a/vendor/winnow/src/ascii/mod.rs b/vendor/winnow/src/ascii/mod.rs
index 4ada7c00b..8b3119fbf 100644
--- a/vendor/winnow/src/ascii/mod.rs
+++ b/vendor/winnow/src/ascii/mod.rs
@@ -8,21 +8,20 @@ mod tests;
use crate::lib::std::ops::{Add, Shl};
use crate::combinator::alt;
-use crate::token::one_of;
-
use crate::combinator::cut_err;
use crate::combinator::opt;
-use crate::error::ParseError;
+use crate::error::ParserError;
use crate::error::{ErrMode, ErrorKind, Needed};
-use crate::stream::ContainsToken;
-use crate::stream::{AsBStr, AsChar, Offset, ParseSlice, Stream, StreamIsPartial};
+use crate::stream::{AsBStr, AsChar, ParseSlice, Stream, StreamIsPartial};
use crate::stream::{Compare, CompareResult};
+use crate::token::one_of;
+use crate::token::take_till0;
use crate::token::take_while;
use crate::trace::trace;
-use crate::IResult;
+use crate::PResult;
use crate::Parser;
-/// Recognizes the string "\r\n".
+/// Recognizes the string `"\r\n"`.
///
/// *Complete version*: Will return an error if there's not enough input data.
///
@@ -31,36 +30,38 @@ use crate::Parser;
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}};
/// # use winnow::ascii::crlf;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// crlf(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// crlf.parse_next(input)
/// }
///
-/// assert_eq!(parser("\r\nc"), Ok(("c", "\r\n")));
-/// assert_eq!(parser("ab\r\nc"), Err(ErrMode::Backtrack(Error::new("ab\r\nc", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("\r\nc"), Ok(("c", "\r\n")));
+/// assert_eq!(parser.parse_peek("ab\r\nc"), Err(ErrMode::Backtrack(InputError::new("ab\r\nc", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::crlf;
-/// assert_eq!(crlf::<_, Error<_>>(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
-/// assert_eq!(crlf::<_, Error<_>>(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
-/// assert_eq!(crlf::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(2))));
+/// assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
+/// assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
+/// assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(2))));
/// ```
#[inline(always)]
-pub fn crlf<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn crlf<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
I: Compare<&'static str>,
{
- trace("crlf", move |input: I| "\r\n".parse_next(input)).parse_next(input)
+ trace("crlf", "\r\n").parse_next(input)
}
-/// Recognizes a string of any char except '\r\n' or '\n'.
+/// Recognizes a string of any char except `"\r\n"` or `"\n"`.
///
/// *Complete version*: Will return an error if there's not enough input data.
///
@@ -69,39 +70,41 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::not_line_ending;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// not_line_ending(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// not_line_ending.parse_next(input)
/// }
///
-/// assert_eq!(parser("ab\r\nc"), Ok(("\r\nc", "ab")));
-/// assert_eq!(parser("ab\nc"), Ok(("\nc", "ab")));
-/// assert_eq!(parser("abc"), Ok(("", "abc")));
-/// assert_eq!(parser(""), Ok(("", "")));
-/// assert_eq!(parser("a\rb\nc"), Err(ErrMode::Backtrack(Error { input: "a\rb\nc", kind: ErrorKind::Tag })));
-/// assert_eq!(parser("a\rbc"), Err(ErrMode::Backtrack(Error { input: "a\rbc", kind: ErrorKind::Tag })));
+/// assert_eq!(parser.parse_peek("ab\r\nc"), Ok(("\r\nc", "ab")));
+/// assert_eq!(parser.parse_peek("ab\nc"), Ok(("\nc", "ab")));
+/// assert_eq!(parser.parse_peek("abc"), Ok(("", "abc")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("a\rb\nc"), Err(ErrMode::Backtrack(InputError::new("\rb\nc", ErrorKind::Tag ))));
+/// assert_eq!(parser.parse_peek("a\rbc"), Err(ErrMode::Backtrack(InputError::new("\rbc", ErrorKind::Tag ))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::not_line_ending;
-/// assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("ab\r\nc")), Ok((Partial::new("\r\nc"), "ab")));
-/// assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("abc")), Err(ErrMode::Incomplete(Needed::Unknown)));
-/// assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::Unknown)));
-/// assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("a\rb\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("a\rb\nc"), ErrorKind::Tag ))));
-/// assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("a\rbc")), Err(ErrMode::Backtrack(Error::new(Partial::new("a\rbc"), ErrorKind::Tag ))));
+/// assert_eq!(not_line_ending::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Ok((Partial::new("\r\nc"), "ab")));
+/// assert_eq!(not_line_ending::<_, InputError<_>>.parse_peek(Partial::new("abc")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(not_line_ending::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(not_line_ending::<_, InputError<_>>.parse_peek(Partial::new("a\rb\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\rb\nc"), ErrorKind::Tag ))));
+/// assert_eq!(not_line_ending::<_, InputError<_>>.parse_peek(Partial::new("a\rbc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\rbc"), ErrorKind::Tag ))));
/// ```
#[inline(always)]
-pub fn not_line_ending<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn not_line_ending<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
- I: Stream + AsBStr,
+ I: Stream,
I: Compare<&'static str>,
- <I as Stream>::Token: AsChar,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("not_line_ending", move |input: I| {
+ trace("not_line_ending", move |input: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
not_line_ending_::<_, _, true>(input)
} else {
@@ -111,45 +114,34 @@ where
.parse_next(input)
}
-fn not_line_ending_<I, E: ParseError<I>, const PARTIAL: bool>(
- input: I,
-) -> IResult<I, <I as Stream>::Slice, E>
+fn not_line_ending_<I, E: ParserError<I>, const PARTIAL: bool>(
+ input: &mut I,
+) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
- I: Stream + AsBStr,
+ I: Stream,
I: Compare<&'static str>,
- <I as Stream>::Token: AsChar,
+ <I as Stream>::Token: AsChar + Clone,
{
- match input.offset_for(|item| {
- let c = item.as_char();
- c == '\r' || c == '\n'
- }) {
- None if PARTIAL && input.is_partial() => Err(ErrMode::Incomplete(Needed::Unknown)),
- None => Ok(input.next_slice(input.eof_offset())),
- Some(offset) => {
- let (new_input, res) = input.next_slice(offset);
- let bytes = new_input.as_bstr();
- let nth = bytes[0];
- if nth == b'\r' {
- let comp = new_input.compare("\r\n");
- match comp {
- //FIXME: calculate the right index
- CompareResult::Ok => {}
- CompareResult::Incomplete if PARTIAL && input.is_partial() => {
- return Err(ErrMode::Incomplete(Needed::Unknown));
- }
- CompareResult::Incomplete | CompareResult::Error => {
- let e: ErrorKind = ErrorKind::Tag;
- return Err(ErrMode::from_error_kind(input, e));
- }
- }
+ let res = take_till0(('\r', '\n')).parse_next(input)?;
+ if input.compare("\r") == CompareResult::Ok {
+ let comp = input.compare("\r\n");
+ match comp {
+ //FIXME: calculate the right index
+ CompareResult::Ok => {}
+ CompareResult::Incomplete if PARTIAL && input.is_partial() => {
+ return Err(ErrMode::Incomplete(Needed::Unknown));
+ }
+ CompareResult::Incomplete | CompareResult::Error => {
+ let e: ErrorKind = ErrorKind::Tag;
+ return Err(ErrMode::from_error_kind(input, e));
}
- Ok((new_input, res))
}
}
+ Ok(res)
}
-/// Recognizes an end of line (both '\n' and '\r\n').
+/// Recognizes an end of line (both `"\n"` and `"\r\n"`).
///
/// *Complete version*: Will return an error if there's not enough input data.
///
@@ -158,39 +150,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::line_ending;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// line_ending(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// line_ending.parse_next(input)
/// }
///
-/// assert_eq!(parser("\r\nc"), Ok(("c", "\r\n")));
-/// assert_eq!(parser("ab\r\nc"), Err(ErrMode::Backtrack(Error::new("ab\r\nc", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("\r\nc"), Ok(("c", "\r\n")));
+/// assert_eq!(parser.parse_peek("ab\r\nc"), Err(ErrMode::Backtrack(InputError::new("ab\r\nc", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::line_ending;
-/// assert_eq!(line_ending::<_, Error<_>>(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
-/// assert_eq!(line_ending::<_, Error<_>>(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
-/// assert_eq!(line_ending::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
+/// assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
+/// assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn line_ending<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn line_ending<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
I: Compare<&'static str>,
{
- trace("line_ending", move |input: I| {
- alt(("\n", "\r\n")).parse_next(input)
- })
- .parse_next(input)
+ trace("line_ending", alt(("\n", "\r\n"))).parse_next(input)
}
-/// Matches a newline character '\n'.
+/// Matches a newline character `'\n'`.
///
/// *Complete version*: Will return an error if there's not enough input data.
///
@@ -199,40 +190,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::newline;
-/// fn parser(input: &str) -> IResult<&str, char> {
-/// newline(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<char, InputError<&'s str>> {
+/// newline.parse_next(input)
/// }
///
-/// assert_eq!(parser("\nc"), Ok(("c", '\n')));
-/// assert_eq!(parser("\r\nc"), Err(ErrMode::Backtrack(Error::new("\r\nc", ErrorKind::Verify))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(parser.parse_peek("\nc"), Ok(("c", '\n')));
+/// assert_eq!(parser.parse_peek("\r\nc"), Err(ErrMode::Backtrack(InputError::new("\r\nc", ErrorKind::Verify))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::newline;
-/// assert_eq!(newline::<_, Error<_>>(Partial::new("\nc")), Ok((Partial::new("c"), '\n')));
-/// assert_eq!(newline::<_, Error<_>>(Partial::new("\r\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("\r\nc"), ErrorKind::Verify))));
-/// assert_eq!(newline::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("\nc")), Ok((Partial::new("c"), '\n')));
+/// assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\r\nc"), ErrorKind::Verify))));
+/// assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn newline<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
+pub fn newline<I, Error: ParserError<I>>(input: &mut I) -> PResult<char, Error>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("newline", move |input: I| {
- '\n'.map(|c: <I as Stream>::Token| c.as_char())
- .parse_next(input)
- })
- .parse_next(input)
+ trace("newline", '\n'.map(AsChar::as_char)).parse_next(input)
}
-/// Matches a tab character '\t'.
+/// Matches a tab character `'\t'`.
///
/// *Complete version*: Will return an error if there's not enough input data.
///
@@ -241,40 +230,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::tab;
-/// fn parser(input: &str) -> IResult<&str, char> {
-/// tab(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<char, InputError<&'s str>> {
+/// tab.parse_next(input)
/// }
///
-/// assert_eq!(parser("\tc"), Ok(("c", '\t')));
-/// assert_eq!(parser("\r\nc"), Err(ErrMode::Backtrack(Error::new("\r\nc", ErrorKind::Verify))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(parser.parse_peek("\tc"), Ok(("c", '\t')));
+/// assert_eq!(parser.parse_peek("\r\nc"), Err(ErrMode::Backtrack(InputError::new("\r\nc", ErrorKind::Verify))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::tab;
-/// assert_eq!(tab::<_, Error<_>>(Partial::new("\tc")), Ok((Partial::new("c"), '\t')));
-/// assert_eq!(tab::<_, Error<_>>(Partial::new("\r\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("\r\nc"), ErrorKind::Verify))));
-/// assert_eq!(tab::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(tab::<_, InputError<_>>.parse_peek(Partial::new("\tc")), Ok((Partial::new("c"), '\t')));
+/// assert_eq!(tab::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\r\nc"), ErrorKind::Verify))));
+/// assert_eq!(tab::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn tab<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
+pub fn tab<I, Error: ParserError<I>>(input: &mut I) -> PResult<char, Error>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("tab", move |input: I| {
- '\t'.map(|c: <I as Stream>::Token| c.as_char())
- .parse_next(input)
- })
- .parse_next(input)
+ trace("tab", '\t'.map(AsChar::as_char)).parse_next(input)
}
-/// Recognizes zero or more lowercase and uppercase ASCII alphabetic characters: a-z, A-Z
+/// Recognizes zero or more lowercase and uppercase ASCII alphabetic characters: `'a'..='z'`, `'A'..='Z'`
///
/// *Complete version*: Will return the whole input if no terminating token is found (a non
/// alphabetic character).
@@ -285,39 +272,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::alpha0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// alpha0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// alpha0.parse_next(input)
/// }
///
-/// assert_eq!(parser("ab1c"), Ok(("1c", "ab")));
-/// assert_eq!(parser("1c"), Ok(("1c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("ab1c"), Ok(("1c", "ab")));
+/// assert_eq!(parser.parse_peek("1c"), Ok(("1c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::alpha0;
-/// assert_eq!(alpha0::<_, Error<_>>(Partial::new("ab1c")), Ok((Partial::new("1c"), "ab")));
-/// assert_eq!(alpha0::<_, Error<_>>(Partial::new("1c")), Ok((Partial::new("1c"), "")));
-/// assert_eq!(alpha0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(alpha0::<_, InputError<_>>.parse_peek(Partial::new("ab1c")), Ok((Partial::new("1c"), "ab")));
+/// assert_eq!(alpha0::<_, InputError<_>>.parse_peek(Partial::new("1c")), Ok((Partial::new("1c"), "")));
+/// assert_eq!(alpha0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn alpha0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn alpha0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("alpha0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| c.is_alpha()).parse_next(input)
- })
- .parse_next(input)
+ trace("alpha0", take_while(0.., AsChar::is_alpha)).parse_next(input)
}
-/// Recognizes one or more lowercase and uppercase ASCII alphabetic characters: a-z, A-Z
+/// Recognizes one or more lowercase and uppercase ASCII alphabetic characters: `'a'..='z'`, `'A'..='Z'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non alphabetic character).
@@ -328,39 +314,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::alpha1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// alpha1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// alpha1.parse_next(input)
/// }
///
-/// assert_eq!(parser("aB1c"), Ok(("1c", "aB")));
-/// assert_eq!(parser("1c"), Err(ErrMode::Backtrack(Error::new("1c", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("aB1c"), Ok(("1c", "aB")));
+/// assert_eq!(parser.parse_peek("1c"), Err(ErrMode::Backtrack(InputError::new("1c", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::alpha1;
-/// assert_eq!(alpha1::<_, Error<_>>(Partial::new("aB1c")), Ok((Partial::new("1c"), "aB")));
-/// assert_eq!(alpha1::<_, Error<_>>(Partial::new("1c")), Err(ErrMode::Backtrack(Error::new(Partial::new("1c"), ErrorKind::Slice))));
-/// assert_eq!(alpha1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(alpha1::<_, InputError<_>>.parse_peek(Partial::new("aB1c")), Ok((Partial::new("1c"), "aB")));
+/// assert_eq!(alpha1::<_, InputError<_>>.parse_peek(Partial::new("1c")), Err(ErrMode::Backtrack(InputError::new(Partial::new("1c"), ErrorKind::Slice))));
+/// assert_eq!(alpha1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn alpha1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn alpha1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("alpha1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| c.is_alpha()).parse_next(input)
- })
- .parse_next(input)
+ trace("alpha1", take_while(1.., AsChar::is_alpha)).parse_next(input)
}
-/// Recognizes zero or more ASCII numerical characters: 0-9
+/// Recognizes zero or more ASCII numerical characters: `'0'..='9'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non digit character).
@@ -371,40 +356,39 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::digit0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// digit0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// digit0.parse_next(input)
/// }
///
-/// assert_eq!(parser("21c"), Ok(("c", "21")));
-/// assert_eq!(parser("21"), Ok(("", "21")));
-/// assert_eq!(parser("a21c"), Ok(("a21c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("21c"), Ok(("c", "21")));
+/// assert_eq!(parser.parse_peek("21"), Ok(("", "21")));
+/// assert_eq!(parser.parse_peek("a21c"), Ok(("a21c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::digit0;
-/// assert_eq!(digit0::<_, Error<_>>(Partial::new("21c")), Ok((Partial::new("c"), "21")));
-/// assert_eq!(digit0::<_, Error<_>>(Partial::new("a21c")), Ok((Partial::new("a21c"), "")));
-/// assert_eq!(digit0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(digit0::<_, InputError<_>>.parse_peek(Partial::new("21c")), Ok((Partial::new("c"), "21")));
+/// assert_eq!(digit0::<_, InputError<_>>.parse_peek(Partial::new("a21c")), Ok((Partial::new("a21c"), "")));
+/// assert_eq!(digit0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn digit0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn digit0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("digit0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| c.is_dec_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("digit0", take_while(0.., AsChar::is_dec_digit)).parse_next(input)
}
-/// Recognizes one or more ASCII numerical characters: 0-9
+/// Recognizes one or more ASCII numerical characters: `'0'..='9'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non digit character).
@@ -415,24 +399,26 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::digit1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// digit1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// digit1.parse_next(input)
/// }
///
-/// assert_eq!(parser("21c"), Ok(("c", "21")));
-/// assert_eq!(parser("c1"), Err(ErrMode::Backtrack(Error::new("c1", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("21c"), Ok(("c", "21")));
+/// assert_eq!(parser.parse_peek("c1"), Err(ErrMode::Backtrack(InputError::new("c1", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::digit1;
-/// assert_eq!(digit1::<_, Error<_>>(Partial::new("21c")), Ok((Partial::new("c"), "21")));
-/// assert_eq!(digit1::<_, Error<_>>(Partial::new("c1")), Err(ErrMode::Backtrack(Error::new(Partial::new("c1"), ErrorKind::Slice))));
-/// assert_eq!(digit1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(digit1::<_, InputError<_>>.parse_peek(Partial::new("21c")), Ok((Partial::new("c"), "21")));
+/// assert_eq!(digit1::<_, InputError<_>>.parse_peek(Partial::new("c1")), Err(ErrMode::Backtrack(InputError::new(Partial::new("c1"), ErrorKind::Slice))));
+/// assert_eq!(digit1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
///
/// ## Parsing an integer
@@ -440,30 +426,29 @@ where
/// You can use `digit1` in combination with [`Parser::try_map`][crate::Parser::try_map] to parse an integer:
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed, Parser};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed, Parser};
/// # use winnow::ascii::digit1;
-/// fn parser(input: &str) -> IResult<&str, u32> {
+/// fn parser<'s>(input: &mut &'s str) -> PResult<u32, InputError<&'s str>> {
/// digit1.try_map(str::parse).parse_next(input)
/// }
///
-/// assert_eq!(parser("416"), Ok(("", 416)));
-/// assert_eq!(parser("12b"), Ok(("b", 12)));
-/// assert!(parser("b").is_err());
+/// assert_eq!(parser.parse_peek("416"), Ok(("", 416)));
+/// assert_eq!(parser.parse_peek("12b"), Ok(("b", 12)));
+/// assert!(parser.parse_peek("b").is_err());
/// ```
#[inline(always)]
-pub fn digit1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn digit1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("digit1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| c.is_dec_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("digit1", take_while(1.., AsChar::is_dec_digit)).parse_next(input)
}
-/// Recognizes zero or more ASCII hexadecimal numerical characters: 0-9, A-F, a-f
+/// Recognizes zero or more ASCII hexadecimal numerical characters: `'0'..='9'`, `'A'..='F'`,
+/// `'a'..='f'`
///
/// *Complete version*: Will return the whole input if no terminating token is found (a non hexadecimal digit character).
///
@@ -473,39 +458,39 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::hex_digit0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// hex_digit0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// hex_digit0.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ"), Ok(("Z", "21c")));
-/// assert_eq!(parser("Z21c"), Ok(("Z21c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("21cZ"), Ok(("Z", "21c")));
+/// assert_eq!(parser.parse_peek("Z21c"), Ok(("Z21c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::hex_digit0;
-/// assert_eq!(hex_digit0::<_, Error<_>>(Partial::new("21cZ")), Ok((Partial::new("Z"), "21c")));
-/// assert_eq!(hex_digit0::<_, Error<_>>(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
-/// assert_eq!(hex_digit0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(hex_digit0::<_, InputError<_>>.parse_peek(Partial::new("21cZ")), Ok((Partial::new("Z"), "21c")));
+/// assert_eq!(hex_digit0::<_, InputError<_>>.parse_peek(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
+/// assert_eq!(hex_digit0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn hex_digit0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn hex_digit0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("hex_digit0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| c.is_hex_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("hex_digit0", take_while(0.., AsChar::is_hex_digit)).parse_next(input)
}
-/// Recognizes one or more ASCII hexadecimal numerical characters: 0-9, A-F, a-f
+/// Recognizes one or more ASCII hexadecimal numerical characters: `'0'..='9'`, `'A'..='F'`,
+/// `'a'..='f'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non hexadecimal digit character).
@@ -516,39 +501,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::hex_digit1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// hex_digit1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// hex_digit1.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ"), Ok(("Z", "21c")));
-/// assert_eq!(parser("H2"), Err(ErrMode::Backtrack(Error::new("H2", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("21cZ"), Ok(("Z", "21c")));
+/// assert_eq!(parser.parse_peek("H2"), Err(ErrMode::Backtrack(InputError::new("H2", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::hex_digit1;
-/// assert_eq!(hex_digit1::<_, Error<_>>(Partial::new("21cZ")), Ok((Partial::new("Z"), "21c")));
-/// assert_eq!(hex_digit1::<_, Error<_>>(Partial::new("H2")), Err(ErrMode::Backtrack(Error::new(Partial::new("H2"), ErrorKind::Slice))));
-/// assert_eq!(hex_digit1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(Partial::new("21cZ")), Ok((Partial::new("Z"), "21c")));
+/// assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(Partial::new("H2")), Err(ErrMode::Backtrack(InputError::new(Partial::new("H2"), ErrorKind::Slice))));
+/// assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn hex_digit1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn hex_digit1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("hex_digit1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| c.is_hex_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("hex_digit1", take_while(1.., AsChar::is_hex_digit)).parse_next(input)
}
-/// Recognizes zero or more octal characters: 0-7
+/// Recognizes zero or more octal characters: `'0'..='7'`
///
/// *Complete version*: Will return the whole input if no terminating token is found (a non octal
/// digit character).
@@ -559,39 +543,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::oct_digit0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// oct_digit0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// oct_digit0.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ"), Ok(("cZ", "21")));
-/// assert_eq!(parser("Z21c"), Ok(("Z21c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("21cZ"), Ok(("cZ", "21")));
+/// assert_eq!(parser.parse_peek("Z21c"), Ok(("Z21c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::oct_digit0;
-/// assert_eq!(oct_digit0::<_, Error<_>>(Partial::new("21cZ")), Ok((Partial::new("cZ"), "21")));
-/// assert_eq!(oct_digit0::<_, Error<_>>(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
-/// assert_eq!(oct_digit0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(oct_digit0::<_, InputError<_>>.parse_peek(Partial::new("21cZ")), Ok((Partial::new("cZ"), "21")));
+/// assert_eq!(oct_digit0::<_, InputError<_>>.parse_peek(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
+/// assert_eq!(oct_digit0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn oct_digit0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn oct_digit0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("oct_digit0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| c.is_oct_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("oct_digit0", take_while(0.., AsChar::is_oct_digit)).parse_next(input)
}
-/// Recognizes one or more octal characters: 0-7
+/// Recognizes one or more octal characters: `'0'..='7'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non octal digit character).
@@ -602,39 +585,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::oct_digit1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// oct_digit1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// oct_digit1.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ"), Ok(("cZ", "21")));
-/// assert_eq!(parser("H2"), Err(ErrMode::Backtrack(Error::new("H2", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("21cZ"), Ok(("cZ", "21")));
+/// assert_eq!(parser.parse_peek("H2"), Err(ErrMode::Backtrack(InputError::new("H2", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::oct_digit1;
-/// assert_eq!(oct_digit1::<_, Error<_>>(Partial::new("21cZ")), Ok((Partial::new("cZ"), "21")));
-/// assert_eq!(oct_digit1::<_, Error<_>>(Partial::new("H2")), Err(ErrMode::Backtrack(Error::new(Partial::new("H2"), ErrorKind::Slice))));
-/// assert_eq!(oct_digit1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(oct_digit1::<_, InputError<_>>.parse_peek(Partial::new("21cZ")), Ok((Partial::new("cZ"), "21")));
+/// assert_eq!(oct_digit1::<_, InputError<_>>.parse_peek(Partial::new("H2")), Err(ErrMode::Backtrack(InputError::new(Partial::new("H2"), ErrorKind::Slice))));
+/// assert_eq!(oct_digit1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn oct_digit1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn oct_digit1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("oct_digit0", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| c.is_oct_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("oct_digit0", take_while(1.., AsChar::is_oct_digit)).parse_next(input)
}
-/// Recognizes zero or more ASCII numerical and alphabetic characters: 0-9, a-z, A-Z
+/// Recognizes zero or more ASCII numerical and alphabetic characters: `'a'..='z'`, `'A'..='Z'`, `'0'..='9'`
///
/// *Complete version*: Will return the whole input if no terminating token is found (a non
/// alphanumerical character).
@@ -645,39 +627,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::alphanumeric0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// alphanumeric0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// alphanumeric0.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ%1"), Ok(("%1", "21cZ")));
-/// assert_eq!(parser("&Z21c"), Ok(("&Z21c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("21cZ%1"), Ok(("%1", "21cZ")));
+/// assert_eq!(parser.parse_peek("&Z21c"), Ok(("&Z21c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::alphanumeric0;
-/// assert_eq!(alphanumeric0::<_, Error<_>>(Partial::new("21cZ%1")), Ok((Partial::new("%1"), "21cZ")));
-/// assert_eq!(alphanumeric0::<_, Error<_>>(Partial::new("&Z21c")), Ok((Partial::new("&Z21c"), "")));
-/// assert_eq!(alphanumeric0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(alphanumeric0::<_, InputError<_>>.parse_peek(Partial::new("21cZ%1")), Ok((Partial::new("%1"), "21cZ")));
+/// assert_eq!(alphanumeric0::<_, InputError<_>>.parse_peek(Partial::new("&Z21c")), Ok((Partial::new("&Z21c"), "")));
+/// assert_eq!(alphanumeric0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn alphanumeric0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn alphanumeric0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("alphanumeric0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| c.is_alphanum()).parse_next(input)
- })
- .parse_next(input)
+ trace("alphanumeric0", take_while(0.., AsChar::is_alphanum)).parse_next(input)
}
-/// Recognizes one or more ASCII numerical and alphabetic characters: 0-9, a-z, A-Z
+/// Recognizes one or more ASCII numerical and alphabetic characters: `'a'..='z'`, `'A'..='Z'`, `'0'..='9'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non alphanumerical character).
@@ -688,36 +669,35 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::alphanumeric1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// alphanumeric1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// alphanumeric1.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ%1"), Ok(("%1", "21cZ")));
-/// assert_eq!(parser("&H2"), Err(ErrMode::Backtrack(Error::new("&H2", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("21cZ%1"), Ok(("%1", "21cZ")));
+/// assert_eq!(parser.parse_peek("&H2"), Err(ErrMode::Backtrack(InputError::new("&H2", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::alphanumeric1;
-/// assert_eq!(alphanumeric1::<_, Error<_>>(Partial::new("21cZ%1")), Ok((Partial::new("%1"), "21cZ")));
-/// assert_eq!(alphanumeric1::<_, Error<_>>(Partial::new("&H2")), Err(ErrMode::Backtrack(Error::new(Partial::new("&H2"), ErrorKind::Slice))));
-/// assert_eq!(alphanumeric1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new("21cZ%1")), Ok((Partial::new("%1"), "21cZ")));
+/// assert_eq!(alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new("&H2")), Err(ErrMode::Backtrack(InputError::new(Partial::new("&H2"), ErrorKind::Slice))));
+/// assert_eq!(alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn alphanumeric1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn alphanumeric1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("alphanumeric1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| c.is_alphanum()).parse_next(input)
- })
- .parse_next(input)
+ trace("alphanumeric1", take_while(1.., AsChar::is_alphanum)).parse_next(input)
}
/// Recognizes zero or more spaces and tabs.
@@ -731,34 +711,28 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::space0;
-/// assert_eq!(space0::<_, Error<_>>(Partial::new(" \t21c")), Ok((Partial::new("21c"), " \t")));
-/// assert_eq!(space0::<_, Error<_>>(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
-/// assert_eq!(space0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(space0::<_, InputError<_>>.parse_peek(Partial::new(" \t21c")), Ok((Partial::new("21c"), " \t")));
+/// assert_eq!(space0::<_, InputError<_>>.parse_peek(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
+/// assert_eq!(space0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn space0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn space0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("space0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| {
- let ch = c.as_char();
- matches!(ch, ' ' | '\t')
- })
- .parse_next(input)
- })
- .parse_next(input)
+ trace("space0", take_while(0.., AsChar::is_space)).parse_next(input)
}
-/// Recognizes one or more spaces and tabs.
+/// Recognizes zero or more spaces and tabs.
///
-/// *Complete version*: Will return an error if there's not enough input data,
-/// or the whole input if no terminating token is found (a non space character).
+/// *Complete version*: Will return the whole input if no terminating token is found (a non space
+/// character).
///
/// *Partial version*: Will return `Err(winnow::error::ErrMode::Incomplete(_))` if there's not enough input data,
/// or if no terminating token is found (a non space character).
@@ -766,40 +740,35 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::space1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// space1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// space1.parse_next(input)
/// }
///
-/// assert_eq!(parser(" \t21c"), Ok(("21c", " \t")));
-/// assert_eq!(parser("H2"), Err(ErrMode::Backtrack(Error::new("H2", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(" \t21c"), Ok(("21c", " \t")));
+/// assert_eq!(parser.parse_peek("H2"), Err(ErrMode::Backtrack(InputError::new("H2", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::space1;
-/// assert_eq!(space1::<_, Error<_>>(Partial::new(" \t21c")), Ok((Partial::new("21c"), " \t")));
-/// assert_eq!(space1::<_, Error<_>>(Partial::new("H2")), Err(ErrMode::Backtrack(Error::new(Partial::new("H2"), ErrorKind::Slice))));
-/// assert_eq!(space1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(space1::<_, InputError<_>>.parse_peek(Partial::new(" \t21c")), Ok((Partial::new("21c"), " \t")));
+/// assert_eq!(space1::<_, InputError<_>>.parse_peek(Partial::new("H2")), Err(ErrMode::Backtrack(InputError::new(Partial::new("H2"), ErrorKind::Slice))));
+/// assert_eq!(space1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn space1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn space1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("space1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| {
- let ch = c.as_char();
- matches!(ch, ' ' | '\t')
- })
- .parse_next(input)
- })
- .parse_next(input)
+ trace("space1", take_while(1.., AsChar::is_space)).parse_next(input)
}
/// Recognizes zero or more spaces, tabs, carriage returns and line feeds.
@@ -813,40 +782,35 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::multispace0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// multispace0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// multispace0.parse_next(input)
/// }
///
-/// assert_eq!(parser(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
-/// assert_eq!(parser("Z21c"), Ok(("Z21c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
+/// assert_eq!(parser.parse_peek("Z21c"), Ok(("Z21c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::multispace0;
-/// assert_eq!(multispace0::<_, Error<_>>(Partial::new(" \t\n\r21c")), Ok((Partial::new("21c"), " \t\n\r")));
-/// assert_eq!(multispace0::<_, Error<_>>(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
-/// assert_eq!(multispace0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(multispace0::<_, InputError<_>>.parse_peek(Partial::new(" \t\n\r21c")), Ok((Partial::new("21c"), " \t\n\r")));
+/// assert_eq!(multispace0::<_, InputError<_>>.parse_peek(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
+/// assert_eq!(multispace0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn multispace0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn multispace0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("multispace0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| {
- let ch = c.as_char();
- matches!(ch, ' ' | '\t' | '\r' | '\n')
- })
- .parse_next(input)
- })
- .parse_next(input)
+ trace("multispace0", take_while(0.., (' ', '\t', '\r', '\n'))).parse_next(input)
}
/// Recognizes one or more spaces, tabs, carriage returns and line feeds.
@@ -860,43 +824,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::multispace1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// multispace1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// multispace1.parse_next(input)
/// }
///
-/// assert_eq!(parser(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
-/// assert_eq!(parser("H2"), Err(ErrMode::Backtrack(Error::new("H2", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
+/// assert_eq!(parser.parse_peek("H2"), Err(ErrMode::Backtrack(InputError::new("H2", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::multispace1;
-/// assert_eq!(multispace1::<_, Error<_>>(Partial::new(" \t\n\r21c")), Ok((Partial::new("21c"), " \t\n\r")));
-/// assert_eq!(multispace1::<_, Error<_>>(Partial::new("H2")), Err(ErrMode::Backtrack(Error::new(Partial::new("H2"), ErrorKind::Slice))));
-/// assert_eq!(multispace1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(multispace1::<_, InputError<_>>.parse_peek(Partial::new(" \t\n\r21c")), Ok((Partial::new("21c"), " \t\n\r")));
+/// assert_eq!(multispace1::<_, InputError<_>>.parse_peek(Partial::new("H2")), Err(ErrMode::Backtrack(InputError::new(Partial::new("H2"), ErrorKind::Slice))));
+/// assert_eq!(multispace1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn multispace1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn multispace1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("multispace1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| {
- let ch = c.as_char();
- matches!(ch, ' ' | '\t' | '\r' | '\n')
- })
- .parse_next(input)
- })
- .parse_next(input)
+ trace("multispace1", take_while(1.., (' ', '\t', '\r', '\n'))).parse_next(input)
}
-/// Decode a decimal unsigned integer
+/// Decode a decimal unsigned integer (e.g. [`u32`])
///
/// *Complete version*: can parse until the end of input.
///
@@ -906,14 +865,14 @@ where
#[doc(alias = "u32")]
#[doc(alias = "u64")]
#[doc(alias = "u128")]
-pub fn dec_uint<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
+pub fn dec_uint<I, O, E: ParserError<I>>(input: &mut I) -> PResult<O, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
O: Uint,
{
- trace("dec_uint", move |input: I| {
+ trace("dec_uint", move |input: &mut I| {
if input.eof_offset() == 0 {
if <I as StreamIsPartial>::is_partial_supported() && input.is_partial() {
return Err(ErrMode::Incomplete(Needed::new(1)));
@@ -936,7 +895,8 @@ where
if offset == 0 {
return Err(ErrMode::from_error_kind(input, ErrorKind::Slice));
} else {
- return Ok((input.next_slice(offset).0, value));
+ let _ = input.next_slice(offset);
+ return Ok(value);
}
}
}
@@ -945,7 +905,8 @@ where
if <I as StreamIsPartial>::is_partial_supported() && input.is_partial() {
Err(ErrMode::Incomplete(Needed::new(1)))
} else {
- Ok((input.next_slice(input.eof_offset()).0, value))
+ let _ = input.finish();
+ Ok(value)
}
})
.parse_next(input)
@@ -1049,7 +1010,7 @@ impl Uint for i128 {
}
}
-/// Decode a decimal signed integer
+/// Decode a decimal signed integer (e.g. [`i32`])
///
/// *Complete version*: can parse until the end of input.
///
@@ -1059,19 +1020,19 @@ impl Uint for i128 {
#[doc(alias = "i32")]
#[doc(alias = "i64")]
#[doc(alias = "i128")]
-pub fn dec_int<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
+pub fn dec_int<I, O, E: ParserError<I>>(input: &mut I) -> PResult<O, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
O: Int,
{
- trace("dec_int", move |input: I| {
+ trace("dec_int", move |input: &mut I| {
fn sign(token: impl AsChar) -> bool {
let token = token.as_char();
token == '+' || token == '-'
}
- let (input, sign) = opt(crate::token::one_of(sign).map(AsChar::as_char))
+ let sign = opt(crate::token::one_of(sign).map(AsChar::as_char))
.map(|c| c != Some('-'))
.parse_next(input)?;
@@ -1101,7 +1062,8 @@ where
if offset == 0 {
return Err(ErrMode::from_error_kind(input, ErrorKind::Slice));
} else {
- return Ok((input.next_slice(offset).0, value));
+ let _ = input.next_slice(offset);
+ return Ok(value);
}
}
}
@@ -1110,7 +1072,8 @@ where
if <I as StreamIsPartial>::is_partial_supported() && input.is_partial() {
Err(ErrMode::Incomplete(Needed::new(1)))
} else {
- Ok((input.next_slice(input.eof_offset()).0, value))
+ let _ = input.finish();
+ Ok(value)
}
})
.parse_next(input)
@@ -1152,7 +1115,7 @@ impl Int for i128 {
}
}
-/// Decode a variable-width hexadecimal integer.
+/// Decode a variable-width hexadecimal integer (e.g. [`u32`])
///
/// *Complete version*: Will parse until the end of input if it has fewer characters than the type
/// supports.
@@ -1164,34 +1127,34 @@ impl Int for i128 {
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// use winnow::ascii::hex_uint;
///
-/// fn parser(s: &[u8]) -> IResult<&[u8], u32> {
+/// fn parser<'s>(s: &mut &'s [u8]) -> PResult<u32, InputError<&'s [u8]>> {
/// hex_uint(s)
/// }
///
-/// assert_eq!(parser(&b"01AE"[..]), Ok((&b""[..], 0x01AE)));
-/// assert_eq!(parser(&b"abc"[..]), Ok((&b""[..], 0x0ABC)));
-/// assert_eq!(parser(&b"ggg"[..]), Err(ErrMode::Backtrack(Error::new(&b"ggg"[..], ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(&b"01AE"[..]), Ok((&b""[..], 0x01AE)));
+/// assert_eq!(parser.parse_peek(&b"abc"[..]), Ok((&b""[..], 0x0ABC)));
+/// assert_eq!(parser.parse_peek(&b"ggg"[..]), Err(ErrMode::Backtrack(InputError::new(&b"ggg"[..], ErrorKind::Slice))));
/// ```
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// use winnow::ascii::hex_uint;
///
-/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> {
+/// fn parser<'s>(s: &mut Partial<&'s [u8]>) -> PResult<u32, InputError<Partial<&'s [u8]>>> {
/// hex_uint(s)
/// }
///
-/// assert_eq!(parser(Partial::new(&b"01AE;"[..])), Ok((Partial::new(&b";"[..]), 0x01AE)));
-/// assert_eq!(parser(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
-/// assert_eq!(parser(Partial::new(&b"ggg"[..])), Err(ErrMode::Backtrack(Error::new(Partial::new(&b"ggg"[..]), ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(Partial::new(&b"01AE;"[..])), Ok((Partial::new(&b";"[..]), 0x01AE)));
+/// assert_eq!(parser.parse_peek(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(parser.parse_peek(Partial::new(&b"ggg"[..])), Err(ErrMode::Backtrack(InputError::new(Partial::new(&b"ggg"[..]), ErrorKind::Slice))));
/// ```
#[inline]
-pub fn hex_uint<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
+pub fn hex_uint<I, O, E: ParserError<I>>(input: &mut I) -> PResult<O, E>
where
I: StreamIsPartial,
I: Stream,
@@ -1199,7 +1162,7 @@ where
<I as Stream>::Token: AsChar,
<I as Stream>::Slice: AsBStr,
{
- trace("hex_uint", move |input: I| {
+ trace("hex_uint", move |input: &mut I| {
let invalid_offset = input
.offset_for(|c| {
let c = c.as_char();
@@ -1233,7 +1196,7 @@ where
// Must be at least one digit
return Err(ErrMode::from_error_kind(input, ErrorKind::Slice));
}
- let (remaining, parsed) = input.next_slice(offset);
+ let parsed = input.next_slice(offset);
let mut res = O::default();
for c in parsed.as_bstr() {
@@ -1243,7 +1206,7 @@ where
res = (res << O::from(4)) + nibble;
}
- Ok((remaining, res))
+ Ok(res)
})
.parse_next(input)
}
@@ -1291,7 +1254,7 @@ impl HexUint for u128 {
}
}
-/// Recognizes floating point number in text format and returns a f32 or f64.
+/// Recognizes floating point number in text format and returns a [`f32`] or [`f64`].
///
/// *Complete version*: Can parse until the end of input.
///
@@ -1301,99 +1264,97 @@ impl HexUint for u128 {
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::error::Needed::Size;
/// use winnow::ascii::float;
///
-/// fn parser(s: &str) -> IResult<&str, f64> {
+/// fn parser<'s>(s: &mut &'s str) -> PResult<f64, InputError<&'s str>> {
/// float(s)
/// }
///
-/// assert_eq!(parser("11e-1"), Ok(("", 1.1)));
-/// assert_eq!(parser("123E-02"), Ok(("", 1.23)));
-/// assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
-/// assert_eq!(parser("abc"), Err(ErrMode::Backtrack(Error::new("abc", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("11e-1"), Ok(("", 1.1)));
+/// assert_eq!(parser.parse_peek("123E-02"), Ok(("", 1.23)));
+/// assert_eq!(parser.parse_peek("123K-01"), Ok(("K-01", 123.0)));
+/// assert_eq!(parser.parse_peek("abc"), Err(ErrMode::Backtrack(InputError::new("abc", ErrorKind::Tag))));
/// ```
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::ascii::float;
///
-/// fn parser(s: Partial<&str>) -> IResult<Partial<&str>, f64> {
+/// fn parser<'s>(s: &mut Partial<&'s str>) -> PResult<f64, InputError<Partial<&'s str>>> {
/// float(s)
/// }
///
-/// assert_eq!(parser(Partial::new("11e-1 ")), Ok((Partial::new(" "), 1.1)));
-/// assert_eq!(parser(Partial::new("11e-1")), Err(ErrMode::Incomplete(Needed::new(1))));
-/// assert_eq!(parser(Partial::new("123E-02")), Err(ErrMode::Incomplete(Needed::new(1))));
-/// assert_eq!(parser(Partial::new("123K-01")), Ok((Partial::new("K-01"), 123.0)));
-/// assert_eq!(parser(Partial::new("abc")), Err(ErrMode::Backtrack(Error::new(Partial::new("abc"), ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek(Partial::new("11e-1 ")), Ok((Partial::new(" "), 1.1)));
+/// assert_eq!(parser.parse_peek(Partial::new("11e-1")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(parser.parse_peek(Partial::new("123E-02")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(parser.parse_peek(Partial::new("123K-01")), Ok((Partial::new("K-01"), 123.0)));
+/// assert_eq!(parser.parse_peek(Partial::new("abc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("abc"), ErrorKind::Tag))));
/// ```
#[inline(always)]
#[doc(alias = "f32")]
#[doc(alias = "double")]
-pub fn float<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
+#[allow(clippy::trait_duplication_in_bounds)] // HACK: clippy 1.64.0 bug
+pub fn float<I, O, E: ParserError<I>>(input: &mut I) -> PResult<O, E>
where
I: StreamIsPartial,
I: Stream,
- I: Offset + Compare<&'static str>,
+ I: Compare<&'static str>,
<I as Stream>::Slice: ParseSlice<O>,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
<I as Stream>::IterOffsets: Clone,
I: AsBStr,
- &'static str: ContainsToken<<I as Stream>::Token>,
{
- trace("float", move |input: I| {
- let (i, s) = recognize_float_or_exceptions(input)?;
- match s.parse_slice() {
- Some(f) => Ok((i, f)),
- None => Err(ErrMode::from_error_kind(i, ErrorKind::Verify)),
- }
+ trace("float", move |input: &mut I| {
+ let s = recognize_float_or_exceptions(input)?;
+ s.parse_slice()
+ .ok_or_else(|| ErrMode::from_error_kind(input, ErrorKind::Verify))
})
.parse_next(input)
}
-fn recognize_float_or_exceptions<I, E: ParseError<I>>(
- input: I,
-) -> IResult<I, <I as Stream>::Slice, E>
+#[allow(clippy::trait_duplication_in_bounds)] // HACK: clippy 1.64.0 bug
+fn recognize_float_or_exceptions<I, E: ParserError<I>>(
+ input: &mut I,
+) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- I: Offset + Compare<&'static str>,
- <I as Stream>::Token: AsChar + Copy,
+ I: Compare<&'static str>,
+ <I as Stream>::Token: AsChar + Clone,
<I as Stream>::IterOffsets: Clone,
I: AsBStr,
- &'static str: ContainsToken<<I as Stream>::Token>,
{
alt((
recognize_float,
crate::token::tag_no_case("nan"),
- crate::token::tag_no_case("inf"),
crate::token::tag_no_case("infinity"),
+ crate::token::tag_no_case("inf"),
))
.parse_next(input)
}
-fn recognize_float<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+#[allow(clippy::trait_duplication_in_bounds)] // HACK: clippy 1.64.0 bug
+fn recognize_float<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- I: Offset + Compare<&'static str>,
- <I as Stream>::Token: AsChar + Copy,
+ I: Compare<&'static str>,
+ <I as Stream>::Token: AsChar + Clone,
<I as Stream>::IterOffsets: Clone,
I: AsBStr,
- &'static str: ContainsToken<<I as Stream>::Token>,
{
(
- opt(one_of("+-")),
+ opt(one_of(['+', '-'])),
alt((
(digit1, opt(('.', opt(digit1)))).map(|_| ()),
('.', digit1).map(|_| ()),
)),
- opt((one_of("eE"), opt(one_of("+-")), cut_err(digit1))),
+ opt((one_of(['e', 'E']), opt(one_of(['+', '-'])), cut_err(digit1))),
)
.recognize()
.parse_next(input)
@@ -1408,14 +1369,15 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed, IResult};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed, IResult};
/// # use winnow::ascii::digit1;
/// # use winnow::prelude::*;
/// use winnow::ascii::escaped;
/// use winnow::token::one_of;
///
/// fn esc(s: &str) -> IResult<&str, &str> {
-/// escaped(digit1, '\\', one_of(r#""n\"#)).parse_next(s)
+/// escaped(digit1, '\\', one_of(['"', 'n', '\\'])).parse_peek(s)
/// }
///
/// assert_eq!(esc("123;"), Ok((";", "123")));
@@ -1423,7 +1385,8 @@ where
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed, IResult};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed, IResult};
/// # use winnow::ascii::digit1;
/// # use winnow::prelude::*;
/// # use winnow::Partial;
@@ -1431,7 +1394,7 @@ where
/// use winnow::token::one_of;
///
/// fn esc(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// escaped(digit1, '\\', one_of("\"n\\")).parse_next(s)
+/// escaped(digit1, '\\', one_of(['"', 'n', '\\'])).parse_peek(s)
/// }
///
/// assert_eq!(esc(Partial::new("123;")), Ok((Partial::new(";"), "123")));
@@ -1445,13 +1408,13 @@ pub fn escaped<'a, I: 'a, Error, F, G, O1, O2>(
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: AsChar + Clone,
F: Parser<I, O1, Error>,
G: Parser<I, O2, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- trace("escaped", move |input: I| {
+ trace("escaped", move |input: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() && input.is_partial() {
streaming_escaped_internal(input, &mut normal, control_char, &mut escapable)
} else {
@@ -1461,56 +1424,41 @@ where
}
fn streaming_escaped_internal<I, Error, F, G, O1, O2>(
- input: I,
+ input: &mut I,
normal: &mut F,
control_char: char,
escapable: &mut G,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: AsChar + Clone,
F: Parser<I, O1, Error>,
G: Parser<I, O2, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- let mut i = input.clone();
+ let start = input.checkpoint();
- while i.eof_offset() > 0 {
- let current_len = i.eof_offset();
+ while input.eof_offset() > 0 {
+ let current_len = input.eof_offset();
- match normal.parse_next(i.clone()) {
- Ok((i2, _)) => {
- if i2.eof_offset() == 0 {
- return Err(ErrMode::Incomplete(Needed::Unknown));
- } else if i2.eof_offset() == current_len {
- let offset = input.offset_to(&i2);
+ match opt(normal.by_ref()).parse_next(input)? {
+ Some(_) => {
+ if input.eof_offset() == current_len {
+ let offset = input.offset_from(&start);
+ input.reset(start);
return Ok(input.next_slice(offset));
- } else {
- i = i2;
}
}
- Err(ErrMode::Backtrack(_)) => {
- if i.next_token().expect("eof_offset > 0").1.as_char() == control_char {
- let next = control_char.len_utf8();
- match escapable.parse_next(i.next_slice(next).0) {
- Ok((i2, _)) => {
- if i2.eof_offset() == 0 {
- return Err(ErrMode::Incomplete(Needed::Unknown));
- } else {
- i = i2;
- }
- }
- Err(e) => return Err(e),
- }
+ None => {
+ if opt(control_char).parse_next(input)?.is_some() {
+ let _ = escapable.parse_next(input)?;
} else {
- let offset = input.offset_to(&i);
+ let offset = input.offset_from(&start);
+ input.reset(start);
return Ok(input.next_slice(offset));
}
}
- Err(e) => {
- return Err(e);
- }
}
}
@@ -1518,62 +1466,46 @@ where
}
fn complete_escaped_internal<'a, I: 'a, Error, F, G, O1, O2>(
- input: I,
+ input: &mut I,
normal: &mut F,
control_char: char,
escapable: &mut G,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: crate::stream::AsChar + Clone,
F: Parser<I, O1, Error>,
G: Parser<I, O2, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- let mut i = input.clone();
-
- while i.eof_offset() > 0 {
- let current_len = i.eof_offset();
-
- match normal.parse_next(i.clone()) {
- Ok((i2, _)) => {
- // return if we consumed everything or if the normal parser
- // does not consume anything
- if i2.eof_offset() == 0 {
- return Ok(input.next_slice(input.eof_offset()));
- } else if i2.eof_offset() == current_len {
- let offset = input.offset_to(&i2);
+ let start = input.checkpoint();
+
+ while input.eof_offset() > 0 {
+ let current_len = input.eof_offset();
+
+ match opt(normal.by_ref()).parse_next(input)? {
+ Some(_) => {
+ if input.eof_offset() == current_len {
+ let offset = input.offset_from(&start);
+ input.reset(start);
return Ok(input.next_slice(offset));
- } else {
- i = i2;
}
}
- Err(ErrMode::Backtrack(_)) => {
- if i.next_token().expect("eof_offset > 0").1.as_char() == control_char {
- let next = control_char.len_utf8();
- match escapable.parse_next(i.next_slice(next).0) {
- Ok((i2, _)) => {
- if i2.eof_offset() == 0 {
- return Ok(input.next_slice(input.eof_offset()));
- } else {
- i = i2;
- }
- }
- Err(e) => return Err(e),
- }
+ None => {
+ if opt(control_char).parse_next(input)?.is_some() {
+ let _ = escapable.parse_next(input)?;
} else {
- let offset = input.offset_to(&i);
+ let offset = input.offset_from(&start);
+ input.reset(start);
return Ok(input.next_slice(offset));
}
}
- Err(e) => {
- return Err(e);
- }
}
}
- Ok(input.next_slice(input.eof_offset()))
+ input.reset(start);
+ Ok(input.finish())
}
/// Matches a byte string with escaped characters.
@@ -1588,14 +1520,14 @@ where
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use std::str::from_utf8;
/// use winnow::token::tag;
/// use winnow::ascii::escaped_transform;
/// use winnow::ascii::alpha1;
/// use winnow::combinator::alt;
///
-/// fn parser(input: &str) -> IResult<&str, String> {
+/// fn parser<'s>(input: &mut &'s str) -> PResult<String, InputError<&'s str>> {
/// escaped_transform(
/// alpha1,
/// '\\',
@@ -1607,13 +1539,13 @@ where
/// ).parse_next(input)
/// }
///
-/// assert_eq!(parser("ab\\\"cd"), Ok(("", String::from("ab\"cd"))));
-/// assert_eq!(parser("ab\\ncd"), Ok(("", String::from("ab\ncd"))));
+/// assert_eq!(parser.parse_peek("ab\\\"cd"), Ok(("", String::from("ab\"cd"))));
+/// assert_eq!(parser.parse_peek("ab\\ncd"), Ok(("", String::from("ab\ncd"))));
/// ```
///
/// ```
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use std::str::from_utf8;
/// # use winnow::Partial;
/// use winnow::token::tag;
@@ -1621,7 +1553,7 @@ where
/// use winnow::ascii::alpha1;
/// use winnow::combinator::alt;
///
-/// fn parser(input: Partial<&str>) -> IResult<Partial<&str>, String> {
+/// fn parser<'s>(input: &mut Partial<&'s str>) -> PResult<String, InputError<Partial<&'s str>>> {
/// escaped_transform(
/// alpha1,
/// '\\',
@@ -1633,9 +1565,8 @@ where
/// ).parse_next(input)
/// }
///
-/// assert_eq!(parser(Partial::new("ab\\\"cd\"")), Ok((Partial::new("\""), String::from("ab\"cd"))));
+/// assert_eq!(parser.parse_peek(Partial::new("ab\\\"cd\"")), Ok((Partial::new("\""), String::from("ab\"cd"))));
/// ```
-#[cfg(feature = "alloc")]
#[inline(always)]
pub fn escaped_transform<I, Error, F, G, Output>(
mut normal: F,
@@ -1644,14 +1575,14 @@ pub fn escaped_transform<I, Error, F, G, Output>(
) -> impl Parser<I, Output, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: crate::stream::AsChar + Clone,
Output: crate::stream::Accumulate<<I as Stream>::Slice>,
F: Parser<I, <I as Stream>::Slice, Error>,
G: Parser<I, <I as Stream>::Slice, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- trace("escaped_transform", move |input: I| {
+ trace("escaped_transform", move |input: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() && input.is_partial() {
streaming_escaped_transform_internal(input, &mut normal, control_char, &mut transform)
} else {
@@ -1660,122 +1591,83 @@ where
})
}
-#[cfg(feature = "alloc")]
fn streaming_escaped_transform_internal<I, Error, F, G, Output>(
- input: I,
+ input: &mut I,
normal: &mut F,
control_char: char,
transform: &mut G,
-) -> IResult<I, Output, Error>
+) -> PResult<Output, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: crate::stream::AsChar + Clone,
Output: crate::stream::Accumulate<<I as Stream>::Slice>,
F: Parser<I, <I as Stream>::Slice, Error>,
G: Parser<I, <I as Stream>::Slice, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- let mut offset = 0;
let mut res = Output::initial(Some(input.eof_offset()));
- let i = input.clone();
-
- while offset < i.eof_offset() {
- let current_len = i.eof_offset();
- let remainder = i.next_slice(offset).0;
- match normal.parse_next(remainder.clone()) {
- Ok((i2, o)) => {
+ while input.eof_offset() > 0 {
+ let current_len = input.eof_offset();
+ match opt(normal.by_ref()).parse_next(input)? {
+ Some(o) => {
res.accumulate(o);
- if i2.eof_offset() == 0 {
- return Err(ErrMode::Incomplete(Needed::Unknown));
- } else if i2.eof_offset() == current_len {
- return Ok((remainder, res));
- } else {
- offset = input.offset_to(&i2);
+ if input.eof_offset() == current_len {
+ return Ok(res);
}
}
- Err(ErrMode::Backtrack(_)) => {
- if remainder.next_token().expect("eof_offset > 0").1.as_char() == control_char {
- let next = offset + control_char.len_utf8();
- match transform.parse_next(i.next_slice(next).0) {
- Ok((i2, o)) => {
- res.accumulate(o);
- if i2.eof_offset() == 0 {
- return Err(ErrMode::Incomplete(Needed::Unknown));
- } else {
- offset = input.offset_to(&i2);
- }
- }
- Err(e) => return Err(e),
- }
+ None => {
+ if opt(control_char).parse_next(input)?.is_some() {
+ let o = transform.parse_next(input)?;
+ res.accumulate(o);
} else {
- return Ok((remainder, res));
+ return Ok(res);
}
}
- Err(e) => return Err(e),
}
}
Err(ErrMode::Incomplete(Needed::Unknown))
}
-#[cfg(feature = "alloc")]
fn complete_escaped_transform_internal<I, Error, F, G, Output>(
- input: I,
+ input: &mut I,
normal: &mut F,
control_char: char,
transform: &mut G,
-) -> IResult<I, Output, Error>
+) -> PResult<Output, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: crate::stream::AsChar + Clone,
Output: crate::stream::Accumulate<<I as Stream>::Slice>,
F: Parser<I, <I as Stream>::Slice, Error>,
G: Parser<I, <I as Stream>::Slice, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- let mut offset = 0;
let mut res = Output::initial(Some(input.eof_offset()));
- let i = input.clone();
+ while input.eof_offset() > 0 {
+ let current_len = input.eof_offset();
- while offset < i.eof_offset() {
- let current_len = i.eof_offset();
- let (remainder, _) = i.next_slice(offset);
- match normal.parse_next(remainder.clone()) {
- Ok((i2, o)) => {
+ match opt(normal.by_ref()).parse_next(input)? {
+ Some(o) => {
res.accumulate(o);
- if i2.eof_offset() == 0 {
- return Ok((i.next_slice(i.eof_offset()).0, res));
- } else if i2.eof_offset() == current_len {
- return Ok((remainder, res));
- } else {
- offset = input.offset_to(&i2);
+ if input.eof_offset() == current_len {
+ return Ok(res);
}
}
- Err(ErrMode::Backtrack(_)) => {
- if remainder.next_token().expect("eof_offset > 0").1.as_char() == control_char {
- let next = offset + control_char.len_utf8();
- match transform.parse_next(i.next_slice(next).0) {
- Ok((i2, o)) => {
- res.accumulate(o);
- if i2.eof_offset() == 0 {
- return Ok((i.next_slice(i.eof_offset()).0, res));
- } else {
- offset = input.offset_to(&i2);
- }
- }
- Err(e) => return Err(e),
- }
+ None => {
+ if opt(control_char).parse_next(input)?.is_some() {
+ let o = transform.parse_next(input)?;
+ res.accumulate(o);
} else {
- return Ok((remainder, res));
+ return Ok(res);
}
}
- Err(e) => return Err(e),
}
}
- Ok((input.next_slice(offset).0, res))
+ Ok(res)
}
mod sealed {
diff --git a/vendor/winnow/src/ascii/tests.rs b/vendor/winnow/src/ascii/tests.rs
index b715d0920..aacbd86f2 100644
--- a/vendor/winnow/src/ascii/tests.rs
+++ b/vendor/winnow/src/ascii/tests.rs
@@ -1,12 +1,13 @@
use super::*;
+use crate::prelude::*;
mod complete {
use super::*;
use crate::combinator::alt;
use crate::combinator::opt;
use crate::error::ErrMode;
- use crate::error::Error;
use crate::error::ErrorKind;
+ use crate::error::InputError;
use crate::stream::ParseSlice;
use crate::token::none_of;
use crate::token::one_of;
@@ -16,7 +17,7 @@ mod complete {
macro_rules! assert_parse(
($left: expr, $right: expr) => {
- let res: $crate::IResult<_, _, Error<_>> = $left;
+ let res: $crate::IResult<_, _, InputError<_>> = $left;
assert_eq!(res, $right);
};
);
@@ -30,60 +31,75 @@ mod complete {
let d: &[u8] = "azé12".as_bytes();
let e: &[u8] = b" ";
let f: &[u8] = b" ;";
- //assert_eq!(alpha1::<_, Error>(a), Err(ErrMode::Incomplete(Needed::Size(1))));
- assert_parse!(alpha1(a), Ok((empty, a)));
+ //assert_eq!(alpha1::<_, InputError>(a), Err(ErrMode::Incomplete(Needed::Size(1))));
+ assert_parse!(alpha1.parse_peek(a), Ok((empty, a)));
assert_eq!(
- alpha1(b),
- Err(ErrMode::Backtrack(Error::new(b, ErrorKind::Slice)))
+ alpha1.parse_peek(b),
+ Err(ErrMode::Backtrack(InputError::new(b, ErrorKind::Slice)))
);
- assert_eq!(alpha1::<_, Error<_>>(c), Ok((&c[1..], &b"a"[..])));
- assert_eq!(alpha1::<_, Error<_>>(d), Ok(("é12".as_bytes(), &b"az"[..])));
assert_eq!(
- digit1(a),
- Err(ErrMode::Backtrack(Error::new(a, ErrorKind::Slice)))
+ alpha1::<_, InputError<_>>.parse_peek(c),
+ Ok((&c[1..], &b"a"[..]))
);
- assert_eq!(digit1::<_, Error<_>>(b), Ok((empty, b)));
assert_eq!(
- digit1(c),
- Err(ErrMode::Backtrack(Error::new(c, ErrorKind::Slice)))
+ alpha1::<_, InputError<_>>.parse_peek(d),
+ Ok(("é12".as_bytes(), &b"az"[..]))
+ );
+ assert_eq!(
+ digit1.parse_peek(a),
+ Err(ErrMode::Backtrack(InputError::new(a, ErrorKind::Slice)))
+ );
+ assert_eq!(digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
+ assert_eq!(
+ digit1.parse_peek(c),
+ Err(ErrMode::Backtrack(InputError::new(c, ErrorKind::Slice)))
);
assert_eq!(
- digit1(d),
- Err(ErrMode::Backtrack(Error::new(d, ErrorKind::Slice)))
+ digit1.parse_peek(d),
+ Err(ErrMode::Backtrack(InputError::new(d, ErrorKind::Slice)))
);
- assert_eq!(hex_digit1::<_, Error<_>>(a), Ok((empty, a)));
- assert_eq!(hex_digit1::<_, Error<_>>(b), Ok((empty, b)));
- assert_eq!(hex_digit1::<_, Error<_>>(c), Ok((empty, c)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(a), Ok((empty, a)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(c), Ok((empty, c)));
assert_eq!(
- hex_digit1::<_, Error<_>>(d),
+ hex_digit1::<_, InputError<_>>.parse_peek(d),
Ok(("zé12".as_bytes(), &b"a"[..]))
);
assert_eq!(
- hex_digit1(e),
- Err(ErrMode::Backtrack(Error::new(e, ErrorKind::Slice)))
+ hex_digit1.parse_peek(e),
+ Err(ErrMode::Backtrack(InputError::new(e, ErrorKind::Slice)))
);
assert_eq!(
- oct_digit1(a),
- Err(ErrMode::Backtrack(Error::new(a, ErrorKind::Slice)))
+ oct_digit1.parse_peek(a),
+ Err(ErrMode::Backtrack(InputError::new(a, ErrorKind::Slice)))
);
- assert_eq!(oct_digit1::<_, Error<_>>(b), Ok((empty, b)));
+ assert_eq!(oct_digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
assert_eq!(
- oct_digit1(c),
- Err(ErrMode::Backtrack(Error::new(c, ErrorKind::Slice)))
+ oct_digit1.parse_peek(c),
+ Err(ErrMode::Backtrack(InputError::new(c, ErrorKind::Slice)))
);
assert_eq!(
- oct_digit1(d),
- Err(ErrMode::Backtrack(Error::new(d, ErrorKind::Slice)))
+ oct_digit1.parse_peek(d),
+ Err(ErrMode::Backtrack(InputError::new(d, ErrorKind::Slice)))
+ );
+ assert_eq!(
+ alphanumeric1::<_, InputError<_>>.parse_peek(a),
+ Ok((empty, a))
);
- assert_eq!(alphanumeric1::<_, Error<_>>(a), Ok((empty, a)));
//assert_eq!(fix_error!(b,(), alphanumeric), Ok((empty, b)));
- assert_eq!(alphanumeric1::<_, Error<_>>(c), Ok((empty, c)));
assert_eq!(
- alphanumeric1::<_, Error<_>>(d),
+ alphanumeric1::<_, InputError<_>>.parse_peek(c),
+ Ok((empty, c))
+ );
+ assert_eq!(
+ alphanumeric1::<_, InputError<_>>.parse_peek(d),
Ok(("é12".as_bytes(), &b"az"[..]))
);
- assert_eq!(space1::<_, Error<_>>(e), Ok((empty, e)));
- assert_eq!(space1::<_, Error<_>>(f), Ok((&b";"[..], &b" "[..])));
+ assert_eq!(space1::<_, InputError<_>>.parse_peek(e), Ok((empty, e)));
+ assert_eq!(
+ space1::<_, InputError<_>>.parse_peek(f),
+ Ok((&b";"[..], &b" "[..]))
+ );
}
#[cfg(feature = "alloc")]
@@ -95,52 +111,64 @@ mod complete {
let c = "a123";
let d = "azé12";
let e = " ";
- assert_eq!(alpha1::<_, Error<_>>(a), Ok((empty, a)));
+ assert_eq!(alpha1::<_, InputError<_>>.parse_peek(a), Ok((empty, a)));
+ assert_eq!(
+ alpha1.parse_peek(b),
+ Err(ErrMode::Backtrack(InputError::new(b, ErrorKind::Slice)))
+ );
+ assert_eq!(alpha1::<_, InputError<_>>.parse_peek(c), Ok((&c[1..], "a")));
+ assert_eq!(alpha1::<_, InputError<_>>.parse_peek(d), Ok(("é12", "az")));
+ assert_eq!(
+ digit1.parse_peek(a),
+ Err(ErrMode::Backtrack(InputError::new(a, ErrorKind::Slice)))
+ );
+ assert_eq!(digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
assert_eq!(
- alpha1(b),
- Err(ErrMode::Backtrack(Error::new(b, ErrorKind::Slice)))
+ digit1.parse_peek(c),
+ Err(ErrMode::Backtrack(InputError::new(c, ErrorKind::Slice)))
);
- assert_eq!(alpha1::<_, Error<_>>(c), Ok((&c[1..], "a")));
- assert_eq!(alpha1::<_, Error<_>>(d), Ok(("é12", "az")));
assert_eq!(
- digit1(a),
- Err(ErrMode::Backtrack(Error::new(a, ErrorKind::Slice)))
+ digit1.parse_peek(d),
+ Err(ErrMode::Backtrack(InputError::new(d, ErrorKind::Slice)))
);
- assert_eq!(digit1::<_, Error<_>>(b), Ok((empty, b)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(a), Ok((empty, a)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(c), Ok((empty, c)));
assert_eq!(
- digit1(c),
- Err(ErrMode::Backtrack(Error::new(c, ErrorKind::Slice)))
+ hex_digit1::<_, InputError<_>>.parse_peek(d),
+ Ok(("zé12", "a"))
);
assert_eq!(
- digit1(d),
- Err(ErrMode::Backtrack(Error::new(d, ErrorKind::Slice)))
+ hex_digit1.parse_peek(e),
+ Err(ErrMode::Backtrack(InputError::new(e, ErrorKind::Slice)))
);
- assert_eq!(hex_digit1::<_, Error<_>>(a), Ok((empty, a)));
- assert_eq!(hex_digit1::<_, Error<_>>(b), Ok((empty, b)));
- assert_eq!(hex_digit1::<_, Error<_>>(c), Ok((empty, c)));
- assert_eq!(hex_digit1::<_, Error<_>>(d), Ok(("zé12", "a")));
assert_eq!(
- hex_digit1(e),
- Err(ErrMode::Backtrack(Error::new(e, ErrorKind::Slice)))
+ oct_digit1.parse_peek(a),
+ Err(ErrMode::Backtrack(InputError::new(a, ErrorKind::Slice)))
);
+ assert_eq!(oct_digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
assert_eq!(
- oct_digit1(a),
- Err(ErrMode::Backtrack(Error::new(a, ErrorKind::Slice)))
+ oct_digit1.parse_peek(c),
+ Err(ErrMode::Backtrack(InputError::new(c, ErrorKind::Slice)))
);
- assert_eq!(oct_digit1::<_, Error<_>>(b), Ok((empty, b)));
assert_eq!(
- oct_digit1(c),
- Err(ErrMode::Backtrack(Error::new(c, ErrorKind::Slice)))
+ oct_digit1.parse_peek(d),
+ Err(ErrMode::Backtrack(InputError::new(d, ErrorKind::Slice)))
);
assert_eq!(
- oct_digit1(d),
- Err(ErrMode::Backtrack(Error::new(d, ErrorKind::Slice)))
+ alphanumeric1::<_, InputError<_>>.parse_peek(a),
+ Ok((empty, a))
);
- assert_eq!(alphanumeric1::<_, Error<_>>(a), Ok((empty, a)));
//assert_eq!(fix_error!(b,(), alphanumeric), Ok((empty, b)));
- assert_eq!(alphanumeric1::<_, Error<_>>(c), Ok((empty, c)));
- assert_eq!(alphanumeric1::<_, Error<_>>(d), Ok(("é12", "az")));
- assert_eq!(space1::<_, Error<_>>(e), Ok((empty, e)));
+ assert_eq!(
+ alphanumeric1::<_, InputError<_>>.parse_peek(c),
+ Ok((empty, c))
+ );
+ assert_eq!(
+ alphanumeric1::<_, InputError<_>>.parse_peek(d),
+ Ok(("é12", "az"))
+ );
+ assert_eq!(space1::<_, InputError<_>>.parse_peek(e), Ok((empty, e)));
}
use crate::stream::Offset;
@@ -153,45 +181,45 @@ mod complete {
let e = &b" \t\r\n;"[..];
let f = &b"123abcDEF;"[..];
- match alpha1::<_, Error<_>>(a) {
+ match alpha1::<_, InputError<_>>.parse_peek(a) {
Ok((i, _)) => {
- assert_eq!(a.offset_to(i) + i.len(), a.len());
+ assert_eq!(i.offset_from(&a) + i.len(), a.len());
}
_ => panic!("wrong return type in offset test for alpha"),
}
- match digit1::<_, Error<_>>(b) {
+ match digit1::<_, InputError<_>>.parse_peek(b) {
Ok((i, _)) => {
- assert_eq!(b.offset_to(i) + i.len(), b.len());
+ assert_eq!(i.offset_from(&b) + i.len(), b.len());
}
_ => panic!("wrong return type in offset test for digit"),
}
- match alphanumeric1::<_, Error<_>>(c) {
+ match alphanumeric1::<_, InputError<_>>.parse_peek(c) {
Ok((i, _)) => {
- assert_eq!(c.offset_to(i) + i.len(), c.len());
+ assert_eq!(i.offset_from(&c) + i.len(), c.len());
}
_ => panic!("wrong return type in offset test for alphanumeric"),
}
- match space1::<_, Error<_>>(d) {
+ match space1::<_, InputError<_>>.parse_peek(d) {
Ok((i, _)) => {
- assert_eq!(d.offset_to(i) + i.len(), d.len());
+ assert_eq!(i.offset_from(&d) + i.len(), d.len());
}
_ => panic!("wrong return type in offset test for space"),
}
- match multispace1::<_, Error<_>>(e) {
+ match multispace1::<_, InputError<_>>.parse_peek(e) {
Ok((i, _)) => {
- assert_eq!(e.offset_to(i) + i.len(), e.len());
+ assert_eq!(i.offset_from(&e) + i.len(), e.len());
}
_ => panic!("wrong return type in offset test for multispace"),
}
- match hex_digit1::<_, Error<_>>(f) {
+ match hex_digit1::<_, InputError<_>>.parse_peek(f) {
Ok((i, _)) => {
- assert_eq!(f.offset_to(i) + i.len(), f.len());
+ assert_eq!(i.offset_from(&f) + i.len(), f.len());
}
_ => panic!("wrong return type in offset test for hex_digit"),
}
- match oct_digit1::<_, Error<_>>(f) {
+ match oct_digit1::<_, InputError<_>>.parse_peek(f) {
Ok((i, _)) => {
- assert_eq!(f.offset_to(i) + i.len(), f.len());
+ assert_eq!(i.offset_from(&f) + i.len(), f.len());
}
_ => panic!("wrong return type in offset test for oct_digit"),
}
@@ -201,53 +229,62 @@ mod complete {
fn is_not_line_ending_bytes() {
let a: &[u8] = b"ab12cd\nefgh";
assert_eq!(
- not_line_ending::<_, Error<_>>(a),
+ not_line_ending::<_, InputError<_>>.parse_peek(a),
Ok((&b"\nefgh"[..], &b"ab12cd"[..]))
);
let b: &[u8] = b"ab12cd\nefgh\nijkl";
assert_eq!(
- not_line_ending::<_, Error<_>>(b),
+ not_line_ending::<_, InputError<_>>.parse_peek(b),
Ok((&b"\nefgh\nijkl"[..], &b"ab12cd"[..]))
);
let c: &[u8] = b"ab12cd\r\nefgh\nijkl";
assert_eq!(
- not_line_ending::<_, Error<_>>(c),
+ not_line_ending::<_, InputError<_>>.parse_peek(c),
Ok((&b"\r\nefgh\nijkl"[..], &b"ab12cd"[..]))
);
let d: &[u8] = b"ab12cd";
- assert_eq!(not_line_ending::<_, Error<_>>(d), Ok((&[][..], d)));
+ assert_eq!(
+ not_line_ending::<_, InputError<_>>.parse_peek(d),
+ Ok((&[][..], d))
+ );
}
#[test]
fn is_not_line_ending_str() {
let f = "βèƒôřè\rÂßÇáƒƭèř";
assert_eq!(
- not_line_ending(f),
- Err(ErrMode::Backtrack(Error::new(f, ErrorKind::Tag)))
+ not_line_ending.parse_peek(f),
+ Err(ErrMode::Backtrack(InputError::new(
+ &f[12..],
+ ErrorKind::Tag
+ )))
);
let g2: &str = "ab12cd";
- assert_eq!(not_line_ending::<_, Error<_>>(g2), Ok(("", g2)));
+ assert_eq!(
+ not_line_ending::<_, InputError<_>>.parse_peek(g2),
+ Ok(("", g2))
+ );
}
#[test]
fn hex_digit_test() {
let i = &b"0123456789abcdefABCDEF;"[..];
- assert_parse!(hex_digit1(i), Ok((&b";"[..], &i[..i.len() - 1])));
+ assert_parse!(hex_digit1.parse_peek(i), Ok((&b";"[..], &i[..i.len() - 1])));
let i = &b"g"[..];
assert_parse!(
- hex_digit1(i),
- Err(ErrMode::Backtrack(error_position!(i, ErrorKind::Slice)))
+ hex_digit1.parse_peek(i),
+ Err(ErrMode::Backtrack(error_position!(&i, ErrorKind::Slice)))
);
let i = &b"G"[..];
assert_parse!(
- hex_digit1(i),
- Err(ErrMode::Backtrack(error_position!(i, ErrorKind::Slice)))
+ hex_digit1.parse_peek(i),
+ Err(ErrMode::Backtrack(error_position!(&i, ErrorKind::Slice)))
);
assert!(AsChar::is_hex_digit(b'0'));
@@ -267,12 +304,12 @@ mod complete {
#[test]
fn oct_digit_test() {
let i = &b"01234567;"[..];
- assert_parse!(oct_digit1(i), Ok((&b";"[..], &i[..i.len() - 1])));
+ assert_parse!(oct_digit1.parse_peek(i), Ok((&b";"[..], &i[..i.len() - 1])));
let i = &b"8"[..];
assert_parse!(
- oct_digit1(i),
- Err(ErrMode::Backtrack(error_position!(i, ErrorKind::Slice)))
+ oct_digit1.parse_peek(i),
+ Err(ErrMode::Backtrack(error_position!(&i, ErrorKind::Slice)))
);
assert!(AsChar::is_oct_digit(b'0'));
@@ -290,7 +327,7 @@ mod complete {
#[test]
fn full_line_windows() {
fn take_full_line(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
- (not_line_ending, line_ending).parse_next(i)
+ (not_line_ending, line_ending).parse_peek(i)
}
let input = b"abc\r\n";
let output = take_full_line(input);
@@ -300,7 +337,7 @@ mod complete {
#[test]
fn full_line_unix() {
fn take_full_line(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
- (not_line_ending, line_ending).parse_next(i)
+ (not_line_ending, line_ending).parse_peek(i)
}
let input = b"abc\n";
let output = take_full_line(input);
@@ -310,87 +347,96 @@ mod complete {
#[test]
fn check_windows_lineending() {
let input = b"\r\n";
- let output = line_ending(&input[..]);
+ let output = line_ending.parse_peek(&input[..]);
assert_parse!(output, Ok((&b""[..], &b"\r\n"[..])));
}
#[test]
fn check_unix_lineending() {
let input = b"\n";
- let output = line_ending(&input[..]);
+ let output = line_ending.parse_peek(&input[..]);
assert_parse!(output, Ok((&b""[..], &b"\n"[..])));
}
#[test]
fn cr_lf() {
- assert_parse!(crlf(&b"\r\na"[..]), Ok((&b"a"[..], &b"\r\n"[..])));
assert_parse!(
- crlf(&b"\r"[..]),
+ crlf.parse_peek(&b"\r\na"[..]),
+ Ok((&b"a"[..], &b"\r\n"[..]))
+ );
+ assert_parse!(
+ crlf.parse_peek(&b"\r"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b"\r"[..],
+ &&b"\r"[..],
ErrorKind::Tag
)))
);
assert_parse!(
- crlf(&b"\ra"[..]),
+ crlf.parse_peek(&b"\ra"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b"\ra"[..],
+ &&b"\ra"[..],
ErrorKind::Tag
)))
);
- assert_parse!(crlf("\r\na"), Ok(("a", "\r\n")));
+ assert_parse!(crlf.parse_peek("\r\na"), Ok(("a", "\r\n")));
assert_parse!(
- crlf("\r"),
- Err(ErrMode::Backtrack(error_position!("\r", ErrorKind::Tag)))
+ crlf.parse_peek("\r"),
+ Err(ErrMode::Backtrack(error_position!(&"\r", ErrorKind::Tag)))
);
assert_parse!(
- crlf("\ra"),
- Err(ErrMode::Backtrack(error_position!("\ra", ErrorKind::Tag)))
+ crlf.parse_peek("\ra"),
+ Err(ErrMode::Backtrack(error_position!(&"\ra", ErrorKind::Tag)))
);
}
#[test]
fn end_of_line() {
- assert_parse!(line_ending(&b"\na"[..]), Ok((&b"a"[..], &b"\n"[..])));
- assert_parse!(line_ending(&b"\r\na"[..]), Ok((&b"a"[..], &b"\r\n"[..])));
assert_parse!(
- line_ending(&b"\r"[..]),
+ line_ending.parse_peek(&b"\na"[..]),
+ Ok((&b"a"[..], &b"\n"[..]))
+ );
+ assert_parse!(
+ line_ending.parse_peek(&b"\r\na"[..]),
+ Ok((&b"a"[..], &b"\r\n"[..]))
+ );
+ assert_parse!(
+ line_ending.parse_peek(&b"\r"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b"\r"[..],
+ &&b"\r"[..],
ErrorKind::Tag
)))
);
assert_parse!(
- line_ending(&b"\ra"[..]),
+ line_ending.parse_peek(&b"\ra"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b"\ra"[..],
+ &&b"\ra"[..],
ErrorKind::Tag
)))
);
- assert_parse!(line_ending("\na"), Ok(("a", "\n")));
- assert_parse!(line_ending("\r\na"), Ok(("a", "\r\n")));
+ assert_parse!(line_ending.parse_peek("\na"), Ok(("a", "\n")));
+ assert_parse!(line_ending.parse_peek("\r\na"), Ok(("a", "\r\n")));
assert_parse!(
- line_ending("\r"),
- Err(ErrMode::Backtrack(error_position!("\r", ErrorKind::Tag)))
+ line_ending.parse_peek("\r"),
+ Err(ErrMode::Backtrack(error_position!(&"\r", ErrorKind::Tag)))
);
assert_parse!(
- line_ending("\ra"),
- Err(ErrMode::Backtrack(error_position!("\ra", ErrorKind::Tag)))
+ line_ending.parse_peek("\ra"),
+ Err(ErrMode::Backtrack(error_position!(&"\ra", ErrorKind::Tag)))
);
}
fn digit_to_i16(input: &str) -> IResult<&str, i16> {
let i = input;
- let (i, opt_sign) = opt(alt(('+', '-'))).parse_next(i)?;
+ let (i, opt_sign) = opt(alt(('+', '-'))).parse_peek(i)?;
let sign = match opt_sign {
Some('+') | None => true,
Some('-') => false,
_ => unreachable!(),
};
- let (i, s) = digit1::<_, crate::error::Error<_>>(i)?;
+ let (i, s) = digit1::<_, InputError<_>>.parse_peek(i)?;
match s.parse_slice() {
Some(n) => {
if sign {
@@ -399,15 +445,15 @@ mod complete {
Ok((i, -n))
}
}
- None => Err(ErrMode::from_error_kind(i, ErrorKind::Verify)),
+ None => Err(ErrMode::from_error_kind(&i, ErrorKind::Verify)),
}
}
fn digit_to_u32(i: &str) -> IResult<&str, u32> {
- let (i, s) = digit1(i)?;
+ let (i, s) = digit1.parse_peek(i)?;
match s.parse_slice() {
Some(n) => Ok((i, n)),
- None => Err(ErrMode::from_error_kind(i, ErrorKind::Verify)),
+ None => Err(ErrMode::from_error_kind(&i, ErrorKind::Verify)),
}
}
@@ -416,7 +462,7 @@ mod complete {
#[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253
fn ints(s in "\\PC*") {
let res1 = digit_to_i16(&s);
- let res2 = dec_int(s.as_str());
+ let res2 = dec_int.parse_peek(s.as_str());
assert_eq!(res1, res2);
}
@@ -424,7 +470,7 @@ mod complete {
#[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253
fn uints(s in "\\PC*") {
let res1 = digit_to_u32(&s);
- let res2 = dec_uint(s.as_str());
+ let res2 = dec_uint.parse_peek(s.as_str());
assert_eq!(res1, res2);
}
}
@@ -432,13 +478,13 @@ mod complete {
#[test]
fn hex_uint_tests() {
fn hex_u32(input: &[u8]) -> IResult<&[u8], u32> {
- hex_uint(input)
+ hex_uint.parse_peek(input)
}
assert_parse!(
hex_u32(&b";"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b";"[..],
+ &&b";"[..],
ErrorKind::Slice
)))
);
@@ -449,14 +495,14 @@ mod complete {
assert_parse!(
hex_u32(&b"00c5a31be2;"[..]), // overflow
Err(ErrMode::Backtrack(error_position!(
- &b"00c5a31be2;"[..],
+ &&b"00c5a31be2;"[..],
ErrorKind::Verify
)))
);
assert_parse!(
hex_u32(&b"c5a31be201;"[..]), // overflow
Err(ErrMode::Backtrack(error_position!(
- &b"c5a31be201;"[..],
+ &&b"c5a31be201;"[..],
ErrorKind::Verify
)))
);
@@ -464,14 +510,14 @@ mod complete {
assert_parse!(
hex_u32(&b"ffffffffffffffff;"[..]), // overflow
Err(ErrMode::Backtrack(error_position!(
- &b"ffffffffffffffff;"[..],
+ &&b"ffffffffffffffff;"[..],
ErrorKind::Verify
)))
);
assert_parse!(
hex_u32(&b"ffffffffffffffff"[..]), // overflow
Err(ErrMode::Backtrack(error_position!(
- &b"ffffffffffffffff"[..],
+ &&b"ffffffffffffffff"[..],
ErrorKind::Verify
)))
);
@@ -510,35 +556,40 @@ mod complete {
let larger = test.to_string();
- assert_parse!(float(larger.as_bytes()), Ok((&b""[..], expected32)));
- assert_parse!(float(&larger[..]), Ok(("", expected32)));
-
- assert_parse!(float(larger.as_bytes()), Ok((&b""[..], expected64)));
- assert_parse!(float(&larger[..]), Ok(("", expected64)));
+ assert_parse!(
+ float.parse_peek(larger.as_bytes()),
+ Ok((&b""[..], expected32))
+ );
+ assert_parse!(float.parse_peek(&larger[..]), Ok(("", expected32)));
+
+ assert_parse!(
+ float.parse_peek(larger.as_bytes()),
+ Ok((&b""[..], expected64))
+ );
+ assert_parse!(float.parse_peek(&larger[..]), Ok(("", expected64)));
}
let remaining_exponent = "-1.234E-";
assert_parse!(
- float::<_, f64, _>(remaining_exponent),
- Err(ErrMode::Cut(Error {
- input: "",
- kind: ErrorKind::Slice
- }))
+ float::<_, f64, _>.parse_peek(remaining_exponent),
+ Err(ErrMode::Cut(InputError::new("", ErrorKind::Slice)))
);
- let (_i, nan) = float::<_, f32, ()>("NaN").unwrap();
+ let (i, nan) = float::<_, f32, ()>.parse_peek("NaN").unwrap();
assert!(nan.is_nan());
+ assert_eq!(i, "");
- let (_i, inf) = float::<_, f32, ()>("inf").unwrap();
+ let (i, inf) = float::<_, f32, ()>.parse_peek("inf").unwrap();
assert!(inf.is_infinite());
- let (_i, inf) = float::<_, f32, ()>("infinite").unwrap();
+ assert_eq!(i, "");
+ let (i, inf) = float::<_, f32, ()>.parse_peek("infinity").unwrap();
assert!(inf.is_infinite());
+ assert_eq!(i, "");
}
#[cfg(feature = "std")]
fn parse_f64(i: &str) -> IResult<&str, f64, ()> {
- #[allow(deprecated)] // will just become `pub(crate)` later
- match super::recognize_float_or_exceptions(i) {
+ match super::recognize_float_or_exceptions.parse_peek(i) {
Err(e) => Err(e),
Ok((i, s)) => {
if s.is_empty() {
@@ -559,7 +610,7 @@ mod complete {
fn floats(s in "\\PC*") {
println!("testing {}", s);
let res1 = parse_f64(&s);
- let res2 = float::<_, f64, ()>(s.as_str());
+ let res2 = float::<_, f64, ()>.parse_peek(s.as_str());
assert_eq!(res1, res2);
}
}
@@ -571,7 +622,7 @@ mod complete {
fn escaped_string(input: &str) -> IResult<&str, &str> {
use crate::ascii::alpha0;
use crate::token::one_of;
- escaped(alpha0, '\\', one_of("n")).parse_next(input)
+ escaped(alpha0, '\\', one_of(['n'])).parse_peek(input)
}
escaped_string("7").unwrap();
@@ -588,10 +639,14 @@ mod complete {
delimited(
'"',
- escaped(opt(none_of(r#"\""#)), '\\', one_of(r#"\"rnt"#)),
+ escaped(
+ opt(none_of(['\\', '"'])),
+ '\\',
+ one_of(['\\', '"', 'r', 'n', 't']),
+ ),
'"',
)
- .parse_next(input)
+ .parse_peek(input)
}
assert_eq!(unquote(r#""""#), Ok(("", "")));
@@ -605,7 +660,7 @@ mod complete {
use crate::token::one_of;
fn esc(i: &[u8]) -> IResult<&[u8], &[u8]> {
- escaped(alpha, '\\', one_of("\"n\\")).parse_next(i)
+ escaped(alpha, '\\', one_of(['\"', 'n', '\\'])).parse_peek(i)
}
assert_eq!(esc(&b"abcd;"[..]), Ok((&b";"[..], &b"abcd"[..])));
assert_eq!(esc(&b"ab\\\"cd;"[..]), Ok((&b";"[..], &b"ab\\\"cd"[..])));
@@ -615,21 +670,21 @@ mod complete {
assert_eq!(
esc(&b"AB\\"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b""[..],
+ &&b""[..],
ErrorKind::Token
)))
);
assert_eq!(
esc(&b"AB\\A"[..]),
Err(ErrMode::Backtrack(error_node_position!(
- &b"AB\\A"[..],
+ &&b"AB\\A"[..],
ErrorKind::Token,
- error_position!(&b"A"[..], ErrorKind::Verify)
+ error_position!(&&b"A"[..], ErrorKind::Verify)
)))
);
fn esc2(i: &[u8]) -> IResult<&[u8], &[u8]> {
- escaped(digit, '\\', one_of("\"n\\")).parse_next(i)
+ escaped(digit, '\\', one_of(['\"', 'n', '\\'])).parse_peek(i)
}
assert_eq!(esc2(&b"12\\nnn34"[..]), Ok((&b"nn34"[..], &b"12\\n"[..])));
}
@@ -641,7 +696,7 @@ mod complete {
use crate::token::one_of;
fn esc(i: &str) -> IResult<&str, &str> {
- escaped(alpha, '\\', one_of("\"n\\")).parse_next(i)
+ escaped(alpha, '\\', one_of(['\"', 'n', '\\'])).parse_peek(i)
}
assert_eq!(esc("abcd;"), Ok((";", "abcd")));
assert_eq!(esc("ab\\\"cd;"), Ok((";", "ab\\\"cd")));
@@ -650,24 +705,24 @@ mod complete {
assert_eq!(esc("ab\\\"12"), Ok(("12", "ab\\\"")));
assert_eq!(
esc("AB\\"),
- Err(ErrMode::Backtrack(error_position!("", ErrorKind::Token)))
+ Err(ErrMode::Backtrack(error_position!(&"", ErrorKind::Token)))
);
assert_eq!(
esc("AB\\A"),
Err(ErrMode::Backtrack(error_node_position!(
- "AB\\A",
+ &"AB\\A",
ErrorKind::Token,
- error_position!("A", ErrorKind::Verify)
+ error_position!(&"A", ErrorKind::Verify)
)))
);
fn esc2(i: &str) -> IResult<&str, &str> {
- escaped(digit, '\\', one_of("\"n\\")).parse_next(i)
+ escaped(digit, '\\', one_of(['\"', 'n', '\\'])).parse_peek(i)
}
assert_eq!(esc2("12\\nnn34"), Ok(("nn34", "12\\n")));
fn esc3(i: &str) -> IResult<&str, &str> {
- escaped(alpha, '\u{241b}', one_of("\"n")).parse_next(i)
+ escaped(alpha, '\u{241b}', one_of(['\"', 'n'])).parse_peek(i)
}
assert_eq!(esc3("ab␛ncd;"), Ok((";", "ab␛ncd")));
}
@@ -676,7 +731,7 @@ mod complete {
fn test_escaped_error() {
fn esc(s: &str) -> IResult<&str, &str> {
use crate::ascii::digit1;
- escaped(digit1, '\\', one_of("\"n\\")).parse_next(s)
+ escaped(digit1, '\\', one_of(['\"', 'n', '\\'])).parse_peek(s)
}
assert_eq!(esc("abcd"), Ok(("abcd", "")));
@@ -703,7 +758,7 @@ mod complete {
)),
)
.map(to_s)
- .parse_next(i)
+ .parse_peek(i)
}
assert_eq!(esc(&b"abcd;"[..]), Ok((&b";"[..], String::from("abcd"))));
@@ -723,16 +778,16 @@ mod complete {
assert_eq!(
esc(&b"AB\\"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b""[..],
+ &&b""[..],
ErrorKind::Tag
)))
);
assert_eq!(
esc(&b"AB\\A"[..]),
Err(ErrMode::Backtrack(error_node_position!(
- &b"AB\\A"[..],
+ &&b"AB\\A"[..],
ErrorKind::Eof,
- error_position!(&b"A"[..], ErrorKind::Tag)
+ error_position!(&&b"A"[..], ErrorKind::Tag)
)))
);
@@ -746,7 +801,7 @@ mod complete {
)),
)
.map(to_s)
- .parse_next(i)
+ .parse_peek(i)
}
assert_eq!(
esc2(&b"ab&egrave;DEF;"[..]),
@@ -769,7 +824,7 @@ mod complete {
'\\',
alt(("\\".value("\\"), "\"".value("\""), "n".value("\n"))),
)
- .parse_next(i)
+ .parse_peek(i)
}
assert_eq!(esc("abcd;"), Ok((";", String::from("abcd"))));
@@ -779,14 +834,14 @@ mod complete {
assert_eq!(esc("ab\\\"12"), Ok(("12", String::from("ab\""))));
assert_eq!(
esc("AB\\"),
- Err(ErrMode::Backtrack(error_position!("", ErrorKind::Tag)))
+ Err(ErrMode::Backtrack(error_position!(&"", ErrorKind::Tag)))
);
assert_eq!(
esc("AB\\A"),
Err(ErrMode::Backtrack(error_node_position!(
- "AB\\A",
+ &"AB\\A",
ErrorKind::Eof,
- error_position!("A", ErrorKind::Tag)
+ error_position!(&"A", ErrorKind::Tag)
)))
);
@@ -796,7 +851,7 @@ mod complete {
'&',
alt(("egrave;".value("è"), "agrave;".value("à"))),
)
- .parse_next(i)
+ .parse_peek(i)
}
assert_eq!(esc2("ab&egrave;DEF;"), Ok((";", String::from("abèDEF"))));
assert_eq!(
@@ -805,7 +860,7 @@ mod complete {
);
fn esc3(i: &str) -> IResult<&str, String> {
- escaped_transform(alpha, '␛', alt(("0".value("\0"), "n".value("\n")))).parse_next(i)
+ escaped_transform(alpha, '␛', alt(("0".value("\0"), "n".value("\n")))).parse_peek(i)
}
assert_eq!(esc3("a␛0bc␛n"), Ok(("", String::from("a\0bc\n"))));
}
@@ -815,7 +870,7 @@ mod complete {
fn test_escaped_transform_error() {
fn esc_trans(s: &str) -> IResult<&str, String> {
use crate::ascii::digit1;
- escaped_transform(digit1, '\\', "n").parse_next(s)
+ escaped_transform(digit1, '\\', "n").parse_peek(s)
}
assert_eq!(esc_trans("abcd"), Ok(("abcd", String::new())));
@@ -825,8 +880,8 @@ mod complete {
mod partial {
use super::*;
use crate::combinator::opt;
- use crate::error::Error;
use crate::error::ErrorKind;
+ use crate::error::InputError;
use crate::error::{ErrMode, Needed};
use crate::stream::ParseSlice;
use crate::IResult;
@@ -835,7 +890,7 @@ mod partial {
macro_rules! assert_parse(
($left: expr, $right: expr) => {
- let res: $crate::IResult<_, _, Error<_>> = $left;
+ let res: $crate::IResult<_, _, InputError<_>> = $left;
assert_eq!(res, $right);
};
);
@@ -850,116 +905,116 @@ mod partial {
let f: &[u8] = b" ;";
//assert_eq!(alpha1::<_, Error<_>>(a), Err(ErrMode::Incomplete(Needed::new(1))));
assert_parse!(
- alpha1(Partial::new(a)),
+ alpha1.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- alpha1(Partial::new(b)),
- Err(ErrMode::Backtrack(Error::new(
+ alpha1.parse_peek(Partial::new(b)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(b),
ErrorKind::Slice
)))
);
assert_eq!(
- alpha1::<_, Error<_>>(Partial::new(c)),
+ alpha1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Ok((Partial::new(&c[1..]), &b"a"[..]))
);
assert_eq!(
- alpha1::<_, Error<_>>(Partial::new(d)),
+ alpha1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("é12".as_bytes()), &b"az"[..]))
);
assert_eq!(
- digit1(Partial::new(a)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(a)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(a),
ErrorKind::Slice
)))
);
assert_eq!(
- digit1::<_, Error<_>>(Partial::new(b)),
+ digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- digit1(Partial::new(c)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(c)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(c),
ErrorKind::Slice
)))
);
assert_eq!(
- digit1(Partial::new(d)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(d)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(d),
ErrorKind::Slice
)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(a)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(b)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(c)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(d)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("zé12".as_bytes()), &b"a"[..]))
);
assert_eq!(
- hex_digit1(Partial::new(e)),
- Err(ErrMode::Backtrack(Error::new(
+ hex_digit1.parse_peek(Partial::new(e)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(e),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1(Partial::new(a)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(a)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(a),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1::<_, Error<_>>(Partial::new(b)),
+ oct_digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- oct_digit1(Partial::new(c)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(c)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(c),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1(Partial::new(d)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(d)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(d),
ErrorKind::Slice
)))
);
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(a)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
//assert_eq!(fix_error!(b,(), alphanumeric1), Ok((empty, b)));
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(c)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(d)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("é12".as_bytes()), &b"az"[..]))
);
assert_eq!(
- space1::<_, Error<_>>(Partial::new(e)),
+ space1::<_, InputError<_>>.parse_peek(Partial::new(e)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- space1::<_, Error<_>>(Partial::new(f)),
+ space1::<_, InputError<_>>.parse_peek(Partial::new(f)),
Ok((Partial::new(&b";"[..]), &b" "[..]))
);
}
@@ -973,112 +1028,112 @@ mod partial {
let d = "azé12";
let e = " ";
assert_eq!(
- alpha1::<_, Error<_>>(Partial::new(a)),
+ alpha1::<_, InputError<_>>.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- alpha1(Partial::new(b)),
- Err(ErrMode::Backtrack(Error::new(
+ alpha1.parse_peek(Partial::new(b)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(b),
ErrorKind::Slice
)))
);
assert_eq!(
- alpha1::<_, Error<_>>(Partial::new(c)),
+ alpha1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Ok((Partial::new(&c[1..]), "a"))
);
assert_eq!(
- alpha1::<_, Error<_>>(Partial::new(d)),
+ alpha1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("é12"), "az"))
);
assert_eq!(
- digit1(Partial::new(a)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(a)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(a),
ErrorKind::Slice
)))
);
assert_eq!(
- digit1::<_, Error<_>>(Partial::new(b)),
+ digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- digit1(Partial::new(c)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(c)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(c),
ErrorKind::Slice
)))
);
assert_eq!(
- digit1(Partial::new(d)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(d)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(d),
ErrorKind::Slice
)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(a)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(b)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(c)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(d)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("zé12"), "a"))
);
assert_eq!(
- hex_digit1(Partial::new(e)),
- Err(ErrMode::Backtrack(Error::new(
+ hex_digit1.parse_peek(Partial::new(e)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(e),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1(Partial::new(a)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(a)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(a),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1::<_, Error<_>>(Partial::new(b)),
+ oct_digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- oct_digit1(Partial::new(c)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(c)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(c),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1(Partial::new(d)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(d)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(d),
ErrorKind::Slice
)))
);
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(a)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
//assert_eq!(fix_error!(b,(), alphanumeric1), Ok((empty, b)));
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(c)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(d)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("é12"), "az"))
);
assert_eq!(
- space1::<_, Error<_>>(Partial::new(e)),
+ space1::<_, InputError<_>>.parse_peek(Partial::new(e)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
}
@@ -1093,52 +1148,52 @@ mod partial {
let e = &b" \t\r\n;"[..];
let f = &b"123abcDEF;"[..];
- match alpha1::<_, Error<_>>(Partial::new(a)) {
+ match alpha1::<_, InputError<_>>.parse_peek(Partial::new(a)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(a.offset_to(i) + i.len(), a.len());
+ assert_eq!(i.offset_from(&a) + i.len(), a.len());
}
_ => panic!("wrong return type in offset test for alpha"),
}
- match digit1::<_, Error<_>>(Partial::new(b)) {
+ match digit1::<_, InputError<_>>.parse_peek(Partial::new(b)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(b.offset_to(i) + i.len(), b.len());
+ assert_eq!(i.offset_from(&b) + i.len(), b.len());
}
_ => panic!("wrong return type in offset test for digit"),
}
- match alphanumeric1::<_, Error<_>>(Partial::new(c)) {
+ match alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(c)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(c.offset_to(i) + i.len(), c.len());
+ assert_eq!(i.offset_from(&c) + i.len(), c.len());
}
_ => panic!("wrong return type in offset test for alphanumeric"),
}
- match space1::<_, Error<_>>(Partial::new(d)) {
+ match space1::<_, InputError<_>>.parse_peek(Partial::new(d)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(d.offset_to(i) + i.len(), d.len());
+ assert_eq!(i.offset_from(&d) + i.len(), d.len());
}
_ => panic!("wrong return type in offset test for space"),
}
- match multispace1::<_, Error<_>>(Partial::new(e)) {
+ match multispace1::<_, InputError<_>>.parse_peek(Partial::new(e)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(e.offset_to(i) + i.len(), e.len());
+ assert_eq!(i.offset_from(&e) + i.len(), e.len());
}
_ => panic!("wrong return type in offset test for multispace"),
}
- match hex_digit1::<_, Error<_>>(Partial::new(f)) {
+ match hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(f)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(f.offset_to(i) + i.len(), f.len());
+ assert_eq!(i.offset_from(&f) + i.len(), f.len());
}
_ => panic!("wrong return type in offset test for hex_digit"),
}
- match oct_digit1::<_, Error<_>>(Partial::new(f)) {
+ match oct_digit1::<_, InputError<_>>.parse_peek(Partial::new(f)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(f.offset_to(i) + i.len(), f.len());
+ assert_eq!(i.offset_from(&f) + i.len(), f.len());
}
_ => panic!("wrong return type in offset test for oct_digit"),
}
@@ -1148,26 +1203,26 @@ mod partial {
fn is_not_line_ending_bytes() {
let a: &[u8] = b"ab12cd\nefgh";
assert_eq!(
- not_line_ending::<_, Error<_>>(Partial::new(a)),
+ not_line_ending::<_, InputError<_>>.parse_peek(Partial::new(a)),
Ok((Partial::new(&b"\nefgh"[..]), &b"ab12cd"[..]))
);
let b: &[u8] = b"ab12cd\nefgh\nijkl";
assert_eq!(
- not_line_ending::<_, Error<_>>(Partial::new(b)),
+ not_line_ending::<_, InputError<_>>.parse_peek(Partial::new(b)),
Ok((Partial::new(&b"\nefgh\nijkl"[..]), &b"ab12cd"[..]))
);
let c: &[u8] = b"ab12cd\r\nefgh\nijkl";
assert_eq!(
- not_line_ending::<_, Error<_>>(Partial::new(c)),
+ not_line_ending::<_, InputError<_>>.parse_peek(Partial::new(c)),
Ok((Partial::new(&b"\r\nefgh\nijkl"[..]), &b"ab12cd"[..]))
);
let d: &[u8] = b"ab12cd";
assert_eq!(
- not_line_ending::<_, Error<_>>(Partial::new(d)),
- Err(ErrMode::Incomplete(Needed::Unknown))
+ not_line_ending::<_, InputError<_>>.parse_peek(Partial::new(d)),
+ Err(ErrMode::Incomplete(Needed::new(1)))
);
}
@@ -1175,17 +1230,17 @@ mod partial {
fn is_not_line_ending_str() {
let f = "βèƒôřè\rÂßÇáƒƭèř";
assert_eq!(
- not_line_ending(Partial::new(f)),
- Err(ErrMode::Backtrack(Error::new(
- Partial::new(f),
+ not_line_ending.parse_peek(Partial::new(f)),
+ Err(ErrMode::Backtrack(InputError::new(
+ Partial::new(&f[12..]),
ErrorKind::Tag
)))
);
let g2: &str = "ab12cd";
assert_eq!(
- not_line_ending::<_, Error<_>>(Partial::new(g2)),
- Err(ErrMode::Incomplete(Needed::Unknown))
+ not_line_ending::<_, InputError<_>>.parse_peek(Partial::new(g2)),
+ Err(ErrMode::Incomplete(Needed::new(1)))
);
}
@@ -1193,24 +1248,24 @@ mod partial {
fn hex_digit_test() {
let i = &b"0123456789abcdefABCDEF;"[..];
assert_parse!(
- hex_digit1(Partial::new(i)),
+ hex_digit1.parse_peek(Partial::new(i)),
Ok((Partial::new(&b";"[..]), &i[..i.len() - 1]))
);
let i = &b"g"[..];
assert_parse!(
- hex_digit1(Partial::new(i)),
+ hex_digit1.parse_peek(Partial::new(i)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(i),
+ &Partial::new(i),
ErrorKind::Slice
)))
);
let i = &b"G"[..];
assert_parse!(
- hex_digit1(Partial::new(i)),
+ hex_digit1.parse_peek(Partial::new(i)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(i),
+ &Partial::new(i),
ErrorKind::Slice
)))
);
@@ -1233,15 +1288,15 @@ mod partial {
fn oct_digit_test() {
let i = &b"01234567;"[..];
assert_parse!(
- oct_digit1(Partial::new(i)),
+ oct_digit1.parse_peek(Partial::new(i)),
Ok((Partial::new(&b";"[..]), &i[..i.len() - 1]))
);
let i = &b"8"[..];
assert_parse!(
- oct_digit1(Partial::new(i)),
+ oct_digit1.parse_peek(Partial::new(i)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(i),
+ &Partial::new(i),
ErrorKind::Slice
)))
);
@@ -1262,7 +1317,7 @@ mod partial {
fn full_line_windows() {
#[allow(clippy::type_complexity)]
fn take_full_line(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, (&[u8], &[u8])> {
- (not_line_ending, line_ending).parse_next(i)
+ (not_line_ending, line_ending).parse_peek(i)
}
let input = b"abc\r\n";
let output = take_full_line(Partial::new(input));
@@ -1276,7 +1331,7 @@ mod partial {
fn full_line_unix() {
#[allow(clippy::type_complexity)]
fn take_full_line(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, (&[u8], &[u8])> {
- (not_line_ending, line_ending).parse_next(i)
+ (not_line_ending, line_ending).parse_peek(i)
}
let input = b"abc\n";
let output = take_full_line(Partial::new(input));
@@ -1289,44 +1344,47 @@ mod partial {
#[test]
fn check_windows_lineending() {
let input = b"\r\n";
- let output = line_ending(Partial::new(&input[..]));
+ let output = line_ending.parse_peek(Partial::new(&input[..]));
assert_parse!(output, Ok((Partial::new(&b""[..]), &b"\r\n"[..])));
}
#[test]
fn check_unix_lineending() {
let input = b"\n";
- let output = line_ending(Partial::new(&input[..]));
+ let output = line_ending.parse_peek(Partial::new(&input[..]));
assert_parse!(output, Ok((Partial::new(&b""[..]), &b"\n"[..])));
}
#[test]
fn cr_lf() {
assert_parse!(
- crlf(Partial::new(&b"\r\na"[..])),
+ crlf.parse_peek(Partial::new(&b"\r\na"[..])),
Ok((Partial::new(&b"a"[..]), &b"\r\n"[..]))
);
assert_parse!(
- crlf(Partial::new(&b"\r"[..])),
+ crlf.parse_peek(Partial::new(&b"\r"[..])),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_parse!(
- crlf(Partial::new(&b"\ra"[..])),
+ crlf.parse_peek(Partial::new(&b"\ra"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"\ra"[..]),
+ &Partial::new(&b"\ra"[..]),
ErrorKind::Tag
)))
);
- assert_parse!(crlf(Partial::new("\r\na")), Ok((Partial::new("a"), "\r\n")));
assert_parse!(
- crlf(Partial::new("\r")),
+ crlf.parse_peek(Partial::new("\r\na")),
+ Ok((Partial::new("a"), "\r\n"))
+ );
+ assert_parse!(
+ crlf.parse_peek(Partial::new("\r")),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_parse!(
- crlf(Partial::new("\ra")),
+ crlf.parse_peek(Partial::new("\ra")),
Err(ErrMode::Backtrack(error_position!(
- Partial::new("\ra"),
+ &Partial::new("\ra"),
ErrorKind::Tag
)))
);
@@ -1335,41 +1393,41 @@ mod partial {
#[test]
fn end_of_line() {
assert_parse!(
- line_ending(Partial::new(&b"\na"[..])),
+ line_ending.parse_peek(Partial::new(&b"\na"[..])),
Ok((Partial::new(&b"a"[..]), &b"\n"[..]))
);
assert_parse!(
- line_ending(Partial::new(&b"\r\na"[..])),
+ line_ending.parse_peek(Partial::new(&b"\r\na"[..])),
Ok((Partial::new(&b"a"[..]), &b"\r\n"[..]))
);
assert_parse!(
- line_ending(Partial::new(&b"\r"[..])),
+ line_ending.parse_peek(Partial::new(&b"\r"[..])),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_parse!(
- line_ending(Partial::new(&b"\ra"[..])),
+ line_ending.parse_peek(Partial::new(&b"\ra"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"\ra"[..]),
+ &Partial::new(&b"\ra"[..]),
ErrorKind::Tag
)))
);
assert_parse!(
- line_ending(Partial::new("\na")),
+ line_ending.parse_peek(Partial::new("\na")),
Ok((Partial::new("a"), "\n"))
);
assert_parse!(
- line_ending(Partial::new("\r\na")),
+ line_ending.parse_peek(Partial::new("\r\na")),
Ok((Partial::new("a"), "\r\n"))
);
assert_parse!(
- line_ending(Partial::new("\r")),
+ line_ending.parse_peek(Partial::new("\r")),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_parse!(
- line_ending(Partial::new("\ra")),
+ line_ending.parse_peek(Partial::new("\ra")),
Err(ErrMode::Backtrack(error_position!(
- Partial::new("\ra"),
+ &Partial::new("\ra"),
ErrorKind::Tag
)))
);
@@ -1377,14 +1435,14 @@ mod partial {
fn digit_to_i16(input: Partial<&str>) -> IResult<Partial<&str>, i16> {
let i = input;
- let (i, opt_sign) = opt(one_of("+-")).parse_next(i)?;
+ let (i, opt_sign) = opt(one_of(['+', '-'])).parse_peek(i)?;
let sign = match opt_sign {
Some('+') | None => true,
Some('-') => false,
_ => unreachable!(),
};
- let (i, s) = digit1::<_, crate::error::Error<_>>(i)?;
+ let (i, s) = digit1::<_, InputError<_>>.parse_peek(i)?;
match s.parse_slice() {
Some(n) => {
if sign {
@@ -1393,15 +1451,15 @@ mod partial {
Ok((i, -n))
}
}
- None => Err(ErrMode::from_error_kind(i, ErrorKind::Verify)),
+ None => Err(ErrMode::from_error_kind(&i, ErrorKind::Verify)),
}
}
fn digit_to_u32(i: Partial<&str>) -> IResult<Partial<&str>, u32> {
- let (i, s) = digit1(i)?;
+ let (i, s) = digit1.parse_peek(i)?;
match s.parse_slice() {
Some(n) => Ok((i, n)),
- None => Err(ErrMode::from_error_kind(i, ErrorKind::Verify)),
+ None => Err(ErrMode::from_error_kind(&i, ErrorKind::Verify)),
}
}
@@ -1410,7 +1468,7 @@ mod partial {
#[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253
fn ints(s in "\\PC*") {
let res1 = digit_to_i16(Partial::new(&s));
- let res2 = dec_int(Partial::new(s.as_str()));
+ let res2 = dec_int.parse_peek(Partial::new(s.as_str()));
assert_eq!(res1, res2);
}
@@ -1418,7 +1476,7 @@ mod partial {
#[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253
fn uints(s in "\\PC*") {
let res1 = digit_to_u32(Partial::new(&s));
- let res2 = dec_uint(Partial::new(s.as_str()));
+ let res2 = dec_uint.parse_peek(Partial::new(s.as_str()));
assert_eq!(res1, res2);
}
}
@@ -1426,13 +1484,13 @@ mod partial {
#[test]
fn hex_uint_tests() {
fn hex_u32(input: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> {
- hex_uint(input)
+ hex_uint.parse_peek(input)
}
assert_parse!(
hex_u32(Partial::new(&b";"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b";"[..]),
+ &Partial::new(&b";"[..]),
ErrorKind::Slice
)))
);
@@ -1455,14 +1513,14 @@ mod partial {
assert_parse!(
hex_u32(Partial::new(&b"00c5a31be2;"[..])), // overflow
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"00c5a31be2;"[..]),
+ &Partial::new(&b"00c5a31be2;"[..]),
ErrorKind::Verify
)))
);
assert_parse!(
hex_u32(Partial::new(&b"c5a31be201;"[..])), // overflow
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"c5a31be201;"[..]),
+ &Partial::new(&b"c5a31be201;"[..]),
ErrorKind::Verify
)))
);
@@ -1473,14 +1531,14 @@ mod partial {
assert_parse!(
hex_u32(Partial::new(&b"ffffffffffffffff;"[..])), // overflow
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"ffffffffffffffff;"[..]),
+ &Partial::new(&b"ffffffffffffffff;"[..]),
ErrorKind::Verify
)))
);
assert_parse!(
hex_u32(Partial::new(&b"ffffffffffffffff"[..])), // overflow
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"ffffffffffffffff"[..]),
+ &Partial::new(&b"ffffffffffffffff"[..]),
ErrorKind::Verify
)))
);
diff --git a/vendor/winnow/src/binary/bits/mod.rs b/vendor/winnow/src/binary/bits/mod.rs
index 5400e3308..334c6bf00 100644
--- a/vendor/winnow/src/binary/bits/mod.rs
+++ b/vendor/winnow/src/binary/bits/mod.rs
@@ -4,11 +4,11 @@
#[cfg(test)]
mod tests;
-use crate::error::{ErrMode, ErrorConvert, ErrorKind, Needed, ParseError};
+use crate::error::{ErrMode, ErrorConvert, ErrorKind, Needed, ParserError};
use crate::lib::std::ops::{AddAssign, Div, Shl, Shr};
use crate::stream::{AsBytes, Stream, StreamIsPartial, ToUsize};
use crate::trace::trace;
-use crate::{IResult, Parser};
+use crate::{unpeek, IResult, PResult, Parser};
/// Converts a byte-level input to a bit-level input
///
@@ -19,7 +19,7 @@ use crate::{IResult, Parser};
/// use winnow::prelude::*;
/// use winnow::Bytes;
/// use winnow::binary::bits::{bits, take};
-/// use winnow::error::Error;
+/// use winnow::error::InputError;
///
/// type Stream<'i> = &'i Bytes;
///
@@ -28,7 +28,7 @@ use crate::{IResult, Parser};
/// }
///
/// fn parse(input: Stream<'_>) -> IResult<Stream<'_>, (u8, u8)> {
-/// bits::<_, _, Error<(_, usize)>, _, _>((take(4usize), take(8usize))).parse_next(input)
+/// bits::<_, _, InputError<(_, usize)>, _, _>((take(4usize), take(8usize))).parse_peek(input)
/// }
///
/// let input = stream(&[0x12, 0x34, 0xff, 0xff]);
@@ -45,25 +45,28 @@ use crate::{IResult, Parser};
/// ```
pub fn bits<I, O, E1, E2, P>(mut parser: P) -> impl Parser<I, O, E2>
where
- E1: ParseError<(I, usize)> + ErrorConvert<E2>,
- E2: ParseError<I>,
- I: Stream,
+ E1: ParserError<(I, usize)> + ErrorConvert<E2>,
+ E2: ParserError<I>,
+ I: Stream + Clone,
P: Parser<(I, usize), O, E1>,
{
- trace("bits", move |input: I| {
- match parser.parse_next((input, 0)) {
- Ok(((rest, offset), result)) => {
- // If the next byte has been partially read, it will be sliced away as well.
- // The parser functions might already slice away all fully read bytes.
- // That's why `offset / 8` isn't necessarily needed at all times.
- let remaining_bytes_index = offset / 8 + if offset % 8 == 0 { 0 } else { 1 };
- let (input, _) = rest.next_slice(remaining_bytes_index);
- Ok((input, result))
+ trace(
+ "bits",
+ unpeek(move |input: I| {
+ match parser.parse_peek((input, 0)) {
+ Ok(((rest, offset), result)) => {
+ // If the next byte has been partially read, it will be sliced away as well.
+ // The parser functions might already slice away all fully read bytes.
+ // That's why `offset / 8` isn't necessarily needed at all times.
+ let remaining_bytes_index = offset / 8 + if offset % 8 == 0 { 0 } else { 1 };
+ let (input, _) = rest.peek_slice(remaining_bytes_index);
+ Ok((input, result))
+ }
+ Err(ErrMode::Incomplete(n)) => Err(ErrMode::Incomplete(n.map(|u| u.get() / 8 + 1))),
+ Err(e) => Err(e.convert()),
}
- Err(ErrMode::Incomplete(n)) => Err(ErrMode::Incomplete(n.map(|u| u.get() / 8 + 1))),
- Err(e) => Err(e.convert()),
- }
- })
+ }),
+ )
}
/// Convert a [`bits`] stream back into a byte stream
@@ -76,7 +79,7 @@ where
/// use winnow::Bytes;
/// use winnow::binary::bits::{bits, bytes, take};
/// use winnow::combinator::rest;
-/// use winnow::error::Error;
+/// use winnow::error::InputError;
///
/// type Stream<'i> = &'i Bytes;
///
@@ -85,11 +88,11 @@ where
/// }
///
/// fn parse(input: Stream<'_>) -> IResult<Stream<'_>, (u8, u8, &[u8])> {
-/// bits::<_, _, Error<(_, usize)>, _, _>((
+/// bits::<_, _, InputError<(_, usize)>, _, _>((
/// take(4usize),
/// take(8usize),
-/// bytes::<_, _, Error<_>, _, _>(rest)
-/// )).parse_next(input)
+/// bytes::<_, _, InputError<_>, _, _>(rest)
+/// )).parse_peek(input)
/// }
///
/// let input = stream(&[0x12, 0x34, 0xff, 0xff]);
@@ -98,31 +101,36 @@ where
/// ```
pub fn bytes<I, O, E1, E2, P>(mut parser: P) -> impl Parser<(I, usize), O, E2>
where
- E1: ParseError<I> + ErrorConvert<E2>,
- E2: ParseError<(I, usize)>,
- I: Stream<Token = u8>,
+ E1: ParserError<I> + ErrorConvert<E2>,
+ E2: ParserError<(I, usize)>,
+ I: Stream<Token = u8> + Clone,
P: Parser<I, O, E1>,
{
- trace("bytes", move |(input, offset): (I, usize)| {
- let (inner, _) = if offset % 8 != 0 {
- input.next_slice(1 + offset / 8)
- } else {
- input.next_slice(offset / 8)
- };
- let i = (input, offset);
- match parser.parse_next(inner) {
- Ok((rest, res)) => Ok(((rest, 0), res)),
- Err(ErrMode::Incomplete(Needed::Unknown)) => Err(ErrMode::Incomplete(Needed::Unknown)),
- Err(ErrMode::Incomplete(Needed::Size(sz))) => Err(match sz.get().checked_mul(8) {
- Some(v) => ErrMode::Incomplete(Needed::new(v)),
- None => ErrMode::Cut(E2::assert(
- i,
- "overflow in turning needed bytes into needed bits",
- )),
- }),
- Err(e) => Err(e.convert()),
- }
- })
+ trace(
+ "bytes",
+ unpeek(move |(input, offset): (I, usize)| {
+ let (inner, _) = if offset % 8 != 0 {
+ input.peek_slice(1 + offset / 8)
+ } else {
+ input.peek_slice(offset / 8)
+ };
+ let i = (input, offset);
+ match parser.parse_peek(inner) {
+ Ok((rest, res)) => Ok(((rest, 0), res)),
+ Err(ErrMode::Incomplete(Needed::Unknown)) => {
+ Err(ErrMode::Incomplete(Needed::Unknown))
+ }
+ Err(ErrMode::Incomplete(Needed::Size(sz))) => Err(match sz.get().checked_mul(8) {
+ Some(v) => ErrMode::Incomplete(Needed::new(v)),
+ None => ErrMode::Cut(E2::assert(
+ &i,
+ "overflow in turning needed bytes into needed bits",
+ )),
+ }),
+ Err(e) => Err(e.convert()),
+ }
+ }),
+ )
}
/// Parse taking `count` bits
@@ -131,7 +139,7 @@ where
/// ```rust
/// # use winnow::prelude::*;
/// # use winnow::Bytes;
-/// # use winnow::error::{Error, ErrorKind};
+/// # use winnow::error::{InputError, ErrorKind};
/// use winnow::binary::bits::take;
///
/// type Stream<'i> = &'i Bytes;
@@ -141,7 +149,7 @@ where
/// }
///
/// fn parser(input: (Stream<'_>, usize), count: usize)-> IResult<(Stream<'_>, usize), u8> {
-/// take(count).parse_next(input)
+/// take(count).parse_peek(input)
/// }
///
/// // Consumes 0 bits, returns 0
@@ -154,32 +162,35 @@ where
/// assert_eq!(parser((stream(&[0b00010010]), 4), 4), Ok(((stream(&[]), 0), 0b00000010)));
///
/// // Tries to consume 12 bits but only 8 are available
-/// assert_eq!(parser((stream(&[0b00010010]), 0), 12), Err(winnow::error::ErrMode::Backtrack(Error{input: (stream(&[0b00010010]), 0), kind: ErrorKind::Eof })));
+/// assert_eq!(parser((stream(&[0b00010010]), 0), 12), Err(winnow::error::ErrMode::Backtrack(InputError::new((stream(&[0b00010010]), 0), ErrorKind::Eof))));
/// ```
#[inline(always)]
-pub fn take<I, O, C, E: ParseError<(I, usize)>>(count: C) -> impl Parser<(I, usize), O, E>
+pub fn take<I, O, C, E: ParserError<(I, usize)>>(count: C) -> impl Parser<(I, usize), O, E>
where
- I: Stream<Token = u8> + AsBytes + StreamIsPartial,
+ I: Stream<Token = u8> + AsBytes + StreamIsPartial + Clone,
C: ToUsize,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O>,
{
let count = count.to_usize();
- trace("take", move |input: (I, usize)| {
- if <I as StreamIsPartial>::is_partial_supported() {
- take_::<_, _, _, true>(input, count)
- } else {
- take_::<_, _, _, false>(input, count)
- }
- })
+ trace(
+ "take",
+ unpeek(move |input: (I, usize)| {
+ if <I as StreamIsPartial>::is_partial_supported() {
+ take_::<_, _, _, true>(input, count)
+ } else {
+ take_::<_, _, _, false>(input, count)
+ }
+ }),
+ )
}
-fn take_<I, O, E: ParseError<(I, usize)>, const PARTIAL: bool>(
+fn take_<I, O, E: ParserError<(I, usize)>, const PARTIAL: bool>(
(input, bit_offset): (I, usize),
count: usize,
) -> IResult<(I, usize), O, E>
where
I: StreamIsPartial,
- I: Stream<Token = u8> + AsBytes,
+ I: Stream<Token = u8> + AsBytes + Clone,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O>,
{
if count == 0 {
@@ -191,7 +202,7 @@ where
Err(ErrMode::Incomplete(Needed::new(count)))
} else {
Err(ErrMode::from_error_kind(
- (input, bit_offset),
+ &(input, bit_offset),
ErrorKind::Eof,
))
}
@@ -221,7 +232,7 @@ where
offset = 0;
}
}
- let (input, _) = input.next_slice(cnt);
+ let (input, _) = input.peek_slice(cnt);
Ok(((input, end_offset), acc))
}
}
@@ -234,7 +245,7 @@ where
/// ```rust
/// # use winnow::prelude::*;
/// # use winnow::Bytes;
-/// # use winnow::error::{Error, ErrorKind};
+/// # use winnow::error::{InputError, ErrorKind};
/// use winnow::binary::bits::tag;
///
/// type Stream<'i> = &'i Bytes;
@@ -247,7 +258,7 @@ where
/// /// Return Ok and the matching section of `input` if there's a match.
/// /// Return Err if there's no match.
/// fn parser(pattern: u8, count: u8, input: (Stream<'_>, usize)) -> IResult<(Stream<'_>, usize), u8> {
-/// tag(pattern, count).parse_next(input)
+/// tag(pattern, count).parse_peek(input)
/// }
///
/// // The lowest 4 bits of 0b00001111 match the lowest 4 bits of 0b11111111.
@@ -265,42 +276,46 @@ where
/// // The lowest 2 bits of 0b11111111 and 0b00000001 are different.
/// assert_eq!(
/// parser(0b000000_01, 2, (stream(&[0b111111_11]), 0)),
-/// Err(winnow::error::ErrMode::Backtrack(Error {
-/// input: (stream(&[0b11111111]), 0),
-/// kind: ErrorKind::Tag
-/// }))
+/// Err(winnow::error::ErrMode::Backtrack(InputError::new(
+/// (stream(&[0b11111111]), 0),
+/// ErrorKind::Tag
+/// )))
/// );
///
/// // The lowest 8 bits of 0b11111111 and 0b11111110 are different.
/// assert_eq!(
/// parser(0b11111110, 8, (stream(&[0b11111111]), 0)),
-/// Err(winnow::error::ErrMode::Backtrack(Error {
-/// input: (stream(&[0b11111111]), 0),
-/// kind: ErrorKind::Tag
-/// }))
+/// Err(winnow::error::ErrMode::Backtrack(InputError::new(
+/// (stream(&[0b11111111]), 0),
+/// ErrorKind::Tag
+/// )))
/// );
/// ```
#[inline(always)]
#[doc(alias = "literal")]
#[doc(alias = "just")]
-pub fn tag<I, O, C, E: ParseError<(I, usize)>>(
+pub fn tag<I, O, C, E: ParserError<(I, usize)>>(
pattern: O,
count: C,
) -> impl Parser<(I, usize), O, E>
where
- I: Stream<Token = u8> + AsBytes + StreamIsPartial,
+ I: Stream<Token = u8> + AsBytes + StreamIsPartial + Clone,
C: ToUsize,
O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O> + PartialEq,
{
let count = count.to_usize();
- trace("tag", move |input: (I, usize)| {
- let inp = input.clone();
+ trace("tag", move |input: &mut (I, usize)| {
+ let start = input.checkpoint();
- take(count).parse_next(input).and_then(|(i, o)| {
+ take(count).parse_next(input).and_then(|o| {
if pattern == o {
- Ok((i, o))
+ Ok(o)
} else {
- Err(ErrMode::Backtrack(E::from_error_kind(inp, ErrorKind::Tag)))
+ input.reset(start);
+ Err(ErrMode::Backtrack(E::from_error_kind(
+ input,
+ ErrorKind::Tag,
+ )))
}
})
})
@@ -313,7 +328,7 @@ where
/// ```rust
/// # use winnow::prelude::*;
/// # use winnow::Bytes;
-/// # use winnow::error::{Error, ErrorKind};
+/// # use winnow::error::{InputError, ErrorKind};
/// use winnow::binary::bits::bool;
///
/// type Stream<'i> = &'i Bytes;
@@ -323,20 +338,20 @@ where
/// }
///
/// fn parse(input: (Stream<'_>, usize)) -> IResult<(Stream<'_>, usize), bool> {
-/// bool.parse_next(input)
+/// bool.parse_peek(input)
/// }
///
/// assert_eq!(parse((stream(&[0b10000000]), 0)), Ok(((stream(&[0b10000000]), 1), true)));
/// assert_eq!(parse((stream(&[0b10000000]), 1)), Ok(((stream(&[0b10000000]), 2), false)));
/// ```
#[doc(alias = "any")]
-pub fn bool<I, E: ParseError<(I, usize)>>(input: (I, usize)) -> IResult<(I, usize), bool, E>
+pub fn bool<I, E: ParserError<(I, usize)>>(input: &mut (I, usize)) -> PResult<bool, E>
where
- I: Stream<Token = u8> + AsBytes + StreamIsPartial,
+ I: Stream<Token = u8> + AsBytes + StreamIsPartial + Clone,
{
- trace("bool", |input: (I, usize)| {
- let (res, bit): (_, u32) = take(1usize).parse_next(input)?;
- Ok((res, bit != 0))
+ trace("bool", |input: &mut (I, usize)| {
+ let bit: u32 = take(1usize).parse_next(input)?;
+ Ok(bit != 0)
})
.parse_next(input)
}
diff --git a/vendor/winnow/src/binary/bits/tests.rs b/vendor/winnow/src/binary/bits/tests.rs
index 61dba2c31..41207c624 100644
--- a/vendor/winnow/src/binary/bits/tests.rs
+++ b/vendor/winnow/src/binary/bits/tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use crate::error::Error;
+use crate::error::InputError;
use crate::Partial;
#[test]
@@ -10,8 +10,8 @@ fn test_complete_byte_consumption_bits() {
// Take 3 bit slices with sizes [4, 8, 4].
let result: IResult<&[u8], (u8, u8, u8)> =
- bits::<_, _, Error<(&[u8], usize)>, _, _>((take(4usize), take(8usize), take(4usize)))
- .parse_next(input);
+ bits::<_, _, InputError<(&[u8], usize)>, _, _>((take(4usize), take(8usize), take(4usize)))
+ .parse_peek(input);
let output = result.expect("We take 2 bytes and the input is longer than 2 bytes");
@@ -34,7 +34,8 @@ fn test_partial_byte_consumption_bits() {
// Take bit slices with sizes [4, 8].
let result: IResult<&[u8], (u8, u8)> =
- bits::<_, _, Error<(&[u8], usize)>, _, _>((take(4usize), take(8usize))).parse_next(input);
+ bits::<_, _, InputError<(&[u8], usize)>, _, _>((take(4usize), take(8usize)))
+ .parse_peek(input);
let output = result.expect("We take 1.5 bytes and the input is longer than 2 bytes");
@@ -54,7 +55,7 @@ fn test_incomplete_bits() {
// Take bit slices with sizes [4, 8].
let result: IResult<_, (u8, u8)> =
- bits::<_, _, Error<(_, usize)>, _, _>((take(4usize), take(8usize))).parse_next(input);
+ bits::<_, _, InputError<(_, usize)>, _, _>((take(4usize), take(8usize))).parse_peek(input);
assert!(result.is_err());
let error = result.err().unwrap();
@@ -68,7 +69,7 @@ fn test_take_complete_0() {
assert_eq!(count, 0usize);
let offset = 0usize;
- let result: crate::IResult<(&[u8], usize), usize> = take(count).parse_next((input, offset));
+ let result: crate::IResult<(&[u8], usize), usize> = take(count).parse_peek((input, offset));
assert_eq!(result, Ok(((input, offset), 0)));
}
@@ -77,14 +78,14 @@ fn test_take_complete_0() {
fn test_take_complete_eof() {
let input = &[0b00010010][..];
- let result: crate::IResult<(&[u8], usize), usize> = take(1usize).parse_next((input, 8));
+ let result: crate::IResult<(&[u8], usize), usize> = take(1usize).parse_peek((input, 8));
assert_eq!(
result,
- Err(crate::error::ErrMode::Backtrack(crate::error::Error {
- input: (input, 8),
- kind: ErrorKind::Eof
- }))
+ Err(crate::error::ErrMode::Backtrack(InputError::new(
+ (input, 8),
+ ErrorKind::Eof
+ )))
);
}
@@ -92,7 +93,7 @@ fn test_take_complete_eof() {
fn test_take_complete_span_over_multiple_bytes() {
let input = &[0b00010010, 0b00110100, 0b11111111, 0b11111111][..];
- let result: crate::IResult<(&[u8], usize), usize> = take(24usize).parse_next((input, 4));
+ let result: crate::IResult<(&[u8], usize), usize> = take(24usize).parse_peek((input, 4));
assert_eq!(
result,
@@ -107,7 +108,7 @@ fn test_take_partial_0() {
assert_eq!(count, 0usize);
let offset = 0usize;
- let result: crate::IResult<(_, usize), usize> = take(count).parse_next((input, offset));
+ let result: crate::IResult<(_, usize), usize> = take(count).parse_peek((input, offset));
assert_eq!(result, Ok(((input, offset), 0)));
}
@@ -120,7 +121,7 @@ fn test_tag_partial_ok() {
let value_to_tag = 0b0001;
let result: crate::IResult<(_, usize), usize> =
- tag(value_to_tag, bits_to_take).parse_next((input, offset));
+ tag(value_to_tag, bits_to_take).parse_peek((input, offset));
assert_eq!(result, Ok(((input, bits_to_take), value_to_tag)));
}
@@ -133,14 +134,14 @@ fn test_tag_partial_err() {
let value_to_tag = 0b1111;
let result: crate::IResult<(_, usize), usize> =
- tag(value_to_tag, bits_to_take).parse_next((input, offset));
+ tag(value_to_tag, bits_to_take).parse_peek((input, offset));
assert_eq!(
result,
- Err(crate::error::ErrMode::Backtrack(crate::error::Error {
- input: (input, offset),
- kind: ErrorKind::Tag
- }))
+ Err(crate::error::ErrMode::Backtrack(InputError::new(
+ (input, offset),
+ ErrorKind::Tag
+ )))
);
}
@@ -148,7 +149,7 @@ fn test_tag_partial_err() {
fn test_bool_0_complete() {
let input = [0b10000000].as_ref();
- let result: crate::IResult<(&[u8], usize), bool> = bool((input, 0));
+ let result: crate::IResult<(&[u8], usize), bool> = bool.parse_peek((input, 0));
assert_eq!(result, Ok(((input, 1), true)));
}
@@ -157,14 +158,14 @@ fn test_bool_0_complete() {
fn test_bool_eof_complete() {
let input = [0b10000000].as_ref();
- let result: crate::IResult<(&[u8], usize), bool> = bool((input, 8));
+ let result: crate::IResult<(&[u8], usize), bool> = bool.parse_peek((input, 8));
assert_eq!(
result,
- Err(crate::error::ErrMode::Backtrack(crate::error::Error {
- input: (input, 8),
- kind: ErrorKind::Eof
- }))
+ Err(crate::error::ErrMode::Backtrack(InputError::new(
+ (input, 8),
+ ErrorKind::Eof
+ )))
);
}
@@ -172,7 +173,7 @@ fn test_bool_eof_complete() {
fn test_bool_0_partial() {
let input = Partial::new([0b10000000].as_ref());
- let result: crate::IResult<(Partial<&[u8]>, usize), bool> = bool((input, 0));
+ let result: crate::IResult<(Partial<&[u8]>, usize), bool> = bool.parse_peek((input, 0));
assert_eq!(result, Ok(((input, 1), true)));
}
@@ -181,7 +182,7 @@ fn test_bool_0_partial() {
fn test_bool_eof_partial() {
let input = Partial::new([0b10000000].as_ref());
- let result: crate::IResult<(Partial<&[u8]>, usize), bool> = bool.parse_next((input, 8));
+ let result: crate::IResult<(Partial<&[u8]>, usize), bool> = bool.parse_peek((input, 8));
assert_eq!(
result,
diff --git a/vendor/winnow/src/binary/mod.rs b/vendor/winnow/src/binary/mod.rs
index 80435e359..8b2ee74ee 100644
--- a/vendor/winnow/src/binary/mod.rs
+++ b/vendor/winnow/src/binary/mod.rs
@@ -11,14 +11,14 @@ use crate::combinator::repeat;
use crate::error::ErrMode;
use crate::error::ErrorKind;
use crate::error::Needed;
-use crate::error::ParseError;
+use crate::error::ParserError;
use crate::lib::std::ops::{Add, Shl};
use crate::stream::Accumulate;
use crate::stream::{AsBytes, Stream, StreamIsPartial};
use crate::stream::{ToUsize, UpdateSlice};
use crate::token::take;
use crate::trace::trace;
-use crate::IResult;
+use crate::PResult;
use crate::Parser;
/// Configurable endianness
@@ -41,34 +41,34 @@ pub enum Endianness {
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_u8;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u8> {
-/// be_u8.parse_next(s)
+/// be_u8.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
-/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token))));
+/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_u8;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> {
-/// be_u8.parse_next(s)
+/// be_u8.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"\x01abcd"[..]), 0x00)));
/// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn be_u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
+pub fn be_u8<I, E: ParserError<I>>(input: &mut I) -> PResult<u8, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
@@ -85,40 +85,40 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_u16;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u16> {
-/// be_u16.parse_next(s)
+/// be_u16.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_u16;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u16> {
-/// be_u16.parse_next(s)
+/// be_u16.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0001)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn be_u16<I, E: ParseError<I>>(input: I) -> IResult<I, u16, E>
+pub fn be_u16<I, E: ParserError<I>>(input: &mut I) -> PResult<u16, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_u16", move |input: I| be_uint(input, 2)).parse_next(input)
+ trace("be_u16", move |input: &mut I| be_uint(input, 2)).parse_next(input)
}
/// Recognizes a big endian unsigned 3 byte integer.
@@ -130,40 +130,40 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_u24;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u32> {
-/// be_u24.parse_next(s)
+/// be_u24.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_u24;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> {
-/// be_u24.parse_next(s)
+/// be_u24.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x000102)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2))));
/// ```
#[inline(always)]
-pub fn be_u24<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+pub fn be_u24<I, E: ParserError<I>>(input: &mut I) -> PResult<u32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_u23", move |input: I| be_uint(input, 3)).parse_next(input)
+ trace("be_u23", move |input: &mut I| be_uint(input, 3)).parse_next(input)
}
/// Recognizes a big endian unsigned 4 bytes integer.
@@ -175,40 +175,40 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_u32;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u32> {
-/// be_u32.parse_next(s)
+/// be_u32.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_u32;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> {
-/// be_u32.parse_next(s)
+/// be_u32.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x00010203)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3))));
/// ```
#[inline(always)]
-pub fn be_u32<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+pub fn be_u32<I, E: ParserError<I>>(input: &mut I) -> PResult<u32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_u32", move |input: I| be_uint(input, 4)).parse_next(input)
+ trace("be_u32", move |input: &mut I| be_uint(input, 4)).parse_next(input)
}
/// Recognizes a big endian unsigned 8 bytes integer.
@@ -220,40 +220,40 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_u64;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u64> {
-/// be_u64.parse_next(s)
+/// be_u64.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_u64;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u64> {
-/// be_u64.parse_next(s)
+/// be_u64.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0001020304050607)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7))));
/// ```
#[inline(always)]
-pub fn be_u64<I, E: ParseError<I>>(input: I) -> IResult<I, u64, E>
+pub fn be_u64<I, E: ParserError<I>>(input: &mut I) -> PResult<u64, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_u64", move |input: I| be_uint(input, 8)).parse_next(input)
+ trace("be_u64", move |input: &mut I| be_uint(input, 8)).parse_next(input)
}
/// Recognizes a big endian unsigned 16 bytes integer.
@@ -265,44 +265,44 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_u128;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u128> {
-/// be_u128.parse_next(s)
+/// be_u128.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_u128;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u128> {
-/// be_u128.parse_next(s)
+/// be_u128.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x00010203040506070809101112131415)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15))));
/// ```
#[inline(always)]
-pub fn be_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E>
+pub fn be_u128<I, E: ParserError<I>>(input: &mut I) -> PResult<u128, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_u128", move |input: I| be_uint(input, 16)).parse_next(input)
+ trace("be_u128", move |input: &mut I| be_uint(input, 16)).parse_next(input)
}
#[inline]
-fn be_uint<I, Uint, E: ParseError<I>>(input: I, bound: usize) -> IResult<I, Uint, E>
+fn be_uint<I, Uint, E: ParserError<I>>(input: &mut I, bound: usize) -> PResult<Uint, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
@@ -337,34 +337,34 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_i8;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i8> {
-/// be_i8.parse_next(s)
+/// be_i8.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
-/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token))));
+/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_i8;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i8> {
-/// be_i8.parse_next(s)
+/// be_i8.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"\x01abcd"[..]), 0x00)));
/// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
+pub fn be_i8<I, E: ParserError<I>>(input: &mut I) -> PResult<i8, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
@@ -381,41 +381,41 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_i16;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i16> {
-/// be_i16.parse_next(s)
+/// be_i16.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_i16;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i16> {
-/// be_i16.parse_next(s)
+/// be_i16.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0001)));
/// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(2))));
/// ```
#[inline(always)]
-pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
+pub fn be_i16<I, E: ParserError<I>>(input: &mut I) -> PResult<i16, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_i16", move |input: I| {
- be_uint::<_, u16, _>(input, 2).map(|(i, n)| (i, n as i16))
+ trace("be_i16", move |input: &mut I| {
+ be_uint::<_, u16, _>(input, 2).map(|n| n as i16)
})
.parse_next(input)
}
@@ -429,48 +429,48 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_i24;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i32> {
-/// be_i24.parse_next(s)
+/// be_i24.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_i24;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> {
-/// be_i24.parse_next(s)
+/// be_i24.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x000102)));
/// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(3))));
/// ```
#[inline(always)]
-pub fn be_i24<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+pub fn be_i24<I, E: ParserError<I>>(input: &mut I) -> PResult<i32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_i24", move |input: I| {
- be_uint::<_, u32, _>(input, 3).map(|(i, n)| {
+ trace("be_i24", move |input: &mut I| {
+ be_uint::<_, u32, _>(input, 3).map(|n| {
// Same as the unsigned version but we need to sign-extend manually here
let n = if n & 0x80_00_00 != 0 {
(n | 0xff_00_00_00) as i32
} else {
n as i32
};
- (i, n)
+ n
})
})
.parse_next(input)
@@ -485,41 +485,41 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_i32;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i32> {
-/// be_i32.parse_next(s)
+/// be_i32.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_i32;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> {
-/// be_i32.parse_next(s)
+/// be_i32.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x00010203)));
/// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(4))));
/// ```
#[inline(always)]
-pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+pub fn be_i32<I, E: ParserError<I>>(input: &mut I) -> PResult<i32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_i32", move |input: I| {
- be_uint::<_, u32, _>(input, 4).map(|(i, n)| (i, n as i32))
+ trace("be_i32", move |input: &mut I| {
+ be_uint::<_, u32, _>(input, 4).map(|n| n as i32)
})
.parse_next(input)
}
@@ -533,41 +533,41 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_i64;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i64> {
-/// be_i64.parse_next(s)
+/// be_i64.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_i64;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i64> {
-/// be_i64.parse_next(s)
+/// be_i64.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0001020304050607)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7))));
/// ```
#[inline(always)]
-pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
+pub fn be_i64<I, E: ParserError<I>>(input: &mut I) -> PResult<i64, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_i64", move |input: I| {
- be_uint::<_, u64, _>(input, 8).map(|(i, n)| (i, n as i64))
+ trace("be_i64", move |input: &mut I| {
+ be_uint::<_, u64, _>(input, 8).map(|n| n as i64)
})
.parse_next(input)
}
@@ -581,41 +581,41 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_i128;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i128> {
-/// be_i128.parse_next(s)
+/// be_i128.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_i128;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i128> {
-/// be_i128.parse_next(s)
+/// be_i128.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x00010203040506070809101112131415)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15))));
/// ```
#[inline(always)]
-pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
+pub fn be_i128<I, E: ParserError<I>>(input: &mut I) -> PResult<i128, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_i128", move |input: I| {
- be_uint::<_, u128, _>(input, 16).map(|(i, n)| (i, n as i128))
+ trace("be_i128", move |input: &mut I| {
+ be_uint::<_, u128, _>(input, 16).map(|n| n as i128)
})
.parse_next(input)
}
@@ -629,34 +629,34 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_u8;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u8> {
-/// le_u8.parse_next(s)
+/// le_u8.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
-/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token))));
+/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_u8;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> {
-/// le_u8.parse_next(s)
+/// le_u8.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"\x01abcd"[..]), 0x00)));
/// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn le_u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
+pub fn le_u8<I, E: ParserError<I>>(input: &mut I) -> PResult<u8, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
@@ -673,40 +673,40 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_u16;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u16> {
-/// le_u16.parse_next(s)
+/// le_u16.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_u16;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u16> {
-/// le_u16::<_, Error<_>>.parse_next(s)
+/// le_u16::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0100)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn le_u16<I, E: ParseError<I>>(input: I) -> IResult<I, u16, E>
+pub fn le_u16<I, E: ParserError<I>>(input: &mut I) -> PResult<u16, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("le_u16", move |input: I| le_uint(input, 2)).parse_next(input)
+ trace("le_u16", move |input: &mut I| le_uint(input, 2)).parse_next(input)
}
/// Recognizes a little endian unsigned 3 byte integer.
@@ -718,40 +718,40 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_u24;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u32> {
-/// le_u24.parse_next(s)
+/// le_u24.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_u24;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> {
-/// le_u24::<_, Error<_>>.parse_next(s)
+/// le_u24::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x020100)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2))));
/// ```
#[inline(always)]
-pub fn le_u24<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+pub fn le_u24<I, E: ParserError<I>>(input: &mut I) -> PResult<u32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("le_u24", move |input: I| le_uint(input, 3)).parse_next(input)
+ trace("le_u24", move |input: &mut I| le_uint(input, 3)).parse_next(input)
}
/// Recognizes a little endian unsigned 4 bytes integer.
@@ -763,40 +763,40 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_u32;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u32> {
-/// le_u32.parse_next(s)
+/// le_u32.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_u32;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> {
-/// le_u32::<_, Error<_>>.parse_next(s)
+/// le_u32::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x03020100)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3))));
/// ```
#[inline(always)]
-pub fn le_u32<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+pub fn le_u32<I, E: ParserError<I>>(input: &mut I) -> PResult<u32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("le_u32", move |input: I| le_uint(input, 4)).parse_next(input)
+ trace("le_u32", move |input: &mut I| le_uint(input, 4)).parse_next(input)
}
/// Recognizes a little endian unsigned 8 bytes integer.
@@ -808,40 +808,40 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_u64;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u64> {
-/// le_u64.parse_next(s)
+/// le_u64.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_u64;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u64> {
-/// le_u64::<_, Error<_>>.parse_next(s)
+/// le_u64::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0706050403020100)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7))));
/// ```
#[inline(always)]
-pub fn le_u64<I, E: ParseError<I>>(input: I) -> IResult<I, u64, E>
+pub fn le_u64<I, E: ParserError<I>>(input: &mut I) -> PResult<u64, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("le_u64", move |input: I| le_uint(input, 8)).parse_next(input)
+ trace("le_u64", move |input: &mut I| le_uint(input, 8)).parse_next(input)
}
/// Recognizes a little endian unsigned 16 bytes integer.
@@ -853,44 +853,44 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_u128;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u128> {
-/// le_u128.parse_next(s)
+/// le_u128.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_u128;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u128> {
-/// le_u128::<_, Error<_>>.parse_next(s)
+/// le_u128::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x15141312111009080706050403020100)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15))));
/// ```
#[inline(always)]
-pub fn le_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E>
+pub fn le_u128<I, E: ParserError<I>>(input: &mut I) -> PResult<u128, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("le_u128", move |input: I| le_uint(input, 16)).parse_next(input)
+ trace("le_u128", move |input: &mut I| le_uint(input, 16)).parse_next(input)
}
#[inline]
-fn le_uint<I, Uint, E: ParseError<I>>(input: I, bound: usize) -> IResult<I, Uint, E>
+fn le_uint<I, Uint, E: ParserError<I>>(input: &mut I, bound: usize) -> PResult<Uint, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
@@ -924,34 +924,34 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_i8;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i8> {
-/// le_i8.parse_next(s)
+/// le_i8.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
-/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token))));
+/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_i8;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i8> {
-/// le_i8.parse_next(s)
+/// le_i8.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"\x01abcd"[..]), 0x00)));
/// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
+pub fn le_i8<I, E: ParserError<I>>(input: &mut I) -> PResult<i8, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
@@ -968,41 +968,41 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_i16;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i16> {
-/// le_i16.parse_next(s)
+/// le_i16.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_i16;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i16> {
-/// le_i16::<_, Error<_>>.parse_next(s)
+/// le_i16::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0100)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
+pub fn le_i16<I, E: ParserError<I>>(input: &mut I) -> PResult<i16, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("le_i16", move |input: I| {
- le_uint::<_, u16, _>(input, 2).map(|(i, n)| (i, n as i16))
+ trace("le_i16", move |input: &mut I| {
+ le_uint::<_, u16, _>(input, 2).map(|n| n as i16)
})
.parse_next(input)
}
@@ -1016,48 +1016,48 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_i24;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i32> {
-/// le_i24.parse_next(s)
+/// le_i24.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_i24;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> {
-/// le_i24::<_, Error<_>>.parse_next(s)
+/// le_i24::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x020100)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2))));
/// ```
#[inline(always)]
-pub fn le_i24<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+pub fn le_i24<I, E: ParserError<I>>(input: &mut I) -> PResult<i32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("le_i24", move |input: I| {
- le_uint::<_, u32, _>(input, 3).map(|(i, n)| {
+ trace("le_i24", move |input: &mut I| {
+ le_uint::<_, u32, _>(input, 3).map(|n| {
// Same as the unsigned version but we need to sign-extend manually here
let n = if n & 0x80_00_00 != 0 {
(n | 0xff_00_00_00) as i32
} else {
n as i32
};
- (i, n)
+ n
})
})
.parse_next(input)
@@ -1072,41 +1072,41 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_i32;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i32> {
-/// le_i32.parse_next(s)
+/// le_i32.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_i32;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> {
-/// le_i32::<_, Error<_>>.parse_next(s)
+/// le_i32::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x03020100)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3))));
/// ```
#[inline(always)]
-pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+pub fn le_i32<I, E: ParserError<I>>(input: &mut I) -> PResult<i32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("le_i32", move |input: I| {
- le_uint::<_, u32, _>(input, 4).map(|(i, n)| (i, n as i32))
+ trace("le_i32", move |input: &mut I| {
+ le_uint::<_, u32, _>(input, 4).map(|n| n as i32)
})
.parse_next(input)
}
@@ -1120,41 +1120,41 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_i64;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i64> {
-/// le_i64.parse_next(s)
+/// le_i64.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_i64;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i64> {
-/// le_i64::<_, Error<_>>.parse_next(s)
+/// le_i64::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x0706050403020100)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7))));
/// ```
#[inline(always)]
-pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
+pub fn le_i64<I, E: ParserError<I>>(input: &mut I) -> PResult<i64, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("le_i64", move |input: I| {
- le_uint::<_, u64, _>(input, 8).map(|(i, n)| (i, n as i64))
+ trace("le_i64", move |input: &mut I| {
+ le_uint::<_, u64, _>(input, 8).map(|n| n as i64)
})
.parse_next(input)
}
@@ -1168,41 +1168,41 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_i128;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i128> {
-/// le_i128.parse_next(s)
+/// le_i128.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
-/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_i128;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i128> {
-/// le_i128::<_, Error<_>>.parse_next(s)
+/// le_i128::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..])), Ok((Partial::new(&b"abcd"[..]), 0x15141312111009080706050403020100)));
/// assert_eq!(parser(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15))));
/// ```
#[inline(always)]
-pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
+pub fn le_i128<I, E: ParserError<I>>(input: &mut I) -> PResult<i128, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("le_i128", move |input: I| {
- le_uint::<_, u128, _>(input, 16).map(|(i, n)| (i, n as i128))
+ trace("le_i128", move |input: &mut I| {
+ le_uint::<_, u128, _>(input, 16).map(|n| n as i128)
})
.parse_next(input)
}
@@ -1218,40 +1218,40 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::u8;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], u8> {
-/// u8.parse_next(s)
+/// u8.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
-/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token))));
+/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::u8;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> {
-/// u8::<_, Error<_>>.parse_next(s)
+/// u8::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"\x03abcefg"[..]), 0x00)));
/// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
+pub fn u8<I, E: ParserError<I>>(input: &mut I) -> PResult<u8, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
{
- trace("u8", move |input: I| {
+ trace("u8", move |input: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
u8_::<_, _, true>(input)
} else {
@@ -1261,7 +1261,7 @@ where
.parse_next(input)
}
-fn u8_<I, E: ParseError<I>, const PARTIAL: bool>(input: I) -> IResult<I, u8, E>
+fn u8_<I, E: ParserError<I>, const PARTIAL: bool>(input: &mut I) -> PResult<u8, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
@@ -1287,55 +1287,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::u16;
///
/// let be_u16 = |s| {
-/// u16(winnow::binary::Endianness::Big).parse_next(s)
+/// u16(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_u16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003)));
-/// assert_eq!(be_u16(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(be_u16(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
///
/// let le_u16 = |s| {
-/// u16(winnow::binary::Endianness::Little).parse_next(s)
+/// u16(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_u16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300)));
-/// assert_eq!(le_u16(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(le_u16(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::u16;
///
/// let be_u16 = |s| {
-/// u16::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// u16::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_u16(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0003)));
/// assert_eq!(be_u16(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
///
/// let le_u16 = |s| {
-/// u16::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// u16::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_u16(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0300)));
/// assert_eq!(le_u16(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn u16<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, u16, E>
+pub fn u16<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, u16, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_u16,
Endianness::Little => le_u16,
@@ -1359,55 +1359,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::u24;
///
/// let be_u24 = |s| {
-/// u24(winnow::binary::Endianness::Big).parse_next(s)
+/// u24(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_u24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305)));
-/// assert_eq!(be_u24(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(be_u24(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
///
/// let le_u24 = |s| {
-/// u24(winnow::binary::Endianness::Little).parse_next(s)
+/// u24(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_u24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300)));
-/// assert_eq!(le_u24(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(le_u24(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::u24;
///
/// let be_u24 = |s| {
-/// u24::<_,Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// u24::<_,InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_u24(Partial::new(&b"\x00\x03\x05abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x000305)));
/// assert_eq!(be_u24(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2))));
///
/// let le_u24 = |s| {
-/// u24::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// u24::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_u24(Partial::new(&b"\x00\x03\x05abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x050300)));
/// assert_eq!(le_u24(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2))));
/// ```
#[inline(always)]
-pub fn u24<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, u32, E>
+pub fn u24<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, u32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_u24,
Endianness::Little => le_u24,
@@ -1431,55 +1431,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::u32;
///
/// let be_u32 = |s| {
-/// u32(winnow::binary::Endianness::Big).parse_next(s)
+/// u32(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_u32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507)));
-/// assert_eq!(be_u32(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(be_u32(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
///
/// let le_u32 = |s| {
-/// u32(winnow::binary::Endianness::Little).parse_next(s)
+/// u32(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_u32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300)));
-/// assert_eq!(le_u32(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(le_u32(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::u32;
///
/// let be_u32 = |s| {
-/// u32::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// u32::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_u32(Partial::new(&b"\x00\x03\x05\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x00030507)));
/// assert_eq!(be_u32(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3))));
///
/// let le_u32 = |s| {
-/// u32::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// u32::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_u32(Partial::new(&b"\x00\x03\x05\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x07050300)));
/// assert_eq!(le_u32(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3))));
/// ```
#[inline(always)]
-pub fn u32<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, u32, E>
+pub fn u32<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, u32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_u32,
Endianness::Little => le_u32,
@@ -1503,55 +1503,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::u64;
///
/// let be_u64 = |s| {
-/// u64(winnow::binary::Endianness::Big).parse_next(s)
+/// u64(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_u64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607)));
-/// assert_eq!(be_u64(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(be_u64(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
///
/// let le_u64 = |s| {
-/// u64(winnow::binary::Endianness::Little).parse_next(s)
+/// u64(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_u64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100)));
-/// assert_eq!(le_u64(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(le_u64(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::u64;
///
/// let be_u64 = |s| {
-/// u64::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// u64::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_u64(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0001020304050607)));
/// assert_eq!(be_u64(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7))));
///
/// let le_u64 = |s| {
-/// u64::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// u64::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_u64(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0706050403020100)));
/// assert_eq!(le_u64(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7))));
/// ```
#[inline(always)]
-pub fn u64<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, u64, E>
+pub fn u64<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, u64, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_u64,
Endianness::Little => le_u64,
@@ -1575,55 +1575,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::u128;
///
/// let be_u128 = |s| {
-/// u128(winnow::binary::Endianness::Big).parse_next(s)
+/// u128(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_u128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
-/// assert_eq!(be_u128(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(be_u128(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
///
/// let le_u128 = |s| {
-/// u128(winnow::binary::Endianness::Little).parse_next(s)
+/// u128(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_u128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
-/// assert_eq!(le_u128(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(le_u128(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::u128;
///
/// let be_u128 = |s| {
-/// u128::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// u128::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_u128(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x00010203040506070001020304050607)));
/// assert_eq!(be_u128(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15))));
///
/// let le_u128 = |s| {
-/// u128::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// u128::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_u128(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x07060504030201000706050403020100)));
/// assert_eq!(le_u128(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15))));
/// ```
#[inline(always)]
-pub fn u128<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, u128, E>
+pub fn u128<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, u128, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_u128,
Endianness::Little => le_u128,
@@ -1646,46 +1646,46 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::i8;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], i8> {
-/// i8.parse_next(s)
+/// i8.parse_peek(s)
/// }
///
/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
-/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&[][..], ErrorKind::Token))));
+/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&[][..], ErrorKind::Token))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::i8;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i8> {
-/// i8.parse_next(s)
+/// i8.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"\x03abcefg"[..]), 0x00)));
/// assert_eq!(parser(Partial::new(&b""[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
+pub fn i8<I, E: ParserError<I>>(input: &mut I) -> PResult<i8, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
{
- trace("i8", move |input: I| {
+ trace("i8", move |input: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
u8_::<_, _, true>(input)
} else {
u8_::<_, _, false>(input)
}
- .map(|(i, n)| (i, n as i8))
+ .map(|n| n as i8)
})
.parse_next(input)
}
@@ -1702,55 +1702,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::i16;
///
/// let be_i16 = |s| {
-/// i16(winnow::binary::Endianness::Big).parse_next(s)
+/// i16(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_i16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003)));
-/// assert_eq!(be_i16(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(be_i16(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
///
/// let le_i16 = |s| {
-/// i16(winnow::binary::Endianness::Little).parse_next(s)
+/// i16(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_i16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300)));
-/// assert_eq!(le_i16(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(le_i16(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::i16;
///
/// let be_i16 = |s| {
-/// i16::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// i16::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_i16(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0003)));
/// assert_eq!(be_i16(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
///
/// let le_i16 = |s| {
-/// i16::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// i16::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_i16(Partial::new(&b"\x00\x03abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0300)));
/// assert_eq!(le_i16(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn i16<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, i16, E>
+pub fn i16<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, i16, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_i16,
Endianness::Little => le_i16,
@@ -1774,55 +1774,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::i24;
///
/// let be_i24 = |s| {
-/// i24(winnow::binary::Endianness::Big).parse_next(s)
+/// i24(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_i24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305)));
-/// assert_eq!(be_i24(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(be_i24(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
///
/// let le_i24 = |s| {
-/// i24(winnow::binary::Endianness::Little).parse_next(s)
+/// i24(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_i24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300)));
-/// assert_eq!(le_i24(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(le_i24(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::i24;
///
/// let be_i24 = |s| {
-/// i24::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// i24::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_i24(Partial::new(&b"\x00\x03\x05abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x000305)));
/// assert_eq!(be_i24(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2))));
///
/// let le_i24 = |s| {
-/// i24::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// i24::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_i24(Partial::new(&b"\x00\x03\x05abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x050300)));
/// assert_eq!(le_i24(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(2))));
/// ```
#[inline(always)]
-pub fn i24<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, i32, E>
+pub fn i24<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, i32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_i24,
Endianness::Little => le_i24,
@@ -1846,55 +1846,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::i32;
///
/// let be_i32 = |s| {
-/// i32(winnow::binary::Endianness::Big).parse_next(s)
+/// i32(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_i32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507)));
-/// assert_eq!(be_i32(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(be_i32(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
///
/// let le_i32 = |s| {
-/// i32(winnow::binary::Endianness::Little).parse_next(s)
+/// i32(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_i32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300)));
-/// assert_eq!(le_i32(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(le_i32(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::i32;
///
/// let be_i32 = |s| {
-/// i32::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// i32::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_i32(Partial::new(&b"\x00\x03\x05\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x00030507)));
/// assert_eq!(be_i32(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3))));
///
/// let le_i32 = |s| {
-/// i32::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// i32::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_i32(Partial::new(&b"\x00\x03\x05\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x07050300)));
/// assert_eq!(le_i32(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(3))));
/// ```
#[inline(always)]
-pub fn i32<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, i32, E>
+pub fn i32<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, i32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_i32,
Endianness::Little => le_i32,
@@ -1918,55 +1918,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::i64;
///
/// let be_i64 = |s| {
-/// i64(winnow::binary::Endianness::Big).parse_next(s)
+/// i64(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_i64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607)));
-/// assert_eq!(be_i64(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(be_i64(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
///
/// let le_i64 = |s| {
-/// i64(winnow::binary::Endianness::Little).parse_next(s)
+/// i64(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_i64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100)));
-/// assert_eq!(le_i64(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(le_i64(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::i64;
///
/// let be_i64 = |s| {
-/// i64::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// i64::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_i64(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0001020304050607)));
/// assert_eq!(be_i64(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7))));
///
/// let le_i64 = |s| {
-/// i64::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// i64::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_i64(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x0706050403020100)));
/// assert_eq!(le_i64(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(7))));
/// ```
#[inline(always)]
-pub fn i64<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, i64, E>
+pub fn i64<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, i64, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_i64,
Endianness::Little => le_i64,
@@ -1990,55 +1990,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::i128;
///
/// let be_i128 = |s| {
-/// i128(winnow::binary::Endianness::Big).parse_next(s)
+/// i128(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_i128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
-/// assert_eq!(be_i128(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(be_i128(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
///
/// let le_i128 = |s| {
-/// i128(winnow::binary::Endianness::Little).parse_next(s)
+/// i128(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_i128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
-/// assert_eq!(le_i128(&b"\x01"[..]), Err(ErrMode::Backtrack(Error::new(&[0x01][..], ErrorKind::Slice))));
+/// assert_eq!(le_i128(&b"\x01"[..]), Err(ErrMode::Backtrack(InputError::new(&[0x01][..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::i128;
///
/// let be_i128 = |s| {
-/// i128::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// i128::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_i128(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x00010203040506070001020304050607)));
/// assert_eq!(be_i128(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15))));
///
/// let le_i128 = |s| {
-/// i128::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// i128::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_i128(Partial::new(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..])), Ok((Partial::new(&b"abcefg"[..]), 0x07060504030201000706050403020100)));
/// assert_eq!(le_i128(Partial::new(&b"\x01"[..])), Err(ErrMode::Incomplete(Needed::new(15))));
/// ```
#[inline(always)]
-pub fn i128<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, i128, E>
+pub fn i128<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, i128, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_i128,
Endianness::Little => le_i128,
@@ -2059,42 +2059,42 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_f32;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], f32> {
-/// be_f32.parse_next(s)
+/// be_f32.parse_peek(s)
/// }
///
/// assert_eq!(parser(&[0x41, 0x48, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_f32;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, f32> {
-/// be_f32.parse_next(s)
+/// be_f32.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&[0x40, 0x29, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 2.640625)));
/// assert_eq!(parser(Partial::new(&[0x01][..])), Err(ErrMode::Incomplete(Needed::new(3))));
/// ```
#[inline(always)]
-pub fn be_f32<I, E: ParseError<I>>(input: I) -> IResult<I, f32, E>
+pub fn be_f32<I, E: ParserError<I>>(input: &mut I) -> PResult<f32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_f32", move |input: I| {
- be_uint::<_, u32, _>(input, 4).map(|(i, n)| (i, f32::from_bits(n)))
+ trace("be_f32", move |input: &mut I| {
+ be_uint::<_, u32, _>(input, 4).map(f32::from_bits)
})
.parse_next(input)
}
@@ -2108,41 +2108,41 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::be_f64;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], f64> {
-/// be_f64.parse_next(s)
+/// be_f64.parse_peek(s)
/// }
///
/// assert_eq!(parser(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::be_f64;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, f64> {
-/// be_f64::<_, Error<_>>.parse_next(s)
+/// be_f64::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 12.5)));
/// assert_eq!(parser(Partial::new(&[0x01][..])), Err(ErrMode::Incomplete(Needed::new(7))));
/// ```
#[inline(always)]
-pub fn be_f64<I, E: ParseError<I>>(input: I) -> IResult<I, f64, E>
+pub fn be_f64<I, E: ParserError<I>>(input: &mut I) -> PResult<f64, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_f64", move |input: I| {
- be_uint::<_, u64, _>(input, 8).map(|(i, n)| (i, f64::from_bits(n)))
+ trace("be_f64", move |input: &mut I| {
+ be_uint::<_, u64, _>(input, 8).map(f64::from_bits)
})
.parse_next(input)
}
@@ -2156,41 +2156,41 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_f32;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], f32> {
-/// le_f32.parse_next(s)
+/// le_f32.parse_peek(s)
/// }
///
/// assert_eq!(parser(&[0x00, 0x00, 0x48, 0x41][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_f32;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, f32> {
-/// le_f32::<_, Error<_>>.parse_next(s)
+/// le_f32::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&[0x00, 0x00, 0x48, 0x41][..])), Ok((Partial::new(&b""[..]), 12.5)));
/// assert_eq!(parser(Partial::new(&[0x01][..])), Err(ErrMode::Incomplete(Needed::new(3))));
/// ```
#[inline(always)]
-pub fn le_f32<I, E: ParseError<I>>(input: I) -> IResult<I, f32, E>
+pub fn le_f32<I, E: ParserError<I>>(input: &mut I) -> PResult<f32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("le_f32", move |input: I| {
- le_uint::<_, u32, _>(input, 4).map(|(i, n)| (i, f32::from_bits(n)))
+ trace("le_f32", move |input: &mut I| {
+ le_uint::<_, u32, _>(input, 4).map(f32::from_bits)
})
.parse_next(input)
}
@@ -2204,41 +2204,41 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::le_f64;
///
/// fn parser(s: &[u8]) -> IResult<&[u8], f64> {
-/// le_f64.parse_next(s)
+/// le_f64.parse_peek(s)
/// }
///
/// assert_eq!(parser(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice))));
+/// assert_eq!(parser(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::binary::le_f64;
///
/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, f64> {
-/// le_f64::<_, Error<_>>.parse_next(s)
+/// le_f64::<_, InputError<_>>.parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x41][..])), Ok((Partial::new(&b""[..]), 3145728.0)));
/// assert_eq!(parser(Partial::new(&[0x01][..])), Err(ErrMode::Incomplete(Needed::new(7))));
/// ```
#[inline(always)]
-pub fn le_f64<I, E: ParseError<I>>(input: I) -> IResult<I, f64, E>
+pub fn le_f64<I, E: ParserError<I>>(input: &mut I) -> PResult<f64, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- trace("be_f64", move |input: I| {
- le_uint::<_, u64, _>(input, 8).map(|(i, n)| (i, f64::from_bits(n)))
+ trace("be_f64", move |input: &mut I| {
+ le_uint::<_, u64, _>(input, 8).map(f64::from_bits)
})
.parse_next(input)
}
@@ -2255,55 +2255,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::f32;
///
/// let be_f32 = |s| {
-/// f32(winnow::binary::Endianness::Big).parse_next(s)
+/// f32(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_f32(&[0x41, 0x48, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(be_f32(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice))));
+/// assert_eq!(be_f32(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice))));
///
/// let le_f32 = |s| {
-/// f32(winnow::binary::Endianness::Little).parse_next(s)
+/// f32(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_f32(&[0x00, 0x00, 0x48, 0x41][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(le_f32(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice))));
+/// assert_eq!(le_f32(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::f32;
///
/// let be_f32 = |s| {
-/// f32::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// f32::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_f32(Partial::new(&[0x41, 0x48, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 12.5)));
/// assert_eq!(be_f32(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
///
/// let le_f32 = |s| {
-/// f32::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// f32::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_f32(Partial::new(&[0x00, 0x00, 0x48, 0x41][..])), Ok((Partial::new(&b""[..]), 12.5)));
/// assert_eq!(le_f32(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn f32<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, f32, E>
+pub fn f32<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, f32, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_f32,
Endianness::Little => le_f32,
@@ -2327,55 +2327,55 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::binary::f64;
///
/// let be_f64 = |s| {
-/// f64(winnow::binary::Endianness::Big).parse_next(s)
+/// f64(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_f64(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(be_f64(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice))));
+/// assert_eq!(be_f64(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice))));
///
/// let le_f64 = |s| {
-/// f64(winnow::binary::Endianness::Little).parse_next(s)
+/// f64(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(le_f64(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice))));
+/// assert_eq!(le_f64(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::binary::f64;
///
/// let be_f64 = |s| {
-/// f64::<_, Error<_>>(winnow::binary::Endianness::Big).parse_next(s)
+/// f64::<_, InputError<_>>(winnow::binary::Endianness::Big).parse_peek(s)
/// };
///
/// assert_eq!(be_f64(Partial::new(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])), Ok((Partial::new(&b""[..]), 12.5)));
/// assert_eq!(be_f64(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(5))));
///
/// let le_f64 = |s| {
-/// f64::<_, Error<_>>(winnow::binary::Endianness::Little).parse_next(s)
+/// f64::<_, InputError<_>>(winnow::binary::Endianness::Little).parse_peek(s)
/// };
///
/// assert_eq!(le_f64(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40][..])), Ok((Partial::new(&b""[..]), 12.5)));
/// assert_eq!(le_f64(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(5))));
/// ```
#[inline(always)]
-pub fn f64<I, E: ParseError<I>>(endian: Endianness) -> impl Parser<I, f64, E>
+pub fn f64<I, E: ParserError<I>>(endian: Endianness) -> impl Parser<I, f64, E>
where
I: StreamIsPartial,
I: Stream<Token = u8>,
<I as Stream>::Slice: AsBytes,
{
- move |input: I| {
+ move |input: &mut I| {
match endian {
Endianness::Big => be_f64,
Endianness::Little => le_f64,
@@ -2414,7 +2414,7 @@ where
/// }
///
/// fn parser(s: Stream<'_>) -> IResult<Stream<'_>, &[u8]> {
-/// length_data(be_u16).parse_next(s)
+/// length_data(be_u16).parse_peek(s)
/// }
///
/// assert_eq!(parser(stream(b"\x00\x03abcefg")), Ok((stream(&b"efg"[..]), &b"abc"[..])));
@@ -2426,10 +2426,10 @@ where
I: Stream,
N: ToUsize,
F: Parser<I, N, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
- trace("length_data", move |i: I| {
- let (i, length) = f.parse_next(i)?;
+ trace("length_data", move |i: &mut I| {
+ let length = f.parse_next(i)?;
crate::token::take(length).parse_next(i)
})
@@ -2452,7 +2452,7 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed, stream::{Partial, StreamIsPartial}};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed, stream::{Partial, StreamIsPartial}};
/// # use winnow::prelude::*;
/// use winnow::Bytes;
/// use winnow::binary::be_u16;
@@ -2472,28 +2472,28 @@ where
/// }
///
/// fn parser(s: Stream<'_>) -> IResult<Stream<'_>, &[u8]> {
-/// length_value(be_u16, "abc").parse_next(s)
+/// length_value(be_u16, "abc").parse_peek(s)
/// }
///
/// assert_eq!(parser(stream(b"\x00\x03abcefg")), Ok((stream(&b"efg"[..]), &b"abc"[..])));
-/// assert_eq!(parser(stream(b"\x00\x03123123")), Err(ErrMode::Backtrack(Error::new(complete_stream(&b"123"[..]), ErrorKind::Tag))));
+/// assert_eq!(parser(stream(b"\x00\x03123123")), Err(ErrMode::Backtrack(InputError::new(complete_stream(&b"123"[..]), ErrorKind::Tag))));
/// assert_eq!(parser(stream(b"\x00\x03a")), Err(ErrMode::Incomplete(Needed::new(2))));
/// ```
pub fn length_value<I, O, N, E, F, G>(mut f: F, mut g: G) -> impl Parser<I, O, E>
where
I: StreamIsPartial,
- I: Stream + UpdateSlice,
+ I: Stream + UpdateSlice + Clone,
N: ToUsize,
F: Parser<I, N, E>,
G: Parser<I, O, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
- trace("length_value", move |i: I| {
- let (i, data) = length_data(f.by_ref()).parse_next(i)?;
+ trace("length_value", move |i: &mut I| {
+ let data = length_data(f.by_ref()).parse_next(i)?;
let mut data = I::update_slice(i.clone(), data);
let _ = data.complete();
- let (_, o) = g.by_ref().complete_err().parse_next(data)?;
- Ok((i, o))
+ let o = g.by_ref().complete_err().parse_next(&mut data)?;
+ Ok(o)
})
}
@@ -2509,7 +2509,7 @@ where
/// ```rust
/// # #[cfg(feature = "std")] {
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::Bytes;
/// use winnow::binary::u8;
@@ -2526,11 +2526,11 @@ where
/// length_count(u8.map(|i| {
/// println!("got number: {}", i);
/// i
-/// }), "abc").parse_next(s)
+/// }), "abc").parse_peek(s)
/// }
///
/// assert_eq!(parser(stream(b"\x02abcabcabc")), Ok((stream(b"abc"), vec![&b"abc"[..], &b"abc"[..]])));
-/// assert_eq!(parser(stream(b"\x03123123123")), Err(ErrMode::Backtrack(Error::new(stream(b"123123123"), ErrorKind::Tag))));
+/// assert_eq!(parser(stream(b"\x03123123123")), Err(ErrMode::Backtrack(InputError::new(stream(b"123123123"), ErrorKind::Tag))));
/// # }
/// ```
pub fn length_count<I, O, C, N, E, F, G>(mut f: F, mut g: G) -> impl Parser<I, C, E>
@@ -2540,10 +2540,10 @@ where
C: Accumulate<O>,
F: Parser<I, N, E>,
G: Parser<I, O, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
- trace("length_count", move |i: I| {
- let (i, n) = f.parse_next(i)?;
+ trace("length_count", move |i: &mut I| {
+ let n = f.parse_next(i)?;
let n = n.to_usize();
repeat(n, g.by_ref()).parse_next(i)
})
diff --git a/vendor/winnow/src/binary/tests.rs b/vendor/winnow/src/binary/tests.rs
index 4307d88fe..5d92055ac 100644
--- a/vendor/winnow/src/binary/tests.rs
+++ b/vendor/winnow/src/binary/tests.rs
@@ -1,70 +1,96 @@
use super::*;
+use crate::unpeek;
+use crate::IResult;
mod complete {
use super::*;
- use crate::error::Error;
+ use crate::error::InputError;
macro_rules! assert_parse(
($left: expr, $right: expr) => {
- let res: $crate::IResult<_, _, Error<_>> = $left;
+ let res: $crate::IResult<_, _, InputError<_>> = $left;
assert_eq!(res, $right);
};
);
#[test]
fn i8_tests() {
- assert_parse!(i8(&[0x00][..]), Ok((&b""[..], 0)));
- assert_parse!(i8(&[0x7f][..]), Ok((&b""[..], 127)));
- assert_parse!(i8(&[0xff][..]), Ok((&b""[..], -1)));
- assert_parse!(i8(&[0x80][..]), Ok((&b""[..], -128)));
+ assert_parse!(i8.parse_peek(&[0x00][..]), Ok((&b""[..], 0)));
+ assert_parse!(i8.parse_peek(&[0x7f][..]), Ok((&b""[..], 127)));
+ assert_parse!(i8.parse_peek(&[0xff][..]), Ok((&b""[..], -1)));
+ assert_parse!(i8.parse_peek(&[0x80][..]), Ok((&b""[..], -128)));
}
#[test]
fn be_i8_tests() {
- assert_parse!(be_i8(&[0x00][..]), Ok((&b""[..], 0)));
- assert_parse!(be_i8(&[0x7f][..]), Ok((&b""[..], 127)));
- assert_parse!(be_i8(&[0xff][..]), Ok((&b""[..], -1)));
- assert_parse!(be_i8(&[0x80][..]), Ok((&b""[..], -128)));
+ assert_parse!(be_i8.parse_peek(&[0x00][..]), Ok((&b""[..], 0)));
+ assert_parse!(be_i8.parse_peek(&[0x7f][..]), Ok((&b""[..], 127)));
+ assert_parse!(be_i8.parse_peek(&[0xff][..]), Ok((&b""[..], -1)));
+ assert_parse!(be_i8.parse_peek(&[0x80][..]), Ok((&b""[..], -128)));
}
#[test]
fn be_i16_tests() {
- assert_parse!(be_i16(&[0x00, 0x00][..]), Ok((&b""[..], 0)));
- assert_parse!(be_i16(&[0x7f, 0xff][..]), Ok((&b""[..], 32_767_i16)));
- assert_parse!(be_i16(&[0xff, 0xff][..]), Ok((&b""[..], -1)));
- assert_parse!(be_i16(&[0x80, 0x00][..]), Ok((&b""[..], -32_768_i16)));
+ assert_parse!(be_i16.parse_peek(&[0x00, 0x00][..]), Ok((&b""[..], 0)));
+ assert_parse!(
+ be_i16.parse_peek(&[0x7f, 0xff][..]),
+ Ok((&b""[..], 32_767_i16))
+ );
+ assert_parse!(be_i16.parse_peek(&[0xff, 0xff][..]), Ok((&b""[..], -1)));
+ assert_parse!(
+ be_i16.parse_peek(&[0x80, 0x00][..]),
+ Ok((&b""[..], -32_768_i16))
+ );
}
#[test]
fn be_u24_tests() {
- assert_parse!(be_u24(&[0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
- assert_parse!(be_u24(&[0x00, 0xFF, 0xFF][..]), Ok((&b""[..], 65_535_u32)));
assert_parse!(
- be_u24(&[0x12, 0x34, 0x56][..]),
+ be_u24.parse_peek(&[0x00, 0x00, 0x00][..]),
+ Ok((&b""[..], 0))
+ );
+ assert_parse!(
+ be_u24.parse_peek(&[0x00, 0xFF, 0xFF][..]),
+ Ok((&b""[..], 65_535_u32))
+ );
+ assert_parse!(
+ be_u24.parse_peek(&[0x12, 0x34, 0x56][..]),
Ok((&b""[..], 1_193_046_u32))
);
}
#[test]
fn be_i24_tests() {
- assert_parse!(be_i24(&[0xFF, 0xFF, 0xFF][..]), Ok((&b""[..], -1_i32)));
- assert_parse!(be_i24(&[0xFF, 0x00, 0x00][..]), Ok((&b""[..], -65_536_i32)));
assert_parse!(
- be_i24(&[0xED, 0xCB, 0xAA][..]),
+ be_i24.parse_peek(&[0xFF, 0xFF, 0xFF][..]),
+ Ok((&b""[..], -1_i32))
+ );
+ assert_parse!(
+ be_i24.parse_peek(&[0xFF, 0x00, 0x00][..]),
+ Ok((&b""[..], -65_536_i32))
+ );
+ assert_parse!(
+ be_i24.parse_peek(&[0xED, 0xCB, 0xAA][..]),
Ok((&b""[..], -1_193_046_i32))
);
}
#[test]
fn be_i32_tests() {
- assert_parse!(be_i32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
assert_parse!(
- be_i32(&[0x7f, 0xff, 0xff, 0xff][..]),
+ be_i32.parse_peek(&[0x00, 0x00, 0x00, 0x00][..]),
+ Ok((&b""[..], 0))
+ );
+ assert_parse!(
+ be_i32.parse_peek(&[0x7f, 0xff, 0xff, 0xff][..]),
Ok((&b""[..], 2_147_483_647_i32))
);
- assert_parse!(be_i32(&[0xff, 0xff, 0xff, 0xff][..]), Ok((&b""[..], -1)));
assert_parse!(
- be_i32(&[0x80, 0x00, 0x00, 0x00][..]),
+ be_i32.parse_peek(&[0xff, 0xff, 0xff, 0xff][..]),
+ Ok((&b""[..], -1))
+ );
+ assert_parse!(
+ be_i32.parse_peek(&[0x80, 0x00, 0x00, 0x00][..]),
Ok((&b""[..], -2_147_483_648_i32))
);
}
@@ -72,19 +98,19 @@ mod complete {
#[test]
fn be_i64_tests() {
assert_parse!(
- be_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+ be_i64.parse_peek(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
Ok((&b""[..], 0))
);
assert_parse!(
- be_i64(&[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
+ be_i64.parse_peek(&[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
Ok((&b""[..], 9_223_372_036_854_775_807_i64))
);
assert_parse!(
- be_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
+ be_i64.parse_peek(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
Ok((&b""[..], -1))
);
assert_parse!(
- be_i64(&[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+ be_i64.parse_peek(&[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
Ok((&b""[..], -9_223_372_036_854_775_808_i64))
);
}
@@ -92,7 +118,7 @@ mod complete {
#[test]
fn be_i128_tests() {
assert_parse!(
- be_i128(
+ be_i128.parse_peek(
&[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
@@ -101,7 +127,7 @@ mod complete {
Ok((&b""[..], 0))
);
assert_parse!(
- be_i128(
+ be_i128.parse_peek(
&[
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff
@@ -113,7 +139,7 @@ mod complete {
))
);
assert_parse!(
- be_i128(
+ be_i128.parse_peek(
&[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff
@@ -122,7 +148,7 @@ mod complete {
Ok((&b""[..], -1))
);
assert_parse!(
- be_i128(
+ be_i128.parse_peek(
&[
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
@@ -137,50 +163,74 @@ mod complete {
#[test]
fn le_i8_tests() {
- assert_parse!(le_i8(&[0x00][..]), Ok((&b""[..], 0)));
- assert_parse!(le_i8(&[0x7f][..]), Ok((&b""[..], 127)));
- assert_parse!(le_i8(&[0xff][..]), Ok((&b""[..], -1)));
- assert_parse!(le_i8(&[0x80][..]), Ok((&b""[..], -128)));
+ assert_parse!(le_i8.parse_peek(&[0x00][..]), Ok((&b""[..], 0)));
+ assert_parse!(le_i8.parse_peek(&[0x7f][..]), Ok((&b""[..], 127)));
+ assert_parse!(le_i8.parse_peek(&[0xff][..]), Ok((&b""[..], -1)));
+ assert_parse!(le_i8.parse_peek(&[0x80][..]), Ok((&b""[..], -128)));
}
#[test]
fn le_i16_tests() {
- assert_parse!(le_i16(&[0x00, 0x00][..]), Ok((&b""[..], 0)));
- assert_parse!(le_i16(&[0xff, 0x7f][..]), Ok((&b""[..], 32_767_i16)));
- assert_parse!(le_i16(&[0xff, 0xff][..]), Ok((&b""[..], -1)));
- assert_parse!(le_i16(&[0x00, 0x80][..]), Ok((&b""[..], -32_768_i16)));
+ assert_parse!(le_i16.parse_peek(&[0x00, 0x00][..]), Ok((&b""[..], 0)));
+ assert_parse!(
+ le_i16.parse_peek(&[0xff, 0x7f][..]),
+ Ok((&b""[..], 32_767_i16))
+ );
+ assert_parse!(le_i16.parse_peek(&[0xff, 0xff][..]), Ok((&b""[..], -1)));
+ assert_parse!(
+ le_i16.parse_peek(&[0x00, 0x80][..]),
+ Ok((&b""[..], -32_768_i16))
+ );
}
#[test]
fn le_u24_tests() {
- assert_parse!(le_u24(&[0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
- assert_parse!(le_u24(&[0xFF, 0xFF, 0x00][..]), Ok((&b""[..], 65_535_u32)));
assert_parse!(
- le_u24(&[0x56, 0x34, 0x12][..]),
+ le_u24.parse_peek(&[0x00, 0x00, 0x00][..]),
+ Ok((&b""[..], 0))
+ );
+ assert_parse!(
+ le_u24.parse_peek(&[0xFF, 0xFF, 0x00][..]),
+ Ok((&b""[..], 65_535_u32))
+ );
+ assert_parse!(
+ le_u24.parse_peek(&[0x56, 0x34, 0x12][..]),
Ok((&b""[..], 1_193_046_u32))
);
}
#[test]
fn le_i24_tests() {
- assert_parse!(le_i24(&[0xFF, 0xFF, 0xFF][..]), Ok((&b""[..], -1_i32)));
- assert_parse!(le_i24(&[0x00, 0x00, 0xFF][..]), Ok((&b""[..], -65_536_i32)));
assert_parse!(
- le_i24(&[0xAA, 0xCB, 0xED][..]),
+ le_i24.parse_peek(&[0xFF, 0xFF, 0xFF][..]),
+ Ok((&b""[..], -1_i32))
+ );
+ assert_parse!(
+ le_i24.parse_peek(&[0x00, 0x00, 0xFF][..]),
+ Ok((&b""[..], -65_536_i32))
+ );
+ assert_parse!(
+ le_i24.parse_peek(&[0xAA, 0xCB, 0xED][..]),
Ok((&b""[..], -1_193_046_i32))
);
}
#[test]
fn le_i32_tests() {
- assert_parse!(le_i32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
assert_parse!(
- le_i32(&[0xff, 0xff, 0xff, 0x7f][..]),
+ le_i32.parse_peek(&[0x00, 0x00, 0x00, 0x00][..]),
+ Ok((&b""[..], 0))
+ );
+ assert_parse!(
+ le_i32.parse_peek(&[0xff, 0xff, 0xff, 0x7f][..]),
Ok((&b""[..], 2_147_483_647_i32))
);
- assert_parse!(le_i32(&[0xff, 0xff, 0xff, 0xff][..]), Ok((&b""[..], -1)));
assert_parse!(
- le_i32(&[0x00, 0x00, 0x00, 0x80][..]),
+ le_i32.parse_peek(&[0xff, 0xff, 0xff, 0xff][..]),
+ Ok((&b""[..], -1))
+ );
+ assert_parse!(
+ le_i32.parse_peek(&[0x00, 0x00, 0x00, 0x80][..]),
Ok((&b""[..], -2_147_483_648_i32))
);
}
@@ -188,19 +238,19 @@ mod complete {
#[test]
fn le_i64_tests() {
assert_parse!(
- le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+ le_i64.parse_peek(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
Ok((&b""[..], 0))
);
assert_parse!(
- le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f][..]),
+ le_i64.parse_peek(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f][..]),
Ok((&b""[..], 9_223_372_036_854_775_807_i64))
);
assert_parse!(
- le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
+ le_i64.parse_peek(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
Ok((&b""[..], -1))
);
assert_parse!(
- le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80][..]),
+ le_i64.parse_peek(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80][..]),
Ok((&b""[..], -9_223_372_036_854_775_808_i64))
);
}
@@ -208,7 +258,7 @@ mod complete {
#[test]
fn le_i128_tests() {
assert_parse!(
- le_i128(
+ le_i128.parse_peek(
&[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
@@ -217,7 +267,7 @@ mod complete {
Ok((&b""[..], 0))
);
assert_parse!(
- le_i128(
+ le_i128.parse_peek(
&[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x7f
@@ -229,7 +279,7 @@ mod complete {
))
);
assert_parse!(
- le_i128(
+ le_i128.parse_peek(
&[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff
@@ -238,7 +288,7 @@ mod complete {
Ok((&b""[..], -1))
);
assert_parse!(
- le_i128(
+ le_i128.parse_peek(
&[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80
@@ -253,9 +303,12 @@ mod complete {
#[test]
fn be_f32_tests() {
- assert_parse!(be_f32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0_f32)));
assert_parse!(
- be_f32(&[0x4d, 0x31, 0x1f, 0xd8][..]),
+ be_f32.parse_peek(&[0x00, 0x00, 0x00, 0x00][..]),
+ Ok((&b""[..], 0_f32))
+ );
+ assert_parse!(
+ be_f32.parse_peek(&[0x4d, 0x31, 0x1f, 0xd8][..]),
Ok((&b""[..], 185_728_380_f32))
);
}
@@ -263,20 +316,23 @@ mod complete {
#[test]
fn be_f64_tests() {
assert_parse!(
- be_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+ be_f64.parse_peek(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
Ok((&b""[..], 0_f64))
);
assert_parse!(
- be_f64(&[0x41, 0xa6, 0x23, 0xfb, 0x10, 0x00, 0x00, 0x00][..]),
+ be_f64.parse_peek(&[0x41, 0xa6, 0x23, 0xfb, 0x10, 0x00, 0x00, 0x00][..]),
Ok((&b""[..], 185_728_392_f64))
);
}
#[test]
fn le_f32_tests() {
- assert_parse!(le_f32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0_f32)));
assert_parse!(
- le_f32(&[0xd8, 0x1f, 0x31, 0x4d][..]),
+ le_f32.parse_peek(&[0x00, 0x00, 0x00, 0x00][..]),
+ Ok((&b""[..], 0_f32))
+ );
+ assert_parse!(
+ le_f32.parse_peek(&[0xd8, 0x1f, 0x31, 0x4d][..]),
Ok((&b""[..], 185_728_380_f32))
);
}
@@ -284,11 +340,11 @@ mod complete {
#[test]
fn le_f64_tests() {
assert_parse!(
- le_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+ le_f64.parse_peek(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
Ok((&b""[..], 0_f64))
);
assert_parse!(
- le_f64(&[0x00, 0x00, 0x00, 0x10, 0xfb, 0x23, 0xa6, 0x41][..]),
+ le_f64.parse_peek(&[0x00, 0x00, 0x00, 0x10, 0xfb, 0x23, 0xa6, 0x41][..]),
Ok((&b""[..], 185_728_392_f64))
);
}
@@ -298,19 +354,19 @@ mod complete {
use crate::binary::Endianness;
fn be_tst16(i: &[u8]) -> IResult<&[u8], u16> {
- u16(Endianness::Big).parse_next(i)
+ u16(Endianness::Big).parse_peek(i)
}
fn le_tst16(i: &[u8]) -> IResult<&[u8], u16> {
- u16(Endianness::Little).parse_next(i)
+ u16(Endianness::Little).parse_peek(i)
}
assert_eq!(be_tst16(&[0x80, 0x00]), Ok((&b""[..], 32_768_u16)));
assert_eq!(le_tst16(&[0x80, 0x00]), Ok((&b""[..], 128_u16)));
fn be_tst32(i: &[u8]) -> IResult<&[u8], u32> {
- u32(Endianness::Big).parse_next(i)
+ u32(Endianness::Big).parse_peek(i)
}
fn le_tst32(i: &[u8]) -> IResult<&[u8], u32> {
- u32(Endianness::Little).parse_next(i)
+ u32(Endianness::Little).parse_peek(i)
}
assert_eq!(
be_tst32(&[0x12, 0x00, 0x60, 0x00]),
@@ -322,10 +378,10 @@ mod complete {
);
fn be_tst64(i: &[u8]) -> IResult<&[u8], u64> {
- u64(Endianness::Big).parse_next(i)
+ u64(Endianness::Big).parse_peek(i)
}
fn le_tst64(i: &[u8]) -> IResult<&[u8], u64> {
- u64(Endianness::Little).parse_next(i)
+ u64(Endianness::Little).parse_peek(i)
}
assert_eq!(
be_tst64(&[0x12, 0x00, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
@@ -337,19 +393,19 @@ mod complete {
);
fn be_tsti16(i: &[u8]) -> IResult<&[u8], i16> {
- i16(Endianness::Big).parse_next(i)
+ i16(Endianness::Big).parse_peek(i)
}
fn le_tsti16(i: &[u8]) -> IResult<&[u8], i16> {
- i16(Endianness::Little).parse_next(i)
+ i16(Endianness::Little).parse_peek(i)
}
assert_eq!(be_tsti16(&[0x00, 0x80]), Ok((&b""[..], 128_i16)));
assert_eq!(le_tsti16(&[0x00, 0x80]), Ok((&b""[..], -32_768_i16)));
fn be_tsti32(i: &[u8]) -> IResult<&[u8], i32> {
- i32(Endianness::Big).parse_next(i)
+ i32(Endianness::Big).parse_peek(i)
}
fn le_tsti32(i: &[u8]) -> IResult<&[u8], i32> {
- i32(Endianness::Little).parse_next(i)
+ i32(Endianness::Little).parse_peek(i)
}
assert_eq!(
be_tsti32(&[0x00, 0x12, 0x60, 0x00]),
@@ -361,10 +417,10 @@ mod complete {
);
fn be_tsti64(i: &[u8]) -> IResult<&[u8], i64> {
- i64(Endianness::Big).parse_next(i)
+ i64(Endianness::Big).parse_peek(i)
}
fn le_tsti64(i: &[u8]) -> IResult<&[u8], i64> {
- i64(Endianness::Little).parse_next(i)
+ i64(Endianness::Little).parse_peek(i)
}
assert_eq!(
be_tsti64(&[0x00, 0xFF, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
@@ -380,7 +436,7 @@ mod complete {
mod partial {
use super::*;
use crate::error::ErrMode;
- use crate::error::Error;
+ use crate::error::InputError;
use crate::error::Needed;
#[cfg(feature = "alloc")]
use crate::lib::std::vec::Vec;
@@ -395,7 +451,7 @@ mod partial {
macro_rules! assert_parse(
($left: expr, $right: expr) => {
- let res: $crate::IResult<_, _, Error<_>> = $left;
+ let res: $crate::IResult<_, _, InputError<_>> = $left;
assert_eq!(res, $right);
};
);
@@ -403,23 +459,23 @@ mod partial {
#[test]
fn i8_tests() {
assert_parse!(
- be_i8(Partial::new(&[0x00][..])),
+ be_i8.parse_peek(Partial::new(&[0x00][..])),
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- be_i8(Partial::new(&[0x7f][..])),
+ be_i8.parse_peek(Partial::new(&[0x7f][..])),
Ok((Partial::new(&b""[..]), 127))
);
assert_parse!(
- be_i8(Partial::new(&[0xff][..])),
+ be_i8.parse_peek(Partial::new(&[0xff][..])),
Ok((Partial::new(&b""[..]), -1))
);
assert_parse!(
- be_i8(Partial::new(&[0x80][..])),
+ be_i8.parse_peek(Partial::new(&[0x80][..])),
Ok((Partial::new(&b""[..]), -128))
);
assert_parse!(
- be_i8(Partial::new(&[][..])),
+ be_i8.parse_peek(Partial::new(&[][..])),
Err(ErrMode::Incomplete(Needed::new(1)))
);
}
@@ -427,27 +483,27 @@ mod partial {
#[test]
fn i16_tests() {
assert_parse!(
- be_i16(Partial::new(&[0x00, 0x00][..])),
+ be_i16.parse_peek(Partial::new(&[0x00, 0x00][..])),
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- be_i16(Partial::new(&[0x7f, 0xff][..])),
+ be_i16.parse_peek(Partial::new(&[0x7f, 0xff][..])),
Ok((Partial::new(&b""[..]), 32_767_i16))
);
assert_parse!(
- be_i16(Partial::new(&[0xff, 0xff][..])),
+ be_i16.parse_peek(Partial::new(&[0xff, 0xff][..])),
Ok((Partial::new(&b""[..]), -1))
);
assert_parse!(
- be_i16(Partial::new(&[0x80, 0x00][..])),
+ be_i16.parse_peek(Partial::new(&[0x80, 0x00][..])),
Ok((Partial::new(&b""[..]), -32_768_i16))
);
assert_parse!(
- be_i16(Partial::new(&[][..])),
+ be_i16.parse_peek(Partial::new(&[][..])),
Err(ErrMode::Incomplete(Needed::new(2)))
);
assert_parse!(
- be_i16(Partial::new(&[0x00][..])),
+ be_i16.parse_peek(Partial::new(&[0x00][..])),
Err(ErrMode::Incomplete(Needed::new(1)))
);
}
@@ -455,27 +511,27 @@ mod partial {
#[test]
fn u24_tests() {
assert_parse!(
- be_u24(Partial::new(&[0x00, 0x00, 0x00][..])),
+ be_u24.parse_peek(Partial::new(&[0x00, 0x00, 0x00][..])),
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- be_u24(Partial::new(&[0x00, 0xFF, 0xFF][..])),
+ be_u24.parse_peek(Partial::new(&[0x00, 0xFF, 0xFF][..])),
Ok((Partial::new(&b""[..]), 65_535_u32))
);
assert_parse!(
- be_u24(Partial::new(&[0x12, 0x34, 0x56][..])),
+ be_u24.parse_peek(Partial::new(&[0x12, 0x34, 0x56][..])),
Ok((Partial::new(&b""[..]), 1_193_046_u32))
);
assert_parse!(
- be_u24(Partial::new(&[][..])),
+ be_u24.parse_peek(Partial::new(&[][..])),
Err(ErrMode::Incomplete(Needed::new(3)))
);
assert_parse!(
- be_u24(Partial::new(&[0x00][..])),
+ be_u24.parse_peek(Partial::new(&[0x00][..])),
Err(ErrMode::Incomplete(Needed::new(2)))
);
assert_parse!(
- be_u24(Partial::new(&[0x00, 0x00][..])),
+ be_u24.parse_peek(Partial::new(&[0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(1)))
);
}
@@ -483,27 +539,27 @@ mod partial {
#[test]
fn i24_tests() {
assert_parse!(
- be_i24(Partial::new(&[0xFF, 0xFF, 0xFF][..])),
+ be_i24.parse_peek(Partial::new(&[0xFF, 0xFF, 0xFF][..])),
Ok((Partial::new(&b""[..]), -1_i32))
);
assert_parse!(
- be_i24(Partial::new(&[0xFF, 0x00, 0x00][..])),
+ be_i24.parse_peek(Partial::new(&[0xFF, 0x00, 0x00][..])),
Ok((Partial::new(&b""[..]), -65_536_i32))
);
assert_parse!(
- be_i24(Partial::new(&[0xED, 0xCB, 0xAA][..])),
+ be_i24.parse_peek(Partial::new(&[0xED, 0xCB, 0xAA][..])),
Ok((Partial::new(&b""[..]), -1_193_046_i32))
);
assert_parse!(
- be_i24(Partial::new(&[][..])),
+ be_i24.parse_peek(Partial::new(&[][..])),
Err(ErrMode::Incomplete(Needed::new(3)))
);
assert_parse!(
- be_i24(Partial::new(&[0x00][..])),
+ be_i24.parse_peek(Partial::new(&[0x00][..])),
Err(ErrMode::Incomplete(Needed::new(2)))
);
assert_parse!(
- be_i24(Partial::new(&[0x00, 0x00][..])),
+ be_i24.parse_peek(Partial::new(&[0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(1)))
);
}
@@ -511,35 +567,35 @@ mod partial {
#[test]
fn i32_tests() {
assert_parse!(
- be_i32(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
+ be_i32.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- be_i32(Partial::new(&[0x7f, 0xff, 0xff, 0xff][..])),
+ be_i32.parse_peek(Partial::new(&[0x7f, 0xff, 0xff, 0xff][..])),
Ok((Partial::new(&b""[..]), 2_147_483_647_i32))
);
assert_parse!(
- be_i32(Partial::new(&[0xff, 0xff, 0xff, 0xff][..])),
+ be_i32.parse_peek(Partial::new(&[0xff, 0xff, 0xff, 0xff][..])),
Ok((Partial::new(&b""[..]), -1))
);
assert_parse!(
- be_i32(Partial::new(&[0x80, 0x00, 0x00, 0x00][..])),
+ be_i32.parse_peek(Partial::new(&[0x80, 0x00, 0x00, 0x00][..])),
Ok((Partial::new(&b""[..]), -2_147_483_648_i32))
);
assert_parse!(
- be_i32(Partial::new(&[][..])),
+ be_i32.parse_peek(Partial::new(&[][..])),
Err(ErrMode::Incomplete(Needed::new(4)))
);
assert_parse!(
- be_i32(Partial::new(&[0x00][..])),
+ be_i32.parse_peek(Partial::new(&[0x00][..])),
Err(ErrMode::Incomplete(Needed::new(3)))
);
assert_parse!(
- be_i32(Partial::new(&[0x00, 0x00][..])),
+ be_i32.parse_peek(Partial::new(&[0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(2)))
);
assert_parse!(
- be_i32(Partial::new(&[0x00, 0x00, 0x00][..])),
+ be_i32.parse_peek(Partial::new(&[0x00, 0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(1)))
);
}
@@ -547,59 +603,59 @@ mod partial {
#[test]
fn i64_tests() {
assert_parse!(
- be_i64(Partial::new(
+ be_i64.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- be_i64(Partial::new(
+ be_i64.parse_peek(Partial::new(
&[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]
)),
Ok((Partial::new(&b""[..]), 9_223_372_036_854_775_807_i64))
);
assert_parse!(
- be_i64(Partial::new(
+ be_i64.parse_peek(Partial::new(
&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]
)),
Ok((Partial::new(&b""[..]), -1))
);
assert_parse!(
- be_i64(Partial::new(
+ be_i64.parse_peek(Partial::new(
&[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Ok((Partial::new(&b""[..]), -9_223_372_036_854_775_808_i64))
);
assert_parse!(
- be_i64(Partial::new(&[][..])),
+ be_i64.parse_peek(Partial::new(&[][..])),
Err(ErrMode::Incomplete(Needed::new(8)))
);
assert_parse!(
- be_i64(Partial::new(&[0x00][..])),
+ be_i64.parse_peek(Partial::new(&[0x00][..])),
Err(ErrMode::Incomplete(Needed::new(7)))
);
assert_parse!(
- be_i64(Partial::new(&[0x00, 0x00][..])),
+ be_i64.parse_peek(Partial::new(&[0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(6)))
);
assert_parse!(
- be_i64(Partial::new(&[0x00, 0x00, 0x00][..])),
+ be_i64.parse_peek(Partial::new(&[0x00, 0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(5)))
);
assert_parse!(
- be_i64(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
+ be_i64.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(4)))
);
assert_parse!(
- be_i64(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00][..])),
+ be_i64.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(3)))
);
assert_parse!(
- be_i64(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])),
+ be_i64.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(2)))
);
assert_parse!(
- be_i64(Partial::new(
+ be_i64.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Err(ErrMode::Incomplete(Needed::new(1)))
@@ -609,7 +665,7 @@ mod partial {
#[test]
fn i128_tests() {
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
@@ -618,7 +674,7 @@ mod partial {
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff
@@ -630,7 +686,7 @@ mod partial {
))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff
@@ -639,7 +695,7 @@ mod partial {
Ok((Partial::new(&b""[..]), -1))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
@@ -651,77 +707,77 @@ mod partial {
))
);
assert_parse!(
- be_i128(Partial::new(&[][..])),
+ be_i128.parse_peek(Partial::new(&[][..])),
Err(ErrMode::Incomplete(Needed::new(16)))
);
assert_parse!(
- be_i128(Partial::new(&[0x00][..])),
+ be_i128.parse_peek(Partial::new(&[0x00][..])),
Err(ErrMode::Incomplete(Needed::new(15)))
);
assert_parse!(
- be_i128(Partial::new(&[0x00, 0x00][..])),
+ be_i128.parse_peek(Partial::new(&[0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(14)))
);
assert_parse!(
- be_i128(Partial::new(&[0x00, 0x00, 0x00][..])),
+ be_i128.parse_peek(Partial::new(&[0x00, 0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(13)))
);
assert_parse!(
- be_i128(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
+ be_i128.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(12)))
);
assert_parse!(
- be_i128(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00][..])),
+ be_i128.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(11)))
);
assert_parse!(
- be_i128(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])),
+ be_i128.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..])),
Err(ErrMode::Incomplete(Needed::new(10)))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Err(ErrMode::Incomplete(Needed::new(9)))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Err(ErrMode::Incomplete(Needed::new(8)))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Err(ErrMode::Incomplete(Needed::new(7)))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Err(ErrMode::Incomplete(Needed::new(6)))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Err(ErrMode::Incomplete(Needed::new(5)))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Err(ErrMode::Incomplete(Needed::new(4)))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Err(ErrMode::Incomplete(Needed::new(3)))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00
@@ -730,7 +786,7 @@ mod partial {
Err(ErrMode::Incomplete(Needed::new(2)))
);
assert_parse!(
- be_i128(Partial::new(
+ be_i128.parse_peek(Partial::new(
&[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00
@@ -743,19 +799,19 @@ mod partial {
#[test]
fn le_i8_tests() {
assert_parse!(
- le_i8(Partial::new(&[0x00][..])),
+ le_i8.parse_peek(Partial::new(&[0x00][..])),
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- le_i8(Partial::new(&[0x7f][..])),
+ le_i8.parse_peek(Partial::new(&[0x7f][..])),
Ok((Partial::new(&b""[..]), 127))
);
assert_parse!(
- le_i8(Partial::new(&[0xff][..])),
+ le_i8.parse_peek(Partial::new(&[0xff][..])),
Ok((Partial::new(&b""[..]), -1))
);
assert_parse!(
- le_i8(Partial::new(&[0x80][..])),
+ le_i8.parse_peek(Partial::new(&[0x80][..])),
Ok((Partial::new(&b""[..]), -128))
);
}
@@ -763,19 +819,19 @@ mod partial {
#[test]
fn le_i16_tests() {
assert_parse!(
- le_i16(Partial::new(&[0x00, 0x00][..])),
+ le_i16.parse_peek(Partial::new(&[0x00, 0x00][..])),
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- le_i16(Partial::new(&[0xff, 0x7f][..])),
+ le_i16.parse_peek(Partial::new(&[0xff, 0x7f][..])),
Ok((Partial::new(&b""[..]), 32_767_i16))
);
assert_parse!(
- le_i16(Partial::new(&[0xff, 0xff][..])),
+ le_i16.parse_peek(Partial::new(&[0xff, 0xff][..])),
Ok((Partial::new(&b""[..]), -1))
);
assert_parse!(
- le_i16(Partial::new(&[0x00, 0x80][..])),
+ le_i16.parse_peek(Partial::new(&[0x00, 0x80][..])),
Ok((Partial::new(&b""[..]), -32_768_i16))
);
}
@@ -783,15 +839,15 @@ mod partial {
#[test]
fn le_u24_tests() {
assert_parse!(
- le_u24(Partial::new(&[0x00, 0x00, 0x00][..])),
+ le_u24.parse_peek(Partial::new(&[0x00, 0x00, 0x00][..])),
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- le_u24(Partial::new(&[0xFF, 0xFF, 0x00][..])),
+ le_u24.parse_peek(Partial::new(&[0xFF, 0xFF, 0x00][..])),
Ok((Partial::new(&b""[..]), 65_535_u32))
);
assert_parse!(
- le_u24(Partial::new(&[0x56, 0x34, 0x12][..])),
+ le_u24.parse_peek(Partial::new(&[0x56, 0x34, 0x12][..])),
Ok((Partial::new(&b""[..]), 1_193_046_u32))
);
}
@@ -799,15 +855,15 @@ mod partial {
#[test]
fn le_i24_tests() {
assert_parse!(
- le_i24(Partial::new(&[0xFF, 0xFF, 0xFF][..])),
+ le_i24.parse_peek(Partial::new(&[0xFF, 0xFF, 0xFF][..])),
Ok((Partial::new(&b""[..]), -1_i32))
);
assert_parse!(
- le_i24(Partial::new(&[0x00, 0x00, 0xFF][..])),
+ le_i24.parse_peek(Partial::new(&[0x00, 0x00, 0xFF][..])),
Ok((Partial::new(&b""[..]), -65_536_i32))
);
assert_parse!(
- le_i24(Partial::new(&[0xAA, 0xCB, 0xED][..])),
+ le_i24.parse_peek(Partial::new(&[0xAA, 0xCB, 0xED][..])),
Ok((Partial::new(&b""[..]), -1_193_046_i32))
);
}
@@ -815,19 +871,19 @@ mod partial {
#[test]
fn le_i32_tests() {
assert_parse!(
- le_i32(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
+ le_i32.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- le_i32(Partial::new(&[0xff, 0xff, 0xff, 0x7f][..])),
+ le_i32.parse_peek(Partial::new(&[0xff, 0xff, 0xff, 0x7f][..])),
Ok((Partial::new(&b""[..]), 2_147_483_647_i32))
);
assert_parse!(
- le_i32(Partial::new(&[0xff, 0xff, 0xff, 0xff][..])),
+ le_i32.parse_peek(Partial::new(&[0xff, 0xff, 0xff, 0xff][..])),
Ok((Partial::new(&b""[..]), -1))
);
assert_parse!(
- le_i32(Partial::new(&[0x00, 0x00, 0x00, 0x80][..])),
+ le_i32.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x80][..])),
Ok((Partial::new(&b""[..]), -2_147_483_648_i32))
);
}
@@ -835,25 +891,25 @@ mod partial {
#[test]
fn le_i64_tests() {
assert_parse!(
- le_i64(Partial::new(
+ le_i64.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- le_i64(Partial::new(
+ le_i64.parse_peek(Partial::new(
&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f][..]
)),
Ok((Partial::new(&b""[..]), 9_223_372_036_854_775_807_i64))
);
assert_parse!(
- le_i64(Partial::new(
+ le_i64.parse_peek(Partial::new(
&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]
)),
Ok((Partial::new(&b""[..]), -1))
);
assert_parse!(
- le_i64(Partial::new(
+ le_i64.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80][..]
)),
Ok((Partial::new(&b""[..]), -9_223_372_036_854_775_808_i64))
@@ -863,7 +919,7 @@ mod partial {
#[test]
fn le_i128_tests() {
assert_parse!(
- le_i128(Partial::new(
+ le_i128.parse_peek(Partial::new(
&[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
@@ -872,7 +928,7 @@ mod partial {
Ok((Partial::new(&b""[..]), 0))
);
assert_parse!(
- le_i128(Partial::new(
+ le_i128.parse_peek(Partial::new(
&[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x7f
@@ -884,7 +940,7 @@ mod partial {
))
);
assert_parse!(
- le_i128(Partial::new(
+ le_i128.parse_peek(Partial::new(
&[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff
@@ -893,7 +949,7 @@ mod partial {
Ok((Partial::new(&b""[..]), -1))
);
assert_parse!(
- le_i128(Partial::new(
+ le_i128.parse_peek(Partial::new(
&[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80
@@ -909,11 +965,11 @@ mod partial {
#[test]
fn be_f32_tests() {
assert_parse!(
- be_f32(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
+ be_f32.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
Ok((Partial::new(&b""[..]), 0_f32))
);
assert_parse!(
- be_f32(Partial::new(&[0x4d, 0x31, 0x1f, 0xd8][..])),
+ be_f32.parse_peek(Partial::new(&[0x4d, 0x31, 0x1f, 0xd8][..])),
Ok((Partial::new(&b""[..]), 185_728_380_f32))
);
}
@@ -921,13 +977,13 @@ mod partial {
#[test]
fn be_f64_tests() {
assert_parse!(
- be_f64(Partial::new(
+ be_f64.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Ok((Partial::new(&b""[..]), 0_f64))
);
assert_parse!(
- be_f64(Partial::new(
+ be_f64.parse_peek(Partial::new(
&[0x41, 0xa6, 0x23, 0xfb, 0x10, 0x00, 0x00, 0x00][..]
)),
Ok((Partial::new(&b""[..]), 185_728_392_f64))
@@ -937,11 +993,11 @@ mod partial {
#[test]
fn le_f32_tests() {
assert_parse!(
- le_f32(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
+ le_f32.parse_peek(Partial::new(&[0x00, 0x00, 0x00, 0x00][..])),
Ok((Partial::new(&b""[..]), 0_f32))
);
assert_parse!(
- le_f32(Partial::new(&[0xd8, 0x1f, 0x31, 0x4d][..])),
+ le_f32.parse_peek(Partial::new(&[0xd8, 0x1f, 0x31, 0x4d][..])),
Ok((Partial::new(&b""[..]), 185_728_380_f32))
);
}
@@ -949,13 +1005,13 @@ mod partial {
#[test]
fn le_f64_tests() {
assert_parse!(
- le_f64(Partial::new(
+ le_f64.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
)),
Ok((Partial::new(&b""[..]), 0_f64))
);
assert_parse!(
- le_f64(Partial::new(
+ le_f64.parse_peek(Partial::new(
&[0x00, 0x00, 0x00, 0x10, 0xfb, 0x23, 0xa6, 0x41][..]
)),
Ok((Partial::new(&b""[..]), 185_728_392_f64))
@@ -967,10 +1023,10 @@ mod partial {
use crate::binary::Endianness;
fn be_tst16(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u16> {
- u16(Endianness::Big).parse_next(i)
+ u16(Endianness::Big).parse_peek(i)
}
fn le_tst16(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u16> {
- u16(Endianness::Little).parse_next(i)
+ u16(Endianness::Little).parse_peek(i)
}
assert_eq!(
be_tst16(Partial::new(&[0x80, 0x00])),
@@ -982,10 +1038,10 @@ mod partial {
);
fn be_tst32(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> {
- u32(Endianness::Big).parse_next(i)
+ u32(Endianness::Big).parse_peek(i)
}
fn le_tst32(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> {
- u32(Endianness::Little).parse_next(i)
+ u32(Endianness::Little).parse_peek(i)
}
assert_eq!(
be_tst32(Partial::new(&[0x12, 0x00, 0x60, 0x00])),
@@ -997,10 +1053,10 @@ mod partial {
);
fn be_tst64(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u64> {
- u64(Endianness::Big).parse_next(i)
+ u64(Endianness::Big).parse_peek(i)
}
fn le_tst64(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u64> {
- u64(Endianness::Little).parse_next(i)
+ u64(Endianness::Little).parse_peek(i)
}
assert_eq!(
be_tst64(Partial::new(&[
@@ -1016,10 +1072,10 @@ mod partial {
);
fn be_tsti16(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i16> {
- i16(Endianness::Big).parse_next(i)
+ i16(Endianness::Big).parse_peek(i)
}
fn le_tsti16(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i16> {
- i16(Endianness::Little).parse_next(i)
+ i16(Endianness::Little).parse_peek(i)
}
assert_eq!(
be_tsti16(Partial::new(&[0x00, 0x80])),
@@ -1031,10 +1087,10 @@ mod partial {
);
fn be_tsti32(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> {
- i32(Endianness::Big).parse_next(i)
+ i32(Endianness::Big).parse_peek(i)
}
fn le_tsti32(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i32> {
- i32(Endianness::Little).parse_next(i)
+ i32(Endianness::Little).parse_peek(i)
}
assert_eq!(
be_tsti32(Partial::new(&[0x00, 0x12, 0x60, 0x00])),
@@ -1046,10 +1102,10 @@ mod partial {
);
fn be_tsti64(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i64> {
- i64(Endianness::Big).parse_next(i)
+ i64(Endianness::Big).parse_peek(i)
}
fn le_tsti64(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, i64> {
- i64(Endianness::Little).parse_next(i)
+ i64(Endianness::Little).parse_peek(i)
}
assert_eq!(
be_tsti64(Partial::new(&[
@@ -1072,11 +1128,11 @@ mod partial {
digit
.try_map(str::from_utf8)
.try_map(FromStr::from_str)
- .parse_next(i)
+ .parse_peek(i)
}
fn cnt(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- length_count(number, "abc").parse_next(i)
+ length_count(unpeek(number), "abc").parse_peek(i)
}
assert_eq!(
@@ -1094,14 +1150,14 @@ mod partial {
assert_eq!(
cnt(Partial::new(&b"xxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Slice
)))
);
assert_eq!(
cnt(Partial::new(&b"2abcxxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Tag
)))
);
@@ -1113,11 +1169,11 @@ mod partial {
digit
.try_map(str::from_utf8)
.try_map(FromStr::from_str)
- .parse_next(i)
+ .parse_peek(i)
}
fn take(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- length_data(number).parse_next(i)
+ length_data(unpeek(number)).parse_peek(i)
}
assert_eq!(
@@ -1131,7 +1187,7 @@ mod partial {
assert_eq!(
take(Partial::new(&b"xxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Slice
)))
);
@@ -1146,10 +1202,10 @@ mod partial {
use crate::stream::StreamIsPartial;
fn length_value_1(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u16> {
- length_value(be_u8, be_u16).parse_next(i)
+ length_value(be_u8, be_u16).parse_peek(i)
}
fn length_value_2(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, (u8, u8)> {
- length_value(be_u8, (be_u8, be_u8)).parse_next(i)
+ length_value(be_u8, (be_u8, be_u8)).parse_peek(i)
}
let mut empty_complete = Partial::new(&b""[..]);
@@ -1159,14 +1215,14 @@ mod partial {
assert_eq!(
length_value_1(Partial::new(&i1)),
Err(ErrMode::Backtrack(error_position!(
- empty_complete,
+ &empty_complete,
ErrorKind::Slice
)))
);
assert_eq!(
length_value_2(Partial::new(&i1)),
Err(ErrMode::Backtrack(error_position!(
- empty_complete,
+ &empty_complete,
ErrorKind::Token
)))
);
@@ -1178,14 +1234,14 @@ mod partial {
assert_eq!(
length_value_1(Partial::new(&i2)),
Err(ErrMode::Backtrack(error_position!(
- middle_complete,
+ &middle_complete,
ErrorKind::Slice
)))
);
assert_eq!(
length_value_2(Partial::new(&i2)),
Err(ErrMode::Backtrack(error_position!(
- empty_complete,
+ &empty_complete,
ErrorKind::Token
)))
);
diff --git a/vendor/winnow/src/bits.rs b/vendor/winnow/src/bits.rs
deleted file mode 100644
index 6b4981f30..000000000
--- a/vendor/winnow/src/bits.rs
+++ /dev/null
@@ -1,71 +0,0 @@
-//! Deprecated, see [`binary::bits`]
-#![deprecated(since = "0.4.2", note = "Replaced with `binary::bits`")]
-
-use crate::binary;
-use crate::error::{ErrorConvert, ParseError};
-use crate::lib::std::ops::{AddAssign, Shl, Shr};
-use crate::stream::{AsBytes, Stream, StreamIsPartial, ToUsize};
-use crate::{IResult, Parser};
-
-/// Deprecated, replaced with [`binary::bits::bits`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::bits::bits`")]
-#[inline(always)]
-pub fn bits<I, O, E1, E2, P>(parser: P) -> impl Parser<I, O, E2>
-where
- E1: ParseError<(I, usize)> + ErrorConvert<E2>,
- E2: ParseError<I>,
- I: Stream,
- P: Parser<(I, usize), O, E1>,
-{
- binary::bits::bits(parser)
-}
-
-/// Deprecated, replaced with [`binary::bits::bytes`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::bits::bytes`")]
-#[inline(always)]
-pub fn bytes<I, O, E1, E2, P>(parser: P) -> impl Parser<(I, usize), O, E2>
-where
- E1: ParseError<I> + ErrorConvert<E2>,
- E2: ParseError<(I, usize)>,
- I: Stream<Token = u8>,
- P: Parser<I, O, E1>,
-{
- binary::bits::bytes(parser)
-}
-
-/// Deprecated, replaced with [`binary::bits::take`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::bits::take`")]
-#[inline(always)]
-pub fn take<I, O, C, E: ParseError<(I, usize)>>(count: C) -> impl Parser<(I, usize), O, E>
-where
- I: Stream<Token = u8> + AsBytes + StreamIsPartial,
- C: ToUsize,
- O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O>,
-{
- binary::bits::take(count)
-}
-
-/// Deprecated, replaced with [`binary::bits::tag`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::bits::tag`")]
-#[inline(always)]
-pub fn tag<I, O, C, E: ParseError<(I, usize)>>(
- pattern: O,
- count: C,
-) -> impl Parser<(I, usize), O, E>
-where
- I: Stream<Token = u8> + AsBytes + StreamIsPartial,
- C: ToUsize,
- O: From<u8> + AddAssign + Shl<usize, Output = O> + Shr<usize, Output = O> + PartialEq,
-{
- binary::bits::tag(pattern, count)
-}
-
-/// Deprecated, replaced with [`binary::bits::bool`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::bits::bool`")]
-#[inline(always)]
-pub fn bool<I, E: ParseError<(I, usize)>>(input: (I, usize)) -> IResult<(I, usize), bool, E>
-where
- I: Stream<Token = u8> + AsBytes + StreamIsPartial,
-{
- binary::bits::bool(input)
-}
diff --git a/vendor/winnow/src/branch.rs b/vendor/winnow/src/branch.rs
deleted file mode 100644
index 0783262b4..000000000
--- a/vendor/winnow/src/branch.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-//! Deprecated, see [`combinator`]
-#![deprecated(since = "0.4.2", note = "Replaced with `combinator`")]
-
-use crate::combinator;
-
-pub use combinator::alt;
-pub use combinator::dispatch;
-pub use combinator::permutation;
-pub use combinator::Alt;
-pub use combinator::Permutation;
diff --git a/vendor/winnow/src/bytes.rs b/vendor/winnow/src/bytes.rs
deleted file mode 100644
index 9f57a56d2..000000000
--- a/vendor/winnow/src/bytes.rs
+++ /dev/null
@@ -1,26 +0,0 @@
-//! Deprecated, see [`token`]
-#![deprecated(since = "0.4.2", note = "Replaced with `token`")]
-
-use crate::error::ParseError;
-use crate::stream::StreamIsPartial;
-use crate::stream::{ContainsToken, Stream};
-use crate::token;
-use crate::Parser;
-
-pub use crate::token::*;
-
-/// Deprecated, see [`token::take_while`]
-#[deprecated(since = "0.4.2", note = "Replaced with `token::take_while`")]
-#[inline(always)]
-pub fn take_while_m_n<T, I, Error: ParseError<I>>(
- m: usize,
- n: usize,
- list: T,
-) -> impl Parser<I, <I as Stream>::Slice, Error>
-where
- I: StreamIsPartial,
- I: Stream,
- T: ContainsToken<<I as Stream>::Token>,
-{
- token::take_while(m..=n, list)
-}
diff --git a/vendor/winnow/src/character.rs b/vendor/winnow/src/character.rs
deleted file mode 100644
index a2f685971..000000000
--- a/vendor/winnow/src/character.rs
+++ /dev/null
@@ -1,342 +0,0 @@
-//! Deprecated, see [`ascii`]
-#![deprecated(since = "0.4.2", note = "Replaced with `ascii`")]
-
-use crate::ascii;
-use crate::error::ParseError;
-use crate::stream::Compare;
-use crate::stream::ContainsToken;
-use crate::stream::{AsBStr, AsChar, Offset, ParseSlice, Stream, StreamIsPartial};
-use crate::IResult;
-use crate::Parser;
-
-/// Deprecated, replaced by [`ascii::crlf`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::crlf`")]
-#[inline(always)]
-pub fn crlf<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- I: Compare<&'static str>,
-{
- ascii::crlf.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::not_line_ending`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::not_line_ending`")]
-#[inline(always)]
-pub fn not_line_ending<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream + AsBStr,
- I: Compare<&'static str>,
- <I as Stream>::Token: AsChar,
-{
- ascii::not_line_ending.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::line_ending`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::line_ending`")]
-#[inline(always)]
-pub fn line_ending<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- I: Compare<&'static str>,
-{
- ascii::line_ending.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::newline`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::newline`")]
-#[inline(always)]
-pub fn newline<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar + Copy,
-{
- ascii::newline.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::tab`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::tab`")]
-#[inline(always)]
-pub fn tab<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar + Copy,
-{
- ascii::tab.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::alpha0`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::alpha0`")]
-#[inline(always)]
-pub fn alpha0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar,
-{
- ascii::alpha0.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::alpha1`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::alpha1`")]
-#[inline(always)]
-pub fn alpha1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar,
-{
- ascii::alpha1.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::digit0`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::digit0`")]
-#[inline(always)]
-pub fn digit0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar,
-{
- ascii::digit0.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::digit1`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::digit1`")]
-#[inline(always)]
-pub fn digit1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar,
-{
- ascii::digit1.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::hex_digit0`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::hex_digit0`")]
-#[inline(always)]
-pub fn hex_digit0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar,
-{
- ascii::hex_digit0.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::hex_digit1`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::hex_digit1`")]
-#[inline(always)]
-pub fn hex_digit1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar,
-{
- ascii::hex_digit1.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::oct_digit0`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::oct_digit0`")]
-#[inline(always)]
-pub fn oct_digit0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar,
-{
- ascii::oct_digit0.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::oct_digit1`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::oct_digit1`")]
-#[inline(always)]
-pub fn oct_digit1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar,
-{
- ascii::oct_digit0.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::alphanumeric0`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::alphanumeric0`")]
-#[inline(always)]
-pub fn alphanumeric0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar,
-{
- ascii::alphanumeric0.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::alphanumeric1`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::alphanumeric1`")]
-#[inline(always)]
-pub fn alphanumeric1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar,
-{
- ascii::alphanumeric1.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::space0`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::space0`")]
-#[inline(always)]
-pub fn space0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar + Copy,
-{
- ascii::space0.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::space1`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::space1`")]
-#[inline(always)]
-pub fn space1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar + Copy,
-{
- ascii::space1.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::multispace0`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::multispace0`")]
-#[inline(always)]
-pub fn multispace0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar + Copy,
-{
- ascii::multispace0.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::multispace1`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::multispace1`")]
-#[inline(always)]
-pub fn multispace1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar + Copy,
-{
- ascii::multispace1.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::dec_uint`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::dec_uint`")]
-#[inline(always)]
-pub fn dec_uint<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar + Copy,
- O: Uint,
-{
- ascii::dec_uint.parse_next(input)
-}
-
-pub use ascii::Uint;
-
-/// Deprecated, replaced by [`ascii::dec_int`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::dec_int`")]
-#[inline(always)]
-pub fn dec_int<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
-where
- I: StreamIsPartial,
- I: Stream,
- <I as Stream>::Token: AsChar + Copy,
- O: Int,
-{
- ascii::dec_int.parse_next(input)
-}
-
-pub use ascii::Int;
-
-/// Deprecated, replaced by [`ascii::hex_uint`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::hex_uint`")]
-#[inline(always)]
-pub fn hex_uint<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
-where
- I: StreamIsPartial,
- I: Stream,
- O: HexUint,
- <I as Stream>::Token: AsChar,
- <I as Stream>::Slice: AsBStr,
-{
- ascii::hex_uint.parse_next(input)
-}
-
-pub use ascii::HexUint;
-
-/// Deprecated, replaced by [`ascii::float`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::float`")]
-#[inline(always)]
-pub fn float<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
-where
- I: StreamIsPartial,
- I: Stream,
- I: Offset + Compare<&'static str>,
- <I as Stream>::Slice: ParseSlice<O>,
- <I as Stream>::Token: AsChar + Copy,
- <I as Stream>::IterOffsets: Clone,
- I: AsBStr,
- &'static str: ContainsToken<<I as Stream>::Token>,
-{
- ascii::float.parse_next(input)
-}
-
-/// Deprecated, replaced by [`ascii::escaped`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::escaped`")]
-#[inline(always)]
-pub fn escaped<'a, I: 'a, Error, F, G, O1, O2>(
- normal: F,
- control_char: char,
- escapable: G,
-) -> impl Parser<I, <I as Stream>::Slice, Error>
-where
- I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
- F: Parser<I, O1, Error>,
- G: Parser<I, O2, Error>,
- Error: ParseError<I>,
-{
- ascii::escaped(normal, control_char, escapable)
-}
-
-#[cfg(feature = "alloc")]
-/// Deprecated, replaced by [`ascii::escaped_transform`]
-#[deprecated(since = "0.4.2", note = "Replaced with `ascii::escaped_transform`")]
-#[inline(always)]
-pub fn escaped_transform<I, Error, F, G, Output>(
- normal: F,
- control_char: char,
- transform: G,
-) -> impl Parser<I, Output, Error>
-where
- I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
- Output: crate::stream::Accumulate<<I as Stream>::Slice>,
- F: Parser<I, <I as Stream>::Slice, Error>,
- G: Parser<I, <I as Stream>::Slice, Error>,
- Error: ParseError<I>,
-{
- ascii::escaped_transform(normal, control_char, transform)
-}
diff --git a/vendor/winnow/src/combinator/branch.rs b/vendor/winnow/src/combinator/branch.rs
index 042b27d53..2a712ec1d 100644
--- a/vendor/winnow/src/combinator/branch.rs
+++ b/vendor/winnow/src/combinator/branch.rs
@@ -1,4 +1,4 @@
-use crate::error::{ErrMode, ErrorKind, ParseError};
+use crate::error::{ErrMode, ErrorKind, ParserError};
use crate::stream::Stream;
use crate::trace::trace;
use crate::*;
@@ -11,7 +11,7 @@ pub use crate::dispatch;
/// This trait is implemented for tuples of up to 21 elements
pub trait Alt<I, O, E> {
/// Tests each parser in the tuple and returns the result of the first one that succeeds
- fn choice(&mut self, input: I) -> IResult<I, O, E>;
+ fn choice(&mut self, input: &mut I) -> PResult<O, E>;
}
/// Pick the first successful parser
@@ -25,13 +25,13 @@ pub trait Alt<I, O, E> {
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::Error,error::ErrorKind, error::Needed};
+/// # use winnow::{error::ErrMode, error::InputError,error::ErrorKind, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::ascii::{alpha1, digit1};
/// use winnow::combinator::alt;
/// # fn main() {
/// fn parser(input: &str) -> IResult<&str, &str> {
-/// alt((alpha1, digit1)).parse_next(input)
+/// alt((alpha1, digit1)).parse_peek(input)
/// };
///
/// // the first parser, alpha1, recognizes the input
@@ -41,14 +41,14 @@ pub trait Alt<I, O, E> {
/// assert_eq!(parser("123456"), Ok(("", "123456")));
///
/// // both parsers failed, and with the default error type, alt will return the last error
-/// assert_eq!(parser(" "), Err(ErrMode::Backtrack(Error::new(" ", ErrorKind::Slice))));
+/// assert_eq!(parser(" "), Err(ErrMode::Backtrack(InputError::new(" ", ErrorKind::Slice))));
/// # }
/// ```
#[doc(alias = "choice")]
-pub fn alt<I: Stream, O, E: ParseError<I>, List: Alt<I, O, E>>(
+pub fn alt<I: Stream, O, E: ParserError<I>, List: Alt<I, O, E>>(
mut l: List,
) -> impl Parser<I, O, E> {
- trace("alt", move |i: I| l.choice(i))
+ trace("alt", move |i: &mut I| l.choice(i))
}
/// Helper trait for the [permutation()] combinator.
@@ -56,7 +56,7 @@ pub fn alt<I: Stream, O, E: ParseError<I>, List: Alt<I, O, E>>(
/// This trait is implemented for tuples of up to 21 elements
pub trait Permutation<I, O, E> {
/// Tries to apply all parsers in the tuple in various orders until all of them succeed
- fn permutation(&mut self, input: I) -> IResult<I, O, E>;
+ fn permutation(&mut self, input: &mut I) -> PResult<O, E>;
}
/// Applies a list of parsers in any order.
@@ -66,13 +66,13 @@ pub trait Permutation<I, O, E> {
/// tuple of the parser results.
///
/// ```rust
-/// # use winnow::{error::ErrMode,error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode,error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::ascii::{alpha1, digit1};
/// use winnow::combinator::permutation;
/// # fn main() {
/// fn parser(input: &str) -> IResult<&str, (&str, &str)> {
-/// permutation((alpha1, digit1)).parse_next(input)
+/// permutation((alpha1, digit1)).parse_peek(input)
/// }
///
/// // permutation recognizes alphabetic characters then digit
@@ -82,20 +82,20 @@ pub trait Permutation<I, O, E> {
/// assert_eq!(parser("123abc"), Ok(("", ("abc", "123"))));
///
/// // it will fail if one of the parsers failed
-/// assert_eq!(parser("abc;"), Err(ErrMode::Backtrack(Error::new(";", ErrorKind::Slice))));
+/// assert_eq!(parser("abc;"), Err(ErrMode::Backtrack(InputError::new(";", ErrorKind::Slice))));
/// # }
/// ```
///
/// The parsers are applied greedily: if there are multiple unapplied parsers
/// that could parse the next slice of input, the first one is used.
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}};
/// # use winnow::prelude::*;
/// use winnow::combinator::permutation;
/// use winnow::token::any;
///
/// fn parser(input: &str) -> IResult<&str, (char, char)> {
-/// permutation((any, 'a')).parse_next(input)
+/// permutation((any, 'a')).parse_peek(input)
/// }
///
/// // any parses 'b', then char('a') parses 'a'
@@ -103,13 +103,13 @@ pub trait Permutation<I, O, E> {
///
/// // any parses 'a', then char('a') fails on 'b',
/// // even though char('a') followed by any would succeed
-/// assert_eq!(parser("ab"), Err(ErrMode::Backtrack(Error::new("b", ErrorKind::Verify))));
+/// assert_eq!(parser("ab"), Err(ErrMode::Backtrack(InputError::new("b", ErrorKind::Verify))));
/// ```
///
-pub fn permutation<I: Stream, O, E: ParseError<I>, List: Permutation<I, O, E>>(
+pub fn permutation<I: Stream, O, E: ParserError<I>, List: Permutation<I, O, E>>(
mut l: List,
) -> impl Parser<I, O, E> {
- trace("permutation", move |i: I| l.permutation(i))
+ trace("permutation", move |i: &mut I| l.permutation(i))
}
macro_rules! alt_trait(
@@ -130,13 +130,14 @@ macro_rules! alt_trait(
macro_rules! alt_trait_impl(
($($id:ident)+) => (
impl<
- I: Clone, Output, Error: ParseError<I>,
+ I: Stream, Output, Error: ParserError<I>,
$($id: Parser<I, Output, Error>),+
> Alt<I, Output, Error> for ( $($id),+ ) {
- fn choice(&mut self, input: I) -> IResult<I, Output, Error> {
- match self.0.parse_next(input.clone()) {
- Err(ErrMode::Backtrack(e)) => alt_trait_inner!(1, self, input, e, $($id)+),
+ fn choice(&mut self, input: &mut I) -> PResult<Output, Error> {
+ let start = input.checkpoint();
+ match self.0.parse_next(input) {
+ Err(ErrMode::Backtrack(e)) => alt_trait_inner!(1, self, input, start, e, $($id)+),
res => res,
}
}
@@ -145,25 +146,26 @@ macro_rules! alt_trait_impl(
);
macro_rules! alt_trait_inner(
- ($it:tt, $self:expr, $input:expr, $err:expr, $head:ident $($id:ident)+) => (
- match $self.$it.parse_next($input.clone()) {
+ ($it:tt, $self:expr, $input:expr, $start:ident, $err:expr, $head:ident $($id:ident)+) => ({
+ $input.reset($start.clone());
+ match $self.$it.parse_next($input) {
Err(ErrMode::Backtrack(e)) => {
let err = $err.or(e);
- succ!($it, alt_trait_inner!($self, $input, err, $($id)+))
+ succ!($it, alt_trait_inner!($self, $input, $start, err, $($id)+))
}
res => res,
}
- );
- ($it:tt, $self:expr, $input:expr, $err:expr, $head:ident) => (
+ });
+ ($it:tt, $self:expr, $input:expr, $start:ident, $err:expr, $head:ident) => ({
Err(ErrMode::Backtrack($err.append($input, ErrorKind::Alt)))
- );
+ });
);
alt_trait!(Alt2 Alt3 Alt4 Alt5 Alt6 Alt7 Alt8 Alt9 Alt10 Alt11 Alt12 Alt13 Alt14 Alt15 Alt16 Alt17 Alt18 Alt19 Alt20 Alt21 Alt22);
// Manually implement Alt for (A,), the 1-tuple type
-impl<I, O, E: ParseError<I>, A: Parser<I, O, E>> Alt<I, O, E> for (A,) {
- fn choice(&mut self, input: I) -> IResult<I, O, E> {
+impl<I, O, E: ParserError<I>, A: Parser<I, O, E>> Alt<I, O, E> for (A,) {
+ fn choice(&mut self, input: &mut I) -> PResult<O, E> {
self.0.parse_next(input)
}
}
@@ -191,27 +193,29 @@ macro_rules! permutation_trait(
macro_rules! permutation_trait_impl(
($($name:ident $ty:ident $item:ident),+) => (
impl<
- I: Clone, $($ty),+ , Error: ParseError<I>,
+ I: Stream, $($ty),+ , Error: ParserError<I>,
$($name: Parser<I, $ty, Error>),+
> Permutation<I, ( $($ty),+ ), Error> for ( $($name),+ ) {
- fn permutation(&mut self, mut input: I) -> IResult<I, ( $($ty),+ ), Error> {
+ fn permutation(&mut self, input: &mut I) -> PResult<( $($ty),+ ), Error> {
let mut res = ($(Option::<$ty>::None),+);
loop {
let mut err: Option<Error> = None;
- permutation_trait_inner!(0, self, input, res, err, $($name)+);
+ let start = input.checkpoint();
+ permutation_trait_inner!(0, self, input, start, res, err, $($name)+);
// If we reach here, every iterator has either been applied before,
// or errored on the remaining input
if let Some(err) = err {
// There are remaining parsers, and all errored on the remaining input
+ input.reset(start.clone());
return Err(ErrMode::Backtrack(err.append(input, ErrorKind::Alt)));
}
// All parsers were applied
match res {
- ($(Some($item)),+) => return Ok((input, ($($item),+))),
+ ($(Some($item)),+) => return Ok(($($item),+)),
_ => unreachable!(),
}
}
@@ -221,11 +225,11 @@ macro_rules! permutation_trait_impl(
);
macro_rules! permutation_trait_inner(
- ($it:tt, $self:expr, $input:ident, $res:expr, $err:expr, $head:ident $($id:ident)*) => (
+ ($it:tt, $self:expr, $input:ident, $start:ident, $res:expr, $err:expr, $head:ident $($id:ident)*) => (
if $res.$it.is_none() {
- match $self.$it.parse_next($input.clone()) {
- Ok((i, o)) => {
- $input = i;
+ $input.reset($start.clone());
+ match $self.$it.parse_next($input) {
+ Ok(o) => {
$res.$it = Some(o);
continue;
}
@@ -238,9 +242,9 @@ macro_rules! permutation_trait_inner(
Err(e) => return Err(e),
};
}
- succ!($it, permutation_trait_inner!($self, $input, $res, $err, $($id)*));
+ succ!($it, permutation_trait_inner!($self, $input, $start, $res, $err, $($id)*));
);
- ($it:tt, $self:expr, $input:ident, $res:expr, $err:expr,) => ();
+ ($it:tt, $self:expr, $input:ident, $start:ident, $res:expr, $err:expr,) => ();
);
permutation_trait!(
diff --git a/vendor/winnow/src/combinator/core.rs b/vendor/winnow/src/combinator/core.rs
index 75551d7c5..d784b4e9e 100644
--- a/vendor/winnow/src/combinator/core.rs
+++ b/vendor/winnow/src/combinator/core.rs
@@ -1,4 +1,4 @@
-use crate::error::{ErrMode, ErrorKind, Needed, ParseError};
+use crate::error::{ErrMode, ErrorKind, Needed, ParserError};
use crate::stream::Stream;
use crate::trace::trace;
use crate::*;
@@ -8,21 +8,19 @@ use crate::*;
/// # Example
///
/// ```rust
+/// # use winnow::prelude::*;
/// # use winnow::error::ErrorKind;
-/// # use winnow::error::Error;
+/// # use winnow::error::InputError;
/// use winnow::combinator::rest;
-/// assert_eq!(rest::<_,Error<_>>("abc"), Ok(("", "abc")));
-/// assert_eq!(rest::<_,Error<_>>(""), Ok(("", "")));
+/// assert_eq!(rest::<_,InputError<_>>.parse_peek("abc"), Ok(("", "abc")));
+/// assert_eq!(rest::<_,InputError<_>>.parse_peek(""), Ok(("", "")));
/// ```
#[inline]
-pub fn rest<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn rest<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: Stream,
{
- trace("rest", move |input: I| {
- Ok(input.next_slice(input.eof_offset()))
- })
- .parse_next(input)
+ trace("rest", move |input: &mut I| Ok(input.finish())).parse_next(input)
}
/// Return the length of the remaining input.
@@ -32,20 +30,21 @@ where
/// # Example
///
/// ```rust
+/// # use winnow::prelude::*;
/// # use winnow::error::ErrorKind;
-/// # use winnow::error::Error;
+/// # use winnow::error::InputError;
/// use winnow::combinator::rest_len;
-/// assert_eq!(rest_len::<_,Error<_>>("abc"), Ok(("abc", 3)));
-/// assert_eq!(rest_len::<_,Error<_>>(""), Ok(("", 0)));
+/// assert_eq!(rest_len::<_,InputError<_>>.parse_peek("abc"), Ok(("abc", 3)));
+/// assert_eq!(rest_len::<_,InputError<_>>.parse_peek(""), Ok(("", 0)));
/// ```
#[inline]
-pub fn rest_len<I, E: ParseError<I>>(input: I) -> IResult<I, usize, E>
+pub fn rest_len<I, E: ParserError<I>>(input: &mut I) -> PResult<usize, E>
where
I: Stream,
{
- trace("rest_len", move |input: I| {
+ trace("rest_len", move |input: &mut I| {
let len = input.eof_offset();
- Ok((input, len))
+ Ok(len)
})
.parse_next(input)
}
@@ -57,29 +56,32 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// # use winnow::prelude::*;
/// use winnow::combinator::opt;
/// use winnow::ascii::alpha1;
/// # fn main() {
///
/// fn parser(i: &str) -> IResult<&str, Option<&str>> {
-/// opt(alpha1).parse_next(i)
+/// opt(alpha1).parse_peek(i)
/// }
///
/// assert_eq!(parser("abcd;"), Ok((";", Some("abcd"))));
/// assert_eq!(parser("123;"), Ok(("123;", None)));
/// # }
/// ```
-pub fn opt<I: Stream, O, E: ParseError<I>, F>(mut f: F) -> impl Parser<I, Option<O>, E>
+pub fn opt<I: Stream, O, E: ParserError<I>, F>(mut f: F) -> impl Parser<I, Option<O>, E>
where
F: Parser<I, O, E>,
{
- trace("opt", move |input: I| {
- let i = input.clone();
+ trace("opt", move |input: &mut I| {
+ let start = input.checkpoint();
match f.parse_next(input) {
- Ok((i, o)) => Ok((i, Some(o))),
- Err(ErrMode::Backtrack(_)) => Ok((i, None)),
+ Ok(o) => Ok(Some(o)),
+ Err(ErrMode::Backtrack(_)) => {
+ input.reset(start);
+ Ok(None)
+ }
Err(e) => Err(e),
}
})
@@ -90,35 +92,32 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, IResult};
/// # use winnow::prelude::*;
/// use winnow::combinator::cond;
/// use winnow::ascii::alpha1;
/// # fn main() {
///
/// fn parser(b: bool, i: &str) -> IResult<&str, Option<&str>> {
-/// cond(b, alpha1).parse_next(i)
+/// cond(b, alpha1).parse_peek(i)
/// }
///
/// assert_eq!(parser(true, "abcd;"), Ok((";", Some("abcd"))));
/// assert_eq!(parser(false, "abcd;"), Ok(("abcd;", None)));
-/// assert_eq!(parser(true, "123;"), Err(ErrMode::Backtrack(Error::new("123;", ErrorKind::Slice))));
+/// assert_eq!(parser(true, "123;"), Err(ErrMode::Backtrack(InputError::new("123;", ErrorKind::Slice))));
/// assert_eq!(parser(false, "123;"), Ok(("123;", None)));
/// # }
/// ```
-pub fn cond<I, O, E: ParseError<I>, F>(b: bool, mut f: F) -> impl Parser<I, Option<O>, E>
+pub fn cond<I, O, E: ParserError<I>, F>(b: bool, mut f: F) -> impl Parser<I, Option<O>, E>
where
I: Stream,
F: Parser<I, O, E>,
{
- trace("cond", move |input: I| {
+ trace("cond", move |input: &mut I| {
if b {
- match f.parse_next(input) {
- Ok((i, o)) => Ok((i, Some(o))),
- Err(e) => Err(e),
- }
+ f.parse_next(input).map(Some)
} else {
- Ok((input, None))
+ Ok(None)
}
})
}
@@ -128,7 +127,7 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, IResult};
/// # use winnow::prelude::*;
/// use winnow::combinator::peek;
/// use winnow::ascii::alpha1;
@@ -136,22 +135,21 @@ where
///
/// let mut parser = peek(alpha1);
///
-/// assert_eq!(parser.parse_next("abcd;"), Ok(("abcd;", "abcd")));
-/// assert_eq!(parser.parse_next("123;"), Err(ErrMode::Backtrack(Error::new("123;", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("abcd;"), Ok(("abcd;", "abcd")));
+/// assert_eq!(parser.parse_peek("123;"), Err(ErrMode::Backtrack(InputError::new("123;", ErrorKind::Slice))));
/// # }
/// ```
#[doc(alias = "look_ahead")]
#[doc(alias = "rewind")]
-pub fn peek<I: Stream, O, E: ParseError<I>, F>(mut f: F) -> impl Parser<I, O, E>
+pub fn peek<I: Stream, O, E: ParserError<I>, F>(mut f: F) -> impl Parser<I, O, E>
where
F: Parser<I, O, E>,
{
- trace("peek", move |input: I| {
- let i = input.clone();
- match f.parse_next(input) {
- Ok((_, o)) => Ok((i, o)),
- Err(e) => Err(e),
- }
+ trace("peek", move |input: &mut I| {
+ let start = input.checkpoint();
+ let res = f.parse_next(input);
+ input.reset(start);
+ res
})
}
@@ -163,21 +161,21 @@ where
///
/// ```rust
/// # use std::str;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// # use winnow::combinator::eof;
/// # use winnow::prelude::*;
///
/// let mut parser = eof;
-/// assert_eq!(parser.parse_next("abc"), Err(ErrMode::Backtrack(Error::new("abc", ErrorKind::Eof))));
-/// assert_eq!(parser.parse_next(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("abc"), Err(ErrMode::Backtrack(InputError::new("abc", ErrorKind::Eof))));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
#[doc(alias = "end")]
#[doc(alias = "eoi")]
-pub fn eof<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn eof<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: Stream,
{
- trace("eof", move |input: I| {
+ trace("eof", move |input: &mut I| {
if input.eof_offset() == 0 {
Ok(input.next_slice(0))
} else {
@@ -194,7 +192,7 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, IResult};
/// # use winnow::prelude::*;
/// use winnow::combinator::not;
/// use winnow::ascii::alpha1;
@@ -202,19 +200,21 @@ where
///
/// let mut parser = not(alpha1);
///
-/// assert_eq!(parser.parse_next("123"), Ok(("123", ())));
-/// assert_eq!(parser.parse_next("abcd"), Err(ErrMode::Backtrack(Error::new("abcd", ErrorKind::Not))));
+/// assert_eq!(parser.parse_peek("123"), Ok(("123", ())));
+/// assert_eq!(parser.parse_peek("abcd"), Err(ErrMode::Backtrack(InputError::new("abcd", ErrorKind::Not))));
/// # }
/// ```
-pub fn not<I: Stream, O, E: ParseError<I>, F>(mut parser: F) -> impl Parser<I, (), E>
+pub fn not<I: Stream, O, E: ParserError<I>, F>(mut parser: F) -> impl Parser<I, (), E>
where
F: Parser<I, O, E>,
{
- trace("not", move |input: I| {
- let i = input.clone();
- match parser.parse_next(input) {
- Ok(_) => Err(ErrMode::from_error_kind(i, ErrorKind::Not)),
- Err(ErrMode::Backtrack(_)) => Ok((i, ())),
+ trace("not", move |input: &mut I| {
+ let start = input.checkpoint();
+ let res = parser.parse_next(input);
+ input.reset(start);
+ match res {
+ Ok(_) => Err(ErrMode::from_error_kind(input, ErrorKind::Not)),
+ Err(ErrMode::Backtrack(_)) => Ok(()),
Err(e) => Err(e),
}
})
@@ -229,7 +229,7 @@ where
///
/// Without `cut_err`:
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// # use winnow::token::one_of;
/// # use winnow::ascii::digit1;
/// # use winnow::combinator::rest;
@@ -240,9 +240,9 @@ where
///
/// fn parser(input: &str) -> IResult<&str, &str> {
/// alt((
-/// preceded(one_of("+-"), digit1),
+/// preceded(one_of(['+', '-']), digit1),
/// rest
-/// )).parse_next(input)
+/// )).parse_peek(input)
/// }
///
/// assert_eq!(parser("+10 ab"), Ok((" ab", "10")));
@@ -253,7 +253,7 @@ where
///
/// With `cut_err`:
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// # use winnow::prelude::*;
/// # use winnow::token::one_of;
/// # use winnow::ascii::digit1;
@@ -265,22 +265,22 @@ where
///
/// fn parser(input: &str) -> IResult<&str, &str> {
/// alt((
-/// preceded(one_of("+-"), cut_err(digit1)),
+/// preceded(one_of(['+', '-']), cut_err(digit1)),
/// rest
-/// )).parse_next(input)
+/// )).parse_peek(input)
/// }
///
/// assert_eq!(parser("+10 ab"), Ok((" ab", "10")));
/// assert_eq!(parser("ab"), Ok(("", "ab")));
-/// assert_eq!(parser("+"), Err(ErrMode::Cut(Error { input: "", kind: ErrorKind::Slice })));
+/// assert_eq!(parser("+"), Err(ErrMode::Cut(InputError::new("", ErrorKind::Slice ))));
/// # }
/// ```
-pub fn cut_err<I, O, E: ParseError<I>, F>(mut parser: F) -> impl Parser<I, O, E>
+pub fn cut_err<I, O, E: ParserError<I>, F>(mut parser: F) -> impl Parser<I, O, E>
where
I: Stream,
F: Parser<I, O, E>,
{
- trace("cut_err", move |input: I| {
+ trace("cut_err", move |input: &mut I| {
parser.parse_next(input).map_err(|e| e.cut())
})
}
@@ -289,12 +289,12 @@ where
///
/// This attempts the parse, allowing other parsers to be tried on failure, like with
/// [`winnow::combinator::alt`][crate::combinator::alt].
-pub fn backtrack_err<I, O, E: ParseError<I>, F>(mut parser: F) -> impl Parser<I, O, E>
+pub fn backtrack_err<I, O, E: ParserError<I>, F>(mut parser: F) -> impl Parser<I, O, E>
where
I: Stream,
F: Parser<I, O, E>,
{
- trace("backtrack_err", move |input: I| {
+ trace("backtrack_err", move |input: &mut I| {
parser.parse_next(input).map_err(|e| e.backtrack())
})
}
@@ -313,17 +313,17 @@ where
/// # use winnow::prelude::*;
/// # use winnow::combinator::todo;
///
-/// fn parser(input: &str) -> IResult<&str, u64> {
+/// fn parser(input: &mut &str) -> PResult<u64> {
/// todo(input)
/// }
/// ```
#[track_caller]
-pub fn todo<I, O, E>(input: I) -> IResult<I, O, E>
+pub fn todo<I, O, E>(input: &mut I) -> PResult<O, E>
where
I: Stream,
{
#![allow(clippy::todo)]
- trace("todo", move |_input: I| todo!("unimplemented parse")).parse_next(input)
+ trace("todo", move |_input: &mut I| todo!("unimplemented parse")).parse_next(input)
}
/// Repeats the embedded parser, lazily returning the results
@@ -352,7 +352,7 @@ pub fn iterator<I, O, E, F>(input: I, parser: F) -> ParserIterator<F, I, O, E>
where
F: Parser<I, O, E>,
I: Stream,
- E: ParseError<I>,
+ E: ParserError<I>,
{
ParserIterator {
parser,
@@ -380,7 +380,7 @@ where
I: Stream,
{
/// Returns the remaining input if parsing was successful, or the error if we encountered an error.
- pub fn finish(mut self) -> IResult<I, (), E> {
+ pub fn finish(mut self) -> PResult<(I, ()), E> {
match self.state.take().unwrap() {
State::Running | State::Done => Ok((self.input, ())),
State::Failure(e) => Err(ErrMode::Cut(e)),
@@ -398,15 +398,15 @@ where
fn next(&mut self) -> Option<Self::Item> {
if let State::Running = self.state.take().unwrap() {
- let input = self.input.clone();
+ let start = self.input.checkpoint();
- match self.parser.parse_next(input) {
- Ok((i, o)) => {
- self.input = i;
+ match self.parser.parse_next(&mut self.input) {
+ Ok(o) => {
self.state = Some(State::Running);
Some(o)
}
Err(ErrMode::Backtrack(_)) => {
+ self.input.reset(start);
self.state = Some(State::Done);
None
}
@@ -442,20 +442,20 @@ enum State<E> {
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// # use winnow::prelude::*;
/// use winnow::combinator::alt;
/// use winnow::combinator::success;
///
-/// let mut parser = success::<_,_,Error<_>>(10);
-/// assert_eq!(parser.parse_next("xyz"), Ok(("xyz", 10)));
+/// let mut parser = success::<_,_,InputError<_>>(10);
+/// assert_eq!(parser.parse_peek("xyz"), Ok(("xyz", 10)));
///
/// fn sign(input: &str) -> IResult<&str, isize> {
/// alt((
/// '-'.value(-1),
/// '+'.value(1),
-/// success::<_,_,Error<_>>(1)
-/// )).parse_next(input)
+/// success::<_,_,InputError<_>>(1)
+/// )).parse_peek(input)
/// }
/// assert_eq!(sign("+10"), Ok(("10", 1)));
/// assert_eq!(sign("-10"), Ok(("10", -1)));
@@ -463,8 +463,8 @@ enum State<E> {
/// ```
#[doc(alias = "value")]
#[doc(alias = "empty")]
-pub fn success<I: Stream, O: Clone, E: ParseError<I>>(val: O) -> impl Parser<I, O, E> {
- trace("success", move |input: I| Ok((input, val.clone())))
+pub fn success<I: Stream, O: Clone, E: ParserError<I>>(val: O) -> impl Parser<I, O, E> {
+ trace("success", move |_input: &mut I| Ok(val.clone()))
}
/// A parser which always fails.
@@ -475,15 +475,16 @@ pub fn success<I: Stream, O: Clone, E: ParseError<I>>(val: O) -> impl Parser<I,
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, IResult};
+/// # use winnow::prelude::*;
/// use winnow::combinator::fail;
///
/// let s = "string";
-/// assert_eq!(fail::<_, &str, _>(s), Err(ErrMode::Backtrack(Error::new(s, ErrorKind::Fail))));
+/// assert_eq!(fail::<_, &str, _>.parse_peek(s), Err(ErrMode::Backtrack(InputError::new(s, ErrorKind::Fail))));
/// ```
#[doc(alias = "unexpected")]
-pub fn fail<I: Stream, O, E: ParseError<I>>(i: I) -> IResult<I, O, E> {
- trace("fail", |i| {
+pub fn fail<I: Stream, O, E: ParserError<I>>(i: &mut I) -> PResult<O, E> {
+ trace("fail", |i: &mut I| {
Err(ErrMode::from_error_kind(i, ErrorKind::Fail))
})
.parse_next(i)
diff --git a/vendor/winnow/src/combinator/multi.rs b/vendor/winnow/src/combinator/multi.rs
index 950432601..1fdb7535b 100644
--- a/vendor/winnow/src/combinator/multi.rs
+++ b/vendor/winnow/src/combinator/multi.rs
@@ -2,12 +2,12 @@
use crate::error::ErrMode;
use crate::error::ErrorKind;
-use crate::error::ParseError;
+use crate::error::ParserError;
use crate::stream::Accumulate;
use crate::stream::Range;
use crate::stream::Stream;
use crate::trace::trace;
-use crate::IResult;
+use crate::PResult;
use crate::Parser;
/// [`Accumulate`] the output of a parser into a container, like `Vec`
@@ -37,7 +37,7 @@ use crate::Parser;
/// use winnow::token::tag;
///
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
-/// repeat(0.., "abc").parse_next(s)
+/// repeat(0.., "abc").parse_peek(s)
/// }
///
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
@@ -50,38 +50,38 @@ use crate::Parser;
/// One or more reptitions:
/// ```rust
/// # #[cfg(feature = "std")] {
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::combinator::repeat;
/// use winnow::token::tag;
///
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
-/// repeat(1.., "abc").parse_next(s)
+/// repeat(1.., "abc").parse_peek(s)
/// }
///
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
/// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
-/// assert_eq!(parser("123123"), Err(ErrMode::Backtrack(Error::new("123123", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser("123123"), Err(ErrMode::Backtrack(InputError::new("123123", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// # }
/// ```
///
/// Fixed number of repeitions:
/// ```rust
/// # #[cfg(feature = "std")] {
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::combinator::repeat;
/// use winnow::token::tag;
///
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
-/// repeat(2, "abc").parse_next(s)
+/// repeat(2, "abc").parse_peek(s)
/// }
///
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
-/// assert_eq!(parser("abc123"), Err(ErrMode::Backtrack(Error::new("123", ErrorKind::Tag))));
-/// assert_eq!(parser("123123"), Err(ErrMode::Backtrack(Error::new("123123", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser("abc123"), Err(ErrMode::Backtrack(InputError::new("123", ErrorKind::Tag))));
+/// assert_eq!(parser("123123"), Err(ErrMode::Backtrack(InputError::new("123123", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));
/// # }
/// ```
@@ -95,7 +95,7 @@ use crate::Parser;
/// use winnow::token::tag;
///
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
-/// repeat(0..=2, "abc").parse_next(s)
+/// repeat(0..=2, "abc").parse_peek(s)
/// }
///
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
@@ -120,13 +120,13 @@ where
I: Stream,
C: Accumulate<O>,
F: Parser<I, O, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
let Range {
start_inclusive,
end_inclusive,
} = range.into();
- trace("repeat", move |i: I| {
+ trace("repeat", move |i: &mut I| {
match (start_inclusive, end_inclusive) {
(0, None) => repeat0_(&mut f, i),
(1, None) => repeat1_(&mut f, i),
@@ -136,84 +136,63 @@ where
})
}
-/// Deprecated, replaced by [`repeat`]
-#[deprecated(since = "0.4.6", note = "Replaced with `repeat`")]
-#[inline(always)]
-pub fn repeat0<I, O, C, E, F>(f: F) -> impl Parser<I, C, E>
-where
- I: Stream,
- C: Accumulate<O>,
- F: Parser<I, O, E>,
- E: ParseError<I>,
-{
- repeat(0.., f)
-}
-
-fn repeat0_<I, O, C, E, F>(f: &mut F, mut i: I) -> IResult<I, C, E>
+fn repeat0_<I, O, C, E, F>(f: &mut F, i: &mut I) -> PResult<C, E>
where
I: Stream,
C: Accumulate<O>,
F: Parser<I, O, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
let mut acc = C::initial(None);
loop {
+ let start = i.checkpoint();
let len = i.eof_offset();
- match f.parse_next(i.clone()) {
- Err(ErrMode::Backtrack(_)) => return Ok((i, acc)),
+ match f.parse_next(i) {
+ Err(ErrMode::Backtrack(_)) => {
+ i.reset(start);
+ return Ok(acc);
+ }
Err(e) => return Err(e),
- Ok((i1, o)) => {
+ Ok(o) => {
// infinite loop check: the parser must always consume
- if i1.eof_offset() == len {
+ if i.eof_offset() == len {
return Err(ErrMode::assert(i, "`repeat` parsers must always consume"));
}
- i = i1;
acc.accumulate(o);
}
}
}
}
-/// Deprecated, replaced by [`repeat`]
-#[deprecated(since = "0.4.6", note = "Replaced with `repeat`")]
-#[inline(always)]
-pub fn repeat1<I, O, C, E, F>(f: F) -> impl Parser<I, C, E>
-where
- I: Stream,
- C: Accumulate<O>,
- F: Parser<I, O, E>,
- E: ParseError<I>,
-{
- repeat(1.., f)
-}
-
-fn repeat1_<I, O, C, E, F>(f: &mut F, mut i: I) -> IResult<I, C, E>
+fn repeat1_<I, O, C, E, F>(f: &mut F, i: &mut I) -> PResult<C, E>
where
I: Stream,
C: Accumulate<O>,
F: Parser<I, O, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
- match f.parse_next(i.clone()) {
+ match f.parse_next(i) {
Err(e) => Err(e.append(i, ErrorKind::Many)),
- Ok((i1, o)) => {
+ Ok(o) => {
let mut acc = C::initial(None);
acc.accumulate(o);
- i = i1;
loop {
+ let start = i.checkpoint();
let len = i.eof_offset();
- match f.parse_next(i.clone()) {
- Err(ErrMode::Backtrack(_)) => return Ok((i, acc)),
+ match f.parse_next(i) {
+ Err(ErrMode::Backtrack(_)) => {
+ i.reset(start);
+ return Ok(acc);
+ }
Err(e) => return Err(e),
- Ok((i1, o)) => {
+ Ok(o) => {
// infinite loop check: the parser must always consume
- if i1.eof_offset() == len {
+ if i.eof_offset() == len {
return Err(ErrMode::assert(i, "`repeat` parsers must always consume"));
}
- i = i1;
acc.accumulate(o);
}
}
@@ -235,19 +214,19 @@ where
///
/// ```rust
/// # #[cfg(feature = "std")] {
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::combinator::repeat_till0;
/// use winnow::token::tag;
///
/// fn parser(s: &str) -> IResult<&str, (Vec<&str>, &str)> {
-/// repeat_till0("abc", "end").parse_next(s)
+/// repeat_till0("abc", "end").parse_peek(s)
/// };
///
/// assert_eq!(parser("abcabcend"), Ok(("", (vec!["abc", "abc"], "end"))));
-/// assert_eq!(parser("abc123end"), Err(ErrMode::Backtrack(Error::new("123end", ErrorKind::Tag))));
-/// assert_eq!(parser("123123end"), Err(ErrMode::Backtrack(Error::new("123123end", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser("abc123end"), Err(ErrMode::Backtrack(InputError::new("123end", ErrorKind::Tag))));
+/// assert_eq!(parser("123123end"), Err(ErrMode::Backtrack(InputError::new("123123end", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// assert_eq!(parser("abcendefg"), Ok(("efg", (vec!["abc"], "end"))));
/// # }
/// ```
@@ -258,20 +237,22 @@ where
C: Accumulate<O>,
F: Parser<I, O, E>,
G: Parser<I, P, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
- trace("repeat_till0", move |mut i: I| {
+ trace("repeat_till0", move |i: &mut I| {
let mut res = C::initial(None);
loop {
+ let start = i.checkpoint();
let len = i.eof_offset();
- match g.parse_next(i.clone()) {
- Ok((i1, o)) => return Ok((i1, (res, o))),
+ match g.parse_next(i) {
+ Ok(o) => return Ok((res, o)),
Err(ErrMode::Backtrack(_)) => {
- match f.parse_next(i.clone()) {
+ i.reset(start);
+ match f.parse_next(i) {
Err(e) => return Err(e.append(i, ErrorKind::Many)),
- Ok((i1, o)) => {
+ Ok(o) => {
// infinite loop check: the parser must always consume
- if i1.eof_offset() == len {
+ if i.eof_offset() == len {
return Err(ErrMode::assert(
i,
"`repeat` parsers must always consume",
@@ -279,7 +260,6 @@ where
}
res.accumulate(o);
- i = i1;
}
}
}
@@ -308,7 +288,7 @@ where
/// use winnow::token::tag;
///
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
-/// separated0("abc", "|").parse_next(s)
+/// separated0("abc", "|").parse_peek(s)
/// }
///
/// assert_eq!(parser("abc|abc|abc"), Ok(("", vec!["abc", "abc", "abc"])));
@@ -326,37 +306,46 @@ where
C: Accumulate<O>,
P: Parser<I, O, E>,
S: Parser<I, O2, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
- trace("separated0", move |mut i: I| {
+ trace("separated0", move |i: &mut I| {
let mut res = C::initial(None);
- match parser.parse_next(i.clone()) {
- Err(ErrMode::Backtrack(_)) => return Ok((i, res)),
+ let start = i.checkpoint();
+ match parser.parse_next(i) {
+ Err(ErrMode::Backtrack(_)) => {
+ i.reset(start);
+ return Ok(res);
+ }
Err(e) => return Err(e),
- Ok((i1, o)) => {
+ Ok(o) => {
res.accumulate(o);
- i = i1;
}
}
loop {
+ let start = i.checkpoint();
let len = i.eof_offset();
- match sep.parse_next(i.clone()) {
- Err(ErrMode::Backtrack(_)) => return Ok((i, res)),
+ match sep.parse_next(i) {
+ Err(ErrMode::Backtrack(_)) => {
+ i.reset(start);
+ return Ok(res);
+ }
Err(e) => return Err(e),
- Ok((i1, _)) => {
+ Ok(_) => {
// infinite loop check: the parser must always consume
- if i1.eof_offset() == len {
+ if i.eof_offset() == len {
return Err(ErrMode::assert(i, "sep parsers must always consume"));
}
- match parser.parse_next(i1.clone()) {
- Err(ErrMode::Backtrack(_)) => return Ok((i, res)),
+ match parser.parse_next(i) {
+ Err(ErrMode::Backtrack(_)) => {
+ i.reset(start);
+ return Ok(res);
+ }
Err(e) => return Err(e),
- Ok((i2, o)) => {
+ Ok(o) => {
res.accumulate(o);
- i = i2;
}
}
}
@@ -380,20 +369,20 @@ where
///
/// ```rust
/// # #[cfg(feature = "std")] {
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::combinator::separated1;
/// use winnow::token::tag;
///
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
-/// separated1("abc", "|").parse_next(s)
+/// separated1("abc", "|").parse_peek(s)
/// }
///
/// assert_eq!(parser("abc|abc|abc"), Ok(("", vec!["abc", "abc", "abc"])));
/// assert_eq!(parser("abc123abc"), Ok(("123abc", vec!["abc"])));
/// assert_eq!(parser("abc|def"), Ok(("|def", vec!["abc"])));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
-/// assert_eq!(parser("def|abc"), Err(ErrMode::Backtrack(Error::new("def|abc", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
+/// assert_eq!(parser("def|abc"), Err(ErrMode::Backtrack(InputError::new("def|abc", ErrorKind::Tag))));
/// # }
/// ```
#[doc(alias = "sep_by1")]
@@ -404,37 +393,42 @@ where
C: Accumulate<O>,
P: Parser<I, O, E>,
S: Parser<I, O2, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
- trace("separated1", move |mut i: I| {
+ trace("separated1", move |i: &mut I| {
let mut res = C::initial(None);
// Parse the first element
- match parser.parse_next(i.clone()) {
+ match parser.parse_next(i) {
Err(e) => return Err(e),
- Ok((i1, o)) => {
+ Ok(o) => {
res.accumulate(o);
- i = i1;
}
}
loop {
+ let start = i.checkpoint();
let len = i.eof_offset();
- match sep.parse_next(i.clone()) {
- Err(ErrMode::Backtrack(_)) => return Ok((i, res)),
+ match sep.parse_next(i) {
+ Err(ErrMode::Backtrack(_)) => {
+ i.reset(start);
+ return Ok(res);
+ }
Err(e) => return Err(e),
- Ok((i1, _)) => {
+ Ok(_) => {
// infinite loop check: the parser must always consume
- if i1.eof_offset() == len {
+ if i.eof_offset() == len {
return Err(ErrMode::assert(i, "sep parsers must always consume"));
}
- match parser.parse_next(i1.clone()) {
- Err(ErrMode::Backtrack(_)) => return Ok((i, res)),
+ match parser.parse_next(i) {
+ Err(ErrMode::Backtrack(_)) => {
+ i.reset(start);
+ return Ok(res);
+ }
Err(e) => return Err(e),
- Ok((i2, o)) => {
+ Ok(o) => {
res.accumulate(o);
- i = i2;
}
}
}
@@ -451,18 +445,18 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::combinator::separated_foldl1;
/// use winnow::ascii::dec_int;
///
/// fn parser(s: &str) -> IResult<&str, i32> {
-/// separated_foldl1(dec_int, "-", |l, _, r| l - r).parse_next(s)
+/// separated_foldl1(dec_int, "-", |l, _, r| l - r).parse_peek(s)
/// }
///
/// assert_eq!(parser("9-3-5"), Ok(("", 1)));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
-/// assert_eq!(parser("def|abc"), Err(ErrMode::Backtrack(Error::new("def|abc", ErrorKind::Slice))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
+/// assert_eq!(parser("def|abc"), Err(ErrMode::Backtrack(InputError::new("def|abc", ErrorKind::Slice))));
/// ```
pub fn separated_foldl1<I, O, O2, E, P, S, Op>(
mut parser: P,
@@ -473,29 +467,35 @@ where
I: Stream,
P: Parser<I, O, E>,
S: Parser<I, O2, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
Op: Fn(O, O2, O) -> O,
{
- trace("separated_foldl1", move |i: I| {
- let (mut i, mut ol) = parser.parse_next(i)?;
+ trace("separated_foldl1", move |i: &mut I| {
+ let mut ol = parser.parse_next(i)?;
loop {
+ let start = i.checkpoint();
let len = i.eof_offset();
- match sep.parse_next(i.clone()) {
- Err(ErrMode::Backtrack(_)) => return Ok((i, ol)),
+ match sep.parse_next(i) {
+ Err(ErrMode::Backtrack(_)) => {
+ i.reset(start);
+ return Ok(ol);
+ }
Err(e) => return Err(e),
- Ok((i1, s)) => {
+ Ok(s) => {
// infinite loop check: the parser must always consume
- if i1.eof_offset() == len {
+ if i.eof_offset() == len {
return Err(ErrMode::assert(i, "`repeat` parsers must always consume"));
}
- match parser.parse_next(i1.clone()) {
- Err(ErrMode::Backtrack(_)) => return Ok((i, ol)),
+ match parser.parse_next(i) {
+ Err(ErrMode::Backtrack(_)) => {
+ i.reset(start);
+ return Ok(ol);
+ }
Err(e) => return Err(e),
- Ok((i2, or)) => {
+ Ok(or) => {
ol = op(ol, s, or);
- i = i2;
}
}
}
@@ -512,19 +512,19 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::combinator::separated_foldr1;
/// use winnow::ascii::dec_uint;
///
/// fn parser(s: &str) -> IResult<&str, u32> {
-/// separated_foldr1(dec_uint, "^", |l: u32, _, r: u32| l.pow(r)).parse_next(s)
+/// separated_foldr1(dec_uint, "^", |l: u32, _, r: u32| l.pow(r)).parse_peek(s)
/// }
///
/// assert_eq!(parser("2^3^2"), Ok(("", 512)));
/// assert_eq!(parser("2"), Ok(("", 2)));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
-/// assert_eq!(parser("def|abc"), Err(ErrMode::Backtrack(Error::new("def|abc", ErrorKind::Slice))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
+/// assert_eq!(parser("def|abc"), Err(ErrMode::Backtrack(InputError::new("def|abc", ErrorKind::Slice))));
/// ```
#[cfg(feature = "alloc")]
pub fn separated_foldr1<I, O, O2, E, P, S, Op>(
@@ -536,12 +536,12 @@ where
I: Stream,
P: Parser<I, O, E>,
S: Parser<I, O2, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
Op: Fn(O, O2, O) -> O,
{
- trace("separated_foldr1", move |i: I| {
- let (i, ol) = parser.parse_next(i)?;
- let (i, all): (_, crate::lib::std::vec::Vec<(O2, O)>) =
+ trace("separated_foldr1", move |i: &mut I| {
+ let ol = parser.parse_next(i)?;
+ let all: crate::lib::std::vec::Vec<(O2, O)> =
repeat(0.., (sep.by_ref(), parser.by_ref())).parse_next(i)?;
if let Some((s, or)) = all
.into_iter()
@@ -549,24 +549,19 @@ where
.reduce(|(sr, or), (sl, ol)| (sl, op(ol, sr, or)))
{
let merged = op(ol, s, or);
- Ok((i, merged))
+ Ok(merged)
} else {
- Ok((i, ol))
+ Ok(ol)
}
})
}
-fn repeat_m_n_<I, O, C, E, F>(
- min: usize,
- max: usize,
- parse: &mut F,
- mut input: I,
-) -> IResult<I, C, E>
+fn repeat_m_n_<I, O, C, E, F>(min: usize, max: usize, parse: &mut F, input: &mut I) -> PResult<C, E>
where
I: Stream,
C: Accumulate<O>,
F: Parser<I, O, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
if min > max {
return Err(ErrMode::Cut(E::from_error_kind(input, ErrorKind::Many)));
@@ -574,11 +569,12 @@ where
let mut res = C::initial(Some(min));
for count in 0..max {
+ let start = input.checkpoint();
let len = input.eof_offset();
- match parse.parse_next(input.clone()) {
- Ok((tail, value)) => {
+ match parse.parse_next(input) {
+ Ok(value) => {
// infinite loop check: the parser must always consume
- if tail.eof_offset() == len {
+ if input.eof_offset() == len {
return Err(ErrMode::assert(
input,
"`repeat` parsers must always consume",
@@ -586,13 +582,13 @@ where
}
res.accumulate(value);
- input = tail;
}
Err(ErrMode::Backtrack(e)) => {
if count < min {
return Err(ErrMode::Backtrack(e.append(input, ErrorKind::Many)));
} else {
- return Ok((input, res));
+ input.reset(start);
+ return Ok(res);
}
}
Err(e) => {
@@ -601,38 +597,22 @@ where
}
}
- Ok((input, res))
+ Ok(res)
}
-/// Deprecated, replaced by [`repeat`]
-#[deprecated(since = "0.4.6", note = "Replaced with `repeat`")]
-#[inline(always)]
-pub fn count<I, O, C, E, F>(f: F, count: usize) -> impl Parser<I, C, E>
+fn repeat_n_<I, O, C, E, F>(count: usize, f: &mut F, i: &mut I) -> PResult<C, E>
where
I: Stream,
C: Accumulate<O>,
F: Parser<I, O, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
- repeat(count, f)
-}
-
-fn repeat_n_<I, O, C, E, F>(count: usize, f: &mut F, i: I) -> IResult<I, C, E>
-where
- I: Stream,
- C: Accumulate<O>,
- F: Parser<I, O, E>,
- E: ParseError<I>,
-{
- let mut input = i.clone();
let mut res = C::initial(Some(count));
for _ in 0..count {
- let input_ = input.clone();
- match f.parse_next(input_) {
- Ok((i, o)) => {
+ match f.parse_next(i) {
+ Ok(o) => {
res.accumulate(o);
- input = i;
}
Err(e) => {
return Err(e.append(i, ErrorKind::Many));
@@ -640,7 +620,7 @@ where
}
}
- Ok((input, res))
+ Ok(res)
}
/// Repeats the embedded parser, filling the given slice with results.
@@ -654,38 +634,34 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::combinator::fill;
/// use winnow::token::tag;
///
/// fn parser(s: &str) -> IResult<&str, [&str; 2]> {
/// let mut buf = ["", ""];
-/// let (rest, ()) = fill("abc", &mut buf).parse_next(s)?;
+/// let (rest, ()) = fill("abc", &mut buf).parse_peek(s)?;
/// Ok((rest, buf))
/// }
///
/// assert_eq!(parser("abcabc"), Ok(("", ["abc", "abc"])));
-/// assert_eq!(parser("abc123"), Err(ErrMode::Backtrack(Error::new("123", ErrorKind::Tag))));
-/// assert_eq!(parser("123123"), Err(ErrMode::Backtrack(Error::new("123123", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser("abc123"), Err(ErrMode::Backtrack(InputError::new("123", ErrorKind::Tag))));
+/// assert_eq!(parser("123123"), Err(ErrMode::Backtrack(InputError::new("123123", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// assert_eq!(parser("abcabcabc"), Ok(("abc", ["abc", "abc"])));
/// ```
pub fn fill<'a, I, O, E, F>(mut f: F, buf: &'a mut [O]) -> impl Parser<I, (), E> + 'a
where
I: Stream + 'a,
F: Parser<I, O, E> + 'a,
- E: ParseError<I> + 'a,
+ E: ParserError<I> + 'a,
{
- trace("fill", move |i: I| {
- let mut input = i.clone();
-
+ trace("fill", move |i: &mut I| {
for elem in buf.iter_mut() {
- let input_ = input.clone();
- match f.parse_next(input_) {
- Ok((i, o)) => {
+ match f.parse_next(i) {
+ Ok(o) => {
*elem = o;
- input = i;
}
Err(e) => {
return Err(e.append(i, ErrorKind::Many));
@@ -693,7 +669,7 @@ where
}
}
- Ok((input, ()))
+ Ok(())
})
}
@@ -732,7 +708,7 @@ where
/// acc.push(item);
/// acc
/// }
-/// ).parse_next(s)
+/// ).parse_peek(s)
/// }
///
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
@@ -743,7 +719,7 @@ where
///
/// One or more repetitions:
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::combinator::fold_repeat;
/// use winnow::token::tag;
@@ -757,13 +733,13 @@ where
/// acc.push(item);
/// acc
/// }
-/// ).parse_next(s)
+/// ).parse_peek(s)
/// }
///
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
/// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
-/// assert_eq!(parser("123123"), Err(ErrMode::Backtrack(Error::new("123123", ErrorKind::Many))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Many))));
+/// assert_eq!(parser("123123"), Err(ErrMode::Backtrack(InputError::new("123123", ErrorKind::Many))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Many))));
/// ```
///
/// Arbitrary number of repetitions:
@@ -782,7 +758,7 @@ where
/// acc.push(item);
/// acc
/// }
-/// ).parse_next(s)
+/// ).parse_peek(s)
/// }
///
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
@@ -806,13 +782,13 @@ where
F: Parser<I, O, E>,
G: FnMut(R, O) -> R,
H: FnMut() -> R,
- E: ParseError<I>,
+ E: ParserError<I>,
{
let Range {
start_inclusive,
end_inclusive,
} = range.into();
- trace("fold_repeat", move |i: I| {
+ trace("fold_repeat", move |i: &mut I| {
match (start_inclusive, end_inclusive) {
(0, None) => fold_repeat0_(&mut f, &mut init, &mut g, i),
(1, None) => fold_repeat1_(&mut f, &mut init, &mut g, i),
@@ -828,48 +804,39 @@ where
})
}
-/// Deprecated, replaced by [`fold_repeat`]
-#[deprecated(since = "0.4.6", note = "Replaced with `fold_repeat`")]
-#[inline(always)]
-pub fn fold_repeat0<I, O, E, F, G, H, R>(mut f: F, mut init: H, mut g: G) -> impl Parser<I, R, E>
-where
- I: Stream,
- F: Parser<I, O, E>,
- G: FnMut(R, O) -> R,
- H: FnMut() -> R,
- E: ParseError<I>,
-{
- trace("fold_repeat0", move |i: I| {
- fold_repeat0_(&mut f, &mut init, &mut g, i)
- })
-}
-
-fn fold_repeat0_<I, O, E, F, G, H, R>(f: &mut F, init: &mut H, g: &mut G, i: I) -> IResult<I, R, E>
+fn fold_repeat0_<I, O, E, F, G, H, R>(
+ f: &mut F,
+ init: &mut H,
+ g: &mut G,
+ input: &mut I,
+) -> PResult<R, E>
where
I: Stream,
F: Parser<I, O, E>,
G: FnMut(R, O) -> R,
H: FnMut() -> R,
- E: ParseError<I>,
+ E: ParserError<I>,
{
let mut res = init();
- let mut input = i;
loop {
- let i_ = input.clone();
+ let start = input.checkpoint();
let len = input.eof_offset();
- match f.parse_next(i_) {
- Ok((i, o)) => {
+ match f.parse_next(input) {
+ Ok(o) => {
// infinite loop check: the parser must always consume
- if i.eof_offset() == len {
- return Err(ErrMode::assert(i, "`repeat` parsers must always consume"));
+ if input.eof_offset() == len {
+ return Err(ErrMode::assert(
+ input,
+ "`repeat` parsers must always consume",
+ ));
}
res = g(res, o);
- input = i;
}
Err(ErrMode::Backtrack(_)) => {
- return Ok((input, res));
+ input.reset(start);
+ return Ok(res);
}
Err(e) => {
return Err(e);
@@ -878,60 +845,50 @@ where
}
}
-/// Deprecated, replaced by [`fold_repeat`]
-#[deprecated(since = "0.4.6", note = "Replaced with `fold_repeat`")]
-#[inline(always)]
-pub fn fold_repeat1<I, O, E, F, G, H, R>(mut f: F, mut init: H, mut g: G) -> impl Parser<I, R, E>
-where
- I: Stream,
- F: Parser<I, O, E>,
- G: FnMut(R, O) -> R,
- H: FnMut() -> R,
- E: ParseError<I>,
-{
- trace("fold_repeat1", move |i: I| {
- fold_repeat1_(&mut f, &mut init, &mut g, i)
- })
-}
-
-fn fold_repeat1_<I, O, E, F, G, H, R>(f: &mut F, init: &mut H, g: &mut G, i: I) -> IResult<I, R, E>
+fn fold_repeat1_<I, O, E, F, G, H, R>(
+ f: &mut F,
+ init: &mut H,
+ g: &mut G,
+ input: &mut I,
+) -> PResult<R, E>
where
I: Stream,
F: Parser<I, O, E>,
G: FnMut(R, O) -> R,
H: FnMut() -> R,
- E: ParseError<I>,
+ E: ParserError<I>,
{
- let _i = i.clone();
let init = init();
- match f.parse_next(_i) {
- Err(ErrMode::Backtrack(_)) => Err(ErrMode::from_error_kind(i, ErrorKind::Many)),
+ match f.parse_next(input) {
+ Err(ErrMode::Backtrack(_)) => Err(ErrMode::from_error_kind(input, ErrorKind::Many)),
Err(e) => Err(e),
- Ok((i1, o1)) => {
+ Ok(o1) => {
let mut acc = g(init, o1);
- let mut input = i1;
loop {
- let _input = input.clone();
+ let start = input.checkpoint();
let len = input.eof_offset();
- match f.parse_next(_input) {
+ match f.parse_next(input) {
Err(ErrMode::Backtrack(_)) => {
+ input.reset(start);
break;
}
Err(e) => return Err(e),
- Ok((i, o)) => {
+ Ok(o) => {
// infinite loop check: the parser must always consume
- if i.eof_offset() == len {
- return Err(ErrMode::assert(i, "`repeat` parsers must always consume"));
+ if input.eof_offset() == len {
+ return Err(ErrMode::assert(
+ input,
+ "`repeat` parsers must always consume",
+ ));
}
acc = g(acc, o);
- input = i;
}
}
}
- Ok((input, acc))
+ Ok(acc)
}
}
}
@@ -942,14 +899,14 @@ fn fold_repeat_m_n_<I, O, E, F, G, H, R>(
parse: &mut F,
init: &mut H,
fold: &mut G,
- mut input: I,
-) -> IResult<I, R, E>
+ input: &mut I,
+) -> PResult<R, E>
where
I: Stream,
F: Parser<I, O, E>,
G: FnMut(R, O) -> R,
H: FnMut() -> R,
- E: ParseError<I>,
+ E: ParserError<I>,
{
if min > max {
return Err(ErrMode::Cut(E::from_error_kind(input, ErrorKind::Many)));
@@ -957,11 +914,12 @@ where
let mut acc = init();
for count in 0..max {
+ let start = input.checkpoint();
let len = input.eof_offset();
- match parse.parse_next(input.clone()) {
- Ok((tail, value)) => {
+ match parse.parse_next(input) {
+ Ok(value) => {
// infinite loop check: the parser must always consume
- if tail.eof_offset() == len {
+ if input.eof_offset() == len {
return Err(ErrMode::assert(
input,
"`repeat` parsers must always consume",
@@ -969,13 +927,13 @@ where
}
acc = fold(acc, value);
- input = tail;
}
//FInputXMError: handle failure properly
Err(ErrMode::Backtrack(err)) => {
if count < min {
return Err(ErrMode::Backtrack(err.append(input, ErrorKind::Many)));
} else {
+ input.reset(start);
break;
}
}
@@ -983,5 +941,5 @@ where
}
}
- Ok((input, acc))
+ Ok(acc)
}
diff --git a/vendor/winnow/src/combinator/parser.rs b/vendor/winnow/src/combinator/parser.rs
index 12b223a2e..969c2d525 100644
--- a/vendor/winnow/src/combinator/parser.rs
+++ b/vendor/winnow/src/combinator/parser.rs
@@ -1,8 +1,8 @@
-use crate::error::{ContextError, ErrMode, ErrorKind, FromExternalError, ParseError};
+use crate::error::{AddContext, ErrMode, ErrorKind, FromExternalError, ParserError};
use crate::lib::std::borrow::Borrow;
use crate::lib::std::ops::Range;
+use crate::stream::StreamIsPartial;
use crate::stream::{Location, Stream};
-use crate::stream::{Offset, StreamIsPartial};
use crate::trace::trace;
use crate::trace::trace_result;
use crate::*;
@@ -20,7 +20,8 @@ impl<'p, P> ByRef<'p, P> {
}
impl<'p, I, O, E, P: Parser<I, O, E>> Parser<I, O, E> for ByRef<'p, P> {
- fn parse_next(&mut self, i: I) -> IResult<I, O, E> {
+ #[inline(always)]
+ fn parse_next(&mut self, i: &mut I) -> PResult<O, E> {
self.p.parse_next(i)
}
}
@@ -62,24 +63,22 @@ where
F: Parser<I, O, E>,
G: Fn(O) -> O2,
{
- fn parse_next(&mut self, i: I) -> IResult<I, O2, E> {
+ #[inline]
+ fn parse_next(&mut self, i: &mut I) -> PResult<O2, E> {
match self.parser.parse_next(i) {
Err(e) => Err(e),
- Ok((i, o)) => Ok((i, (self.map)(o))),
+ Ok(o) => Ok((self.map)(o)),
}
}
}
-#[deprecated(since = "0.4.2", note = "Replaced with `TryMap`")]
-pub use TryMap as MapRes;
-
/// Implementation of [`Parser::try_map`]
#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
pub struct TryMap<F, G, I, O, O2, E, E2>
where
F: Parser<I, O, E>,
G: FnMut(O) -> Result<O2, E2>,
- I: Clone,
+ I: Stream,
E: FromExternalError<I, E2>,
{
parser: F,
@@ -95,7 +94,7 @@ impl<F, G, I, O, O2, E, E2> TryMap<F, G, I, O, O2, E, E2>
where
F: Parser<I, O, E>,
G: FnMut(O) -> Result<O2, E2>,
- I: Clone,
+ I: Stream,
E: FromExternalError<I, E2>,
{
pub(crate) fn new(parser: F, map: G) -> Self {
@@ -115,16 +114,17 @@ impl<F, G, I, O, O2, E, E2> Parser<I, O2, E> for TryMap<F, G, I, O, O2, E, E2>
where
F: Parser<I, O, E>,
G: FnMut(O) -> Result<O2, E2>,
- I: Clone,
+ I: Stream,
E: FromExternalError<I, E2>,
{
- fn parse_next(&mut self, input: I) -> IResult<I, O2, E> {
- let i = input.clone();
- let (input, o) = self.parser.parse_next(input)?;
- let res = match (self.map)(o) {
- Ok(o2) => Ok((input, o2)),
- Err(e) => Err(ErrMode::from_external_error(i, ErrorKind::Verify, e)),
- };
+ #[inline]
+ fn parse_next(&mut self, input: &mut I) -> PResult<O2, E> {
+ let start = input.checkpoint();
+ let o = self.parser.parse_next(input)?;
+ let res = (self.map)(o).map_err(|err| {
+ input.reset(start);
+ ErrMode::from_external_error(input, ErrorKind::Verify, err)
+ });
trace_result("verify", &res);
res
}
@@ -136,8 +136,8 @@ pub struct VerifyMap<F, G, I, O, O2, E>
where
F: Parser<I, O, E>,
G: FnMut(O) -> Option<O2>,
- I: Clone,
- E: ParseError<I>,
+ I: Stream,
+ E: ParserError<I>,
{
parser: F,
map: G,
@@ -151,8 +151,8 @@ impl<F, G, I, O, O2, E> VerifyMap<F, G, I, O, O2, E>
where
F: Parser<I, O, E>,
G: FnMut(O) -> Option<O2>,
- I: Clone,
- E: ParseError<I>,
+ I: Stream,
+ E: ParserError<I>,
{
pub(crate) fn new(parser: F, map: G) -> Self {
Self {
@@ -170,16 +170,17 @@ impl<F, G, I, O, O2, E> Parser<I, O2, E> for VerifyMap<F, G, I, O, O2, E>
where
F: Parser<I, O, E>,
G: FnMut(O) -> Option<O2>,
- I: Clone,
- E: ParseError<I>,
-{
- fn parse_next(&mut self, input: I) -> IResult<I, O2, E> {
- let i = input.clone();
- let (input, o) = self.parser.parse_next(input)?;
- let res = match (self.map)(o) {
- Some(o2) => Ok((input, o2)),
- None => Err(ErrMode::from_error_kind(i, ErrorKind::Verify)),
- };
+ I: Stream,
+ E: ParserError<I>,
+{
+ #[inline]
+ fn parse_next(&mut self, input: &mut I) -> PResult<O2, E> {
+ let start = input.checkpoint();
+ let o = self.parser.parse_next(input)?;
+ let res = (self.map)(o).ok_or_else(|| {
+ input.reset(start);
+ ErrMode::from_error_kind(input, ErrorKind::Verify)
+ });
trace_result("verify", &res);
res
}
@@ -192,6 +193,7 @@ where
F: Parser<I, O, E>,
G: Parser<O, O2, E>,
O: StreamIsPartial,
+ I: Stream,
{
outer: F,
inner: G,
@@ -206,6 +208,7 @@ where
F: Parser<I, O, E>,
G: Parser<O, O2, E>,
O: StreamIsPartial,
+ I: Stream,
{
pub(crate) fn new(outer: F, inner: G) -> Self {
Self {
@@ -224,12 +227,18 @@ where
F: Parser<I, O, E>,
G: Parser<O, O2, E>,
O: StreamIsPartial,
+ I: Stream,
{
- fn parse_next(&mut self, i: I) -> IResult<I, O2, E> {
- let (i, mut o) = self.outer.parse_next(i)?;
+ #[inline(always)]
+ fn parse_next(&mut self, i: &mut I) -> PResult<O2, E> {
+ let start = i.checkpoint();
+ let mut o = self.outer.parse_next(i)?;
let _ = o.complete();
- let (_, o2) = self.inner.parse_next(o)?;
- Ok((i, o2))
+ let o2 = self.inner.parse_next(&mut o).map_err(|err| {
+ i.reset(start);
+ err
+ })?;
+ Ok(o2)
}
}
@@ -240,7 +249,7 @@ where
P: Parser<I, O, E>,
I: Stream,
O: crate::stream::ParseSlice<O2>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
p: P,
i: core::marker::PhantomData<I>,
@@ -254,7 +263,7 @@ where
P: Parser<I, O, E>,
I: Stream,
O: crate::stream::ParseSlice<O2>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
pub(crate) fn new(p: P) -> Self {
Self {
@@ -272,17 +281,18 @@ where
P: Parser<I, O, E>,
I: Stream,
O: crate::stream::ParseSlice<O2>,
- E: ParseError<I>,
-{
- fn parse_next(&mut self, i: I) -> IResult<I, O2, E> {
- let input = i.clone();
- let (i, o) = self.p.parse_next(i)?;
-
- let res = o
- .parse_slice()
- .ok_or_else(|| ErrMode::from_error_kind(input, ErrorKind::Verify));
+ E: ParserError<I>,
+{
+ #[inline]
+ fn parse_next(&mut self, i: &mut I) -> PResult<O2, E> {
+ let start = i.checkpoint();
+ let o = self.p.parse_next(i)?;
+ let res = o.parse_slice().ok_or_else(|| {
+ i.reset(start);
+ ErrMode::from_error_kind(i, ErrorKind::Verify)
+ });
trace_result("verify", &res);
- Ok((i, res?))
+ res
}
}
@@ -328,8 +338,9 @@ where
G: FnMut(O) -> H,
H: Parser<I, O2, E>,
{
- fn parse_next(&mut self, i: I) -> IResult<I, O2, E> {
- let (i, o) = self.f.parse_next(i)?;
+ #[inline(always)]
+ fn parse_next(&mut self, i: &mut I) -> PResult<O2, E> {
+ let o = self.f.parse_next(i)?;
(self.g)(o).parse_next(i)
}
}
@@ -350,14 +361,14 @@ impl<F, I, O, E> Parser<I, O, E> for CompleteErr<F>
where
I: Stream,
F: Parser<I, O, E>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
- fn parse_next(&mut self, input: I) -> IResult<I, O, E> {
- trace("complete_err", |input: I| {
- let i = input.clone();
+ #[inline]
+ fn parse_next(&mut self, input: &mut I) -> PResult<O, E> {
+ trace("complete_err", |input: &mut I| {
match (self.f).parse_next(input) {
Err(ErrMode::Incomplete(_)) => {
- Err(ErrMode::from_error_kind(i, ErrorKind::Complete))
+ Err(ErrMode::from_error_kind(input, ErrorKind::Complete))
}
rest => rest,
}
@@ -372,10 +383,10 @@ pub struct Verify<F, G, I, O, O2, E>
where
F: Parser<I, O, E>,
G: Fn(&O2) -> bool,
- I: Clone,
+ I: Stream,
O: Borrow<O2>,
O2: ?Sized,
- E: ParseError<I>,
+ E: ParserError<I>,
{
parser: F,
filter: G,
@@ -389,10 +400,10 @@ impl<F, G, I, O, O2, E> Verify<F, G, I, O, O2, E>
where
F: Parser<I, O, E>,
G: Fn(&O2) -> bool,
- I: Clone,
+ I: Stream,
O: Borrow<O2>,
O2: ?Sized,
- E: ParseError<I>,
+ E: ParserError<I>,
{
pub(crate) fn new(parser: F, filter: G) -> Self {
Self {
@@ -410,20 +421,19 @@ impl<F, G, I, O, O2, E> Parser<I, O, E> for Verify<F, G, I, O, O2, E>
where
F: Parser<I, O, E>,
G: Fn(&O2) -> bool,
- I: Clone,
+ I: Stream,
O: Borrow<O2>,
O2: ?Sized,
- E: ParseError<I>,
-{
- fn parse_next(&mut self, input: I) -> IResult<I, O, E> {
- let i = input.clone();
- let (input, o) = self.parser.parse_next(input)?;
-
- let res = if (self.filter)(o.borrow()) {
- Ok((input, o))
- } else {
- Err(ErrMode::from_error_kind(i, ErrorKind::Verify))
- };
+ E: ParserError<I>,
+{
+ #[inline]
+ fn parse_next(&mut self, input: &mut I) -> PResult<O, E> {
+ let start = input.checkpoint();
+ let o = self.parser.parse_next(input)?;
+ let res = (self.filter)(o.borrow()).then_some(o).ok_or_else(|| {
+ input.reset(start);
+ ErrMode::from_error_kind(input, ErrorKind::Verify)
+ });
trace_result("verify", &res);
res
}
@@ -464,10 +474,9 @@ where
F: Parser<I, O, E>,
O2: Clone,
{
- fn parse_next(&mut self, input: I) -> IResult<I, O2, E> {
- (self.parser)
- .parse_next(input)
- .map(|(i, _)| (i, self.val.clone()))
+ #[inline]
+ fn parse_next(&mut self, input: &mut I) -> PResult<O2, E> {
+ (self.parser).parse_next(input).map(|_| self.val.clone())
}
}
@@ -501,8 +510,9 @@ impl<F, I, O, E> Parser<I, (), E> for Void<F, I, O, E>
where
F: Parser<I, O, E>,
{
- fn parse_next(&mut self, input: I) -> IResult<I, (), E> {
- (self.parser).parse_next(input).map(|(i, _)| (i, ()))
+ #[inline(always)]
+ fn parse_next(&mut self, input: &mut I) -> PResult<(), E> {
+ (self.parser).parse_next(input).map(|_| ())
}
}
@@ -511,7 +521,7 @@ where
pub struct Recognize<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Stream + Offset,
+ I: Stream,
{
parser: F,
i: core::marker::PhantomData<I>,
@@ -522,7 +532,7 @@ where
impl<F, I, O, E> Recognize<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Stream + Offset,
+ I: Stream,
{
pub(crate) fn new(parser: F) -> Self {
Self {
@@ -537,14 +547,17 @@ where
impl<I, O, E, F> Parser<I, <I as Stream>::Slice, E> for Recognize<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Stream + Offset,
+ I: Stream,
{
- fn parse_next(&mut self, input: I) -> IResult<I, <I as Stream>::Slice, E> {
- let i = input.clone();
- match (self.parser).parse_next(i) {
- Ok((i, _)) => {
- let offset = input.offset_to(&i);
- Ok(input.next_slice(offset))
+ #[inline]
+ fn parse_next(&mut self, input: &mut I) -> PResult<<I as Stream>::Slice, E> {
+ let checkpoint = input.checkpoint();
+ match (self.parser).parse_next(input) {
+ Ok(_) => {
+ let offset = input.offset_from(&checkpoint);
+ input.reset(checkpoint);
+ let recognized = input.next_slice(offset);
+ Ok(recognized)
}
Err(e) => Err(e),
}
@@ -556,7 +569,7 @@ where
pub struct WithRecognized<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Stream + Offset,
+ I: Stream,
{
parser: F,
i: core::marker::PhantomData<I>,
@@ -567,7 +580,7 @@ where
impl<F, I, O, E> WithRecognized<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Stream + Offset,
+ I: Stream,
{
pub(crate) fn new(parser: F) -> Self {
Self {
@@ -582,15 +595,17 @@ where
impl<F, I, O, E> Parser<I, (O, <I as Stream>::Slice), E> for WithRecognized<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Stream + Offset,
+ I: Stream,
{
- fn parse_next(&mut self, input: I) -> IResult<I, (O, <I as Stream>::Slice), E> {
- let i = input.clone();
- match (self.parser).parse_next(i) {
- Ok((remaining, result)) => {
- let offset = input.offset_to(&remaining);
- let (remaining, recognized) = input.next_slice(offset);
- Ok((remaining, (result, recognized)))
+ #[inline]
+ fn parse_next(&mut self, input: &mut I) -> PResult<(O, <I as Stream>::Slice), E> {
+ let checkpoint = input.checkpoint();
+ match (self.parser).parse_next(input) {
+ Ok(result) => {
+ let offset = input.offset_from(&checkpoint);
+ input.reset(checkpoint);
+ let recognized = input.next_slice(offset);
+ Ok((result, recognized))
}
Err(e) => Err(e),
}
@@ -602,7 +617,7 @@ where
pub struct Span<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Clone + Location,
+ I: Stream + Location,
{
parser: F,
i: core::marker::PhantomData<I>,
@@ -613,7 +628,7 @@ where
impl<F, I, O, E> Span<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Clone + Location,
+ I: Stream + Location,
{
pub(crate) fn new(parser: F) -> Self {
Self {
@@ -628,13 +643,14 @@ where
impl<I, O, E, F> Parser<I, Range<usize>, E> for Span<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Clone + Location,
+ I: Stream + Location,
{
- fn parse_next(&mut self, input: I) -> IResult<I, Range<usize>, E> {
+ #[inline]
+ fn parse_next(&mut self, input: &mut I) -> PResult<Range<usize>, E> {
let start = input.location();
- self.parser.parse_next(input).map(move |(remaining, _)| {
- let end = remaining.location();
- (remaining, (start..end))
+ self.parser.parse_next(input).map(move |_| {
+ let end = input.location();
+ start..end
})
}
}
@@ -644,7 +660,7 @@ where
pub struct WithSpan<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Clone + Location,
+ I: Stream + Location,
{
parser: F,
i: core::marker::PhantomData<I>,
@@ -655,7 +671,7 @@ where
impl<F, I, O, E> WithSpan<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Clone + Location,
+ I: Stream + Location,
{
pub(crate) fn new(parser: F) -> Self {
Self {
@@ -670,16 +686,15 @@ where
impl<F, I, O, E> Parser<I, (O, Range<usize>), E> for WithSpan<F, I, O, E>
where
F: Parser<I, O, E>,
- I: Clone + Location,
+ I: Stream + Location,
{
- fn parse_next(&mut self, input: I) -> IResult<I, (O, Range<usize>), E> {
+ #[inline]
+ fn parse_next(&mut self, input: &mut I) -> PResult<(O, Range<usize>), E> {
let start = input.location();
- self.parser
- .parse_next(input)
- .map(move |(remaining, output)| {
- let end = remaining.location();
- (remaining, (output, (start..end)))
- })
+ self.parser.parse_next(input).map(move |output| {
+ let end = input.location();
+ (output, (start..end))
+ })
}
}
@@ -718,11 +733,9 @@ where
F: Parser<I, O, E>,
O: Into<O2>,
{
- fn parse_next(&mut self, i: I) -> IResult<I, O2, E> {
- match self.parser.parse_next(i) {
- Ok((i, o)) => Ok((i, o.into())),
- Err(err) => Err(err),
- }
+ #[inline]
+ fn parse_next(&mut self, i: &mut I) -> PResult<O2, E> {
+ self.parser.parse_next(i).map(|o| o.into())
}
}
@@ -761,7 +774,8 @@ where
F: Parser<I, O, E>,
E: Into<E2>,
{
- fn parse_next(&mut self, i: I) -> IResult<I, O, E2> {
+ #[inline]
+ fn parse_next(&mut self, i: &mut I) -> PResult<O, E2> {
match self.parser.parse_next(i) {
Ok(ok) => Ok(ok),
Err(ErrMode::Backtrack(e)) => Err(ErrMode::Backtrack(e.into())),
@@ -777,7 +791,7 @@ pub struct Context<F, I, O, E, C>
where
F: Parser<I, O, E>,
I: Stream,
- E: ContextError<I, C>,
+ E: AddContext<I, C>,
C: Clone + crate::lib::std::fmt::Debug,
{
parser: F,
@@ -791,7 +805,7 @@ impl<F, I, O, E, C> Context<F, I, O, E, C>
where
F: Parser<I, O, E>,
I: Stream,
- E: ContextError<I, C>,
+ E: AddContext<I, C>,
C: Clone + crate::lib::std::fmt::Debug,
{
pub(crate) fn new(parser: F, context: C) -> Self {
@@ -809,17 +823,18 @@ impl<F, I, O, E, C> Parser<I, O, E> for Context<F, I, O, E, C>
where
F: Parser<I, O, E>,
I: Stream,
- E: ContextError<I, C>,
+ E: AddContext<I, C>,
C: Clone + crate::lib::std::fmt::Debug,
{
- fn parse_next(&mut self, i: I) -> IResult<I, O, E> {
+ #[inline]
+ fn parse_next(&mut self, i: &mut I) -> PResult<O, E> {
#[cfg(feature = "debug")]
let name = format!("context={:?}", self.context);
#[cfg(not(feature = "debug"))]
let name = "context";
- trace(name, move |i: I| {
+ trace(name, move |i: &mut I| {
(self.parser)
- .parse_next(i.clone())
+ .parse_next(i)
.map_err(|err| err.map(|err| err.add_context(i, self.context.clone())))
})
.parse_next(i)
diff --git a/vendor/winnow/src/combinator/sequence.rs b/vendor/winnow/src/combinator/sequence.rs
index 89c29a548..5cfeb9cb4 100644
--- a/vendor/winnow/src/combinator/sequence.rs
+++ b/vendor/winnow/src/combinator/sequence.rs
@@ -1,4 +1,4 @@
-use crate::error::ParseError;
+use crate::error::ParserError;
use crate::stream::Stream;
use crate::trace::trace;
use crate::*;
@@ -12,7 +12,7 @@ use crate::*;
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::combinator::preceded;
@@ -20,13 +20,13 @@ use crate::*;
///
/// let mut parser = preceded("abc", "efg");
///
-/// assert_eq!(parser.parse_next("abcefg"), Ok(("", "efg")));
-/// assert_eq!(parser.parse_next("abcefghij"), Ok(("hij", "efg")));
-/// assert_eq!(parser.parse_next(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
-/// assert_eq!(parser.parse_next("123"), Err(ErrMode::Backtrack(Error::new("123", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("abcefg"), Ok(("", "efg")));
+/// assert_eq!(parser.parse_peek("abcefghij"), Ok(("hij", "efg")));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("123"), Err(ErrMode::Backtrack(InputError::new("123", ErrorKind::Tag))));
/// ```
#[doc(alias = "ignore_then")]
-pub fn preceded<I, O1, O2, E: ParseError<I>, F, G>(
+pub fn preceded<I, O1, O2, E: ParserError<I>, F, G>(
mut first: F,
mut second: G,
) -> impl Parser<I, O2, E>
@@ -35,8 +35,8 @@ where
F: Parser<I, O1, E>,
G: Parser<I, O2, E>,
{
- trace("preceded", move |input: I| {
- let (input, _) = first.parse_next(input)?;
+ trace("preceded", move |input: &mut I| {
+ let _ = first.parse_next(input)?;
second.parse_next(input)
})
}
@@ -50,7 +50,7 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::error::Needed::Size;
/// use winnow::combinator::terminated;
@@ -58,13 +58,13 @@ where
///
/// let mut parser = terminated("abc", "efg");
///
-/// assert_eq!(parser.parse_next("abcefg"), Ok(("", "abc")));
-/// assert_eq!(parser.parse_next("abcefghij"), Ok(("hij", "abc")));
-/// assert_eq!(parser.parse_next(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
-/// assert_eq!(parser.parse_next("123"), Err(ErrMode::Backtrack(Error::new("123", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("abcefg"), Ok(("", "abc")));
+/// assert_eq!(parser.parse_peek("abcefghij"), Ok(("hij", "abc")));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("123"), Err(ErrMode::Backtrack(InputError::new("123", ErrorKind::Tag))));
/// ```
#[doc(alias = "then_ignore")]
-pub fn terminated<I, O1, O2, E: ParseError<I>, F, G>(
+pub fn terminated<I, O1, O2, E: ParserError<I>, F, G>(
mut first: F,
mut second: G,
) -> impl Parser<I, O1, E>
@@ -73,9 +73,9 @@ where
F: Parser<I, O1, E>,
G: Parser<I, O2, E>,
{
- trace("terminated", move |input: I| {
- let (input, o1) = first.parse_next(input)?;
- second.parse_next(input).map(|(i, _)| (i, o1))
+ trace("terminated", move |input: &mut I| {
+ let o1 = first.parse_next(input)?;
+ second.parse_next(input).map(|_| o1)
})
}
@@ -89,7 +89,7 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::error::Needed::Size;
/// # use winnow::prelude::*;
/// use winnow::combinator::separated_pair;
@@ -97,12 +97,12 @@ where
///
/// let mut parser = separated_pair("abc", "|", "efg");
///
-/// assert_eq!(parser.parse_next("abc|efg"), Ok(("", ("abc", "efg"))));
-/// assert_eq!(parser.parse_next("abc|efghij"), Ok(("hij", ("abc", "efg"))));
-/// assert_eq!(parser.parse_next(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
-/// assert_eq!(parser.parse_next("123"), Err(ErrMode::Backtrack(Error::new("123", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("abc|efg"), Ok(("", ("abc", "efg"))));
+/// assert_eq!(parser.parse_peek("abc|efghij"), Ok(("hij", ("abc", "efg"))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("123"), Err(ErrMode::Backtrack(InputError::new("123", ErrorKind::Tag))));
/// ```
-pub fn separated_pair<I, O1, O2, O3, E: ParseError<I>, F, G, H>(
+pub fn separated_pair<I, O1, O2, O3, E: ParserError<I>, F, G, H>(
mut first: F,
mut sep: G,
mut second: H,
@@ -113,10 +113,10 @@ where
G: Parser<I, O2, E>,
H: Parser<I, O3, E>,
{
- trace("separated_pair", move |input: I| {
- let (input, o1) = first.parse_next(input)?;
- let (input, _) = sep.parse_next(input)?;
- second.parse_next(input).map(|(i, o2)| (i, (o1, o2)))
+ trace("separated_pair", move |input: &mut I| {
+ let o1 = first.parse_next(input)?;
+ let _ = sep.parse_next(input)?;
+ second.parse_next(input).map(|o2| (o1, o2))
})
}
@@ -130,7 +130,7 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::error::Needed::Size;
/// # use winnow::prelude::*;
/// use winnow::combinator::delimited;
@@ -138,14 +138,14 @@ where
///
/// let mut parser = delimited("(", "abc", ")");
///
-/// assert_eq!(parser.parse_next("(abc)"), Ok(("", "abc")));
-/// assert_eq!(parser.parse_next("(abc)def"), Ok(("def", "abc")));
-/// assert_eq!(parser.parse_next(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
-/// assert_eq!(parser.parse_next("123"), Err(ErrMode::Backtrack(Error::new("123", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("(abc)"), Ok(("", "abc")));
+/// assert_eq!(parser.parse_peek("(abc)def"), Ok(("def", "abc")));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("123"), Err(ErrMode::Backtrack(InputError::new("123", ErrorKind::Tag))));
/// ```
#[doc(alias = "between")]
#[doc(alias = "padded")]
-pub fn delimited<I, O1, O2, O3, E: ParseError<I>, F, G, H>(
+pub fn delimited<I, O1, O2, O3, E: ParserError<I>, F, G, H>(
mut first: F,
mut second: G,
mut third: H,
@@ -156,9 +156,9 @@ where
G: Parser<I, O2, E>,
H: Parser<I, O3, E>,
{
- trace("delimited", move |input: I| {
- let (input, _) = first.parse_next(input)?;
- let (input, o2) = second.parse_next(input)?;
- third.parse_next(input).map(|(i, _)| (i, o2))
+ trace("delimited", move |input: &mut I| {
+ let _ = first.parse_next(input)?;
+ let o2 = second.parse_next(input)?;
+ third.parse_next(input).map(|_| o2)
})
}
diff --git a/vendor/winnow/src/combinator/tests.rs b/vendor/winnow/src/combinator/tests.rs
index cdb787760..62dc420e5 100644
--- a/vendor/winnow/src/combinator/tests.rs
+++ b/vendor/winnow/src/combinator/tests.rs
@@ -5,11 +5,13 @@ use crate::binary::u16;
use crate::binary::u8;
use crate::binary::Endianness;
use crate::error::ErrMode;
-use crate::error::Error;
use crate::error::ErrorKind;
+use crate::error::InputError;
use crate::error::Needed;
-use crate::error::ParseError;
+use crate::error::ParserError;
+use crate::stream::Stream;
use crate::token::take;
+use crate::unpeek;
use crate::IResult;
use crate::Parser;
use crate::Partial;
@@ -19,7 +21,7 @@ use crate::lib::std::vec::Vec;
macro_rules! assert_parse(
($left: expr, $right: expr) => {
- let res: $crate::IResult<_, _, Error<_>> = $left;
+ let res: $crate::IResult<_, _, InputError<_>> = $left;
assert_eq!(res, $right);
};
);
@@ -29,16 +31,16 @@ fn eof_on_slices() {
let not_over: &[u8] = &b"Hello, world!"[..];
let is_over: &[u8] = &b""[..];
- let res_not_over = eof(not_over);
+ let res_not_over = eof.parse_peek(not_over);
assert_parse!(
res_not_over,
Err(ErrMode::Backtrack(error_position!(
- not_over,
+ &not_over,
ErrorKind::Eof
)))
);
- let res_over = eof(is_over);
+ let res_over = eof.parse_peek(is_over);
assert_parse!(res_over, Ok((is_over, is_over)));
}
@@ -47,16 +49,16 @@ fn eof_on_strs() {
let not_over: &str = "Hello, world!";
let is_over: &str = "";
- let res_not_over = eof(not_over);
+ let res_not_over = eof.parse_peek(not_over);
assert_parse!(
res_not_over,
Err(ErrMode::Backtrack(error_position!(
- not_over,
+ &not_over,
ErrorKind::Eof
)))
);
- let res_over = eof(is_over);
+ let res_over = eof.parse_peek(is_over);
assert_parse!(res_over, Ok((is_over, is_over)));
}
@@ -64,20 +66,20 @@ fn eof_on_strs() {
fn rest_on_slices() {
let input: &[u8] = &b"Hello, world!"[..];
let empty: &[u8] = &b""[..];
- assert_parse!(rest(input), Ok((empty, input)));
+ assert_parse!(rest.parse_peek(input), Ok((empty, input)));
}
#[test]
fn rest_on_strs() {
let input: &str = "Hello, world!";
let empty: &str = "";
- assert_parse!(rest(input), Ok((empty, input)));
+ assert_parse!(rest.parse_peek(input), Ok((empty, input)));
}
#[test]
fn rest_len_on_slices() {
let input: &[u8] = &b"Hello, world!"[..];
- assert_parse!(rest_len(input), Ok((input, input.len())));
+ assert_parse!(rest_len.parse_peek(input), Ok((input, input.len())));
}
use crate::lib::std::convert::From;
@@ -87,12 +89,12 @@ impl From<u32> for CustomError {
}
}
-impl<I> ParseError<I> for CustomError {
- fn from_error_kind(_: I, _: ErrorKind) -> Self {
+impl<I> ParserError<I> for CustomError {
+ fn from_error_kind(_: &I, _: ErrorKind) -> Self {
CustomError
}
- fn append(self, _: I, _: ErrorKind) -> Self {
+ fn append(self, _: &I, _: ErrorKind) -> Self {
CustomError
}
}
@@ -101,14 +103,14 @@ struct CustomError;
#[allow(dead_code)]
fn custom_error(input: &[u8]) -> IResult<&[u8], &[u8], CustomError> {
//fix_error!(input, CustomError<_>, alphanumeric)
- crate::ascii::alphanumeric1(input)
+ crate::ascii::alphanumeric1.parse_peek(input)
}
#[test]
fn test_parser_flat_map() {
let input: &[u8] = &[3, 100, 101, 102, 103, 104][..];
assert_parse!(
- u8.flat_map(take).parse_next(input),
+ u8.flat_map(take).parse_peek(input),
Ok((&[103, 104][..], &[100, 101, 102][..]))
);
}
@@ -116,7 +118,7 @@ fn test_parser_flat_map() {
#[allow(dead_code)]
fn test_closure_compiles_195(input: &[u8]) -> IResult<&[u8], ()> {
u8.flat_map(|num| repeat(num as usize, u16(Endianness::Big)))
- .parse_next(input)
+ .parse_peek(input)
}
#[test]
@@ -124,15 +126,15 @@ fn test_parser_verify_map() {
let input: &[u8] = &[50][..];
assert_parse!(
u8.verify_map(|u| if u < 20 { Some(u) } else { None })
- .parse_next(input),
- Err(ErrMode::Backtrack(Error {
- input: &[50][..],
- kind: ErrorKind::Verify
- }))
+ .parse_peek(input),
+ Err(ErrMode::Backtrack(InputError::new(
+ &[50][..],
+ ErrorKind::Verify
+ )))
);
assert_parse!(
u8.verify_map(|u| if u > 20 { Some(u) } else { None })
- .parse_next(input),
+ .parse_peek(input),
Ok((&[][..], 50))
);
}
@@ -141,7 +143,7 @@ fn test_parser_verify_map() {
fn test_parser_map_parser() {
let input: &[u8] = &[100, 101, 102, 103, 104][..];
assert_parse!(
- take(4usize).and_then(take(2usize)).parse_next(input),
+ take(4usize).and_then(take(2usize)).parse_peek(input),
Ok((&[104][..], &[100, 101][..]))
);
}
@@ -149,11 +151,11 @@ fn test_parser_map_parser() {
#[test]
#[cfg(feature = "std")]
fn test_parser_into() {
- use crate::error::Error;
+ use crate::error::InputError;
use crate::token::take;
- let mut parser = take::<_, _, Error<_>>(3u8).output_into();
- let result: IResult<&[u8], Vec<u8>> = parser.parse_next(&b"abcdefg"[..]);
+ let mut parser = take::<_, _, InputError<_>>(3u8).output_into();
+ let result: IResult<&[u8], Vec<u8>> = parser.parse_peek(&b"abcdefg"[..]);
assert_eq!(result, Ok((&b"defg"[..], vec![97, 98, 99])));
}
@@ -161,7 +163,7 @@ fn test_parser_into() {
#[test]
fn opt_test() {
fn opt_abcd(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Option<&[u8]>> {
- opt("abcd").parse_next(i)
+ opt("abcd").parse_peek(i)
}
let a = &b"abcdef"[..];
@@ -184,7 +186,7 @@ fn opt_test() {
#[test]
fn peek_test() {
fn peek_tag(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- peek("abcd").parse_next(i)
+ peek("abcd").parse_peek(i)
}
assert_eq!(
@@ -198,7 +200,7 @@ fn peek_test() {
assert_eq!(
peek_tag(Partial::new(&b"xxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Tag
)))
);
@@ -207,13 +209,13 @@ fn peek_test() {
#[test]
fn not_test() {
fn not_aaa(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, ()> {
- not("aaa").parse_next(i)
+ not("aaa").parse_peek(i)
}
assert_eq!(
not_aaa(Partial::new(&b"aaa"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"aaa"[..]),
+ &Partial::new(&b"aaa"[..]),
ErrorKind::Not
)))
);
@@ -234,7 +236,7 @@ fn test_parser_verify() {
fn test(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
take(5u8)
.verify(|slice: &[u8]| slice[0] == b'a')
- .parse_next(i)
+ .parse_peek(i)
}
assert_eq!(
test(Partial::new(&b"bcd"[..])),
@@ -243,7 +245,7 @@ fn test_parser_verify() {
assert_eq!(
test(Partial::new(&b"bcdefg"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"bcdefg"[..]),
+ &Partial::new(&b"bcdefg"[..]),
ErrorKind::Verify
)))
);
@@ -261,21 +263,21 @@ fn test_parser_verify_ref() {
let mut parser1 = take(3u8).verify(|s: &[u8]| s == &b"abc"[..]);
assert_eq!(
- parser1.parse_next(&b"abcd"[..]),
+ parser1.parse_peek(&b"abcd"[..]),
Ok((&b"d"[..], &b"abc"[..]))
);
assert_eq!(
- parser1.parse_next(&b"defg"[..]),
- Err(ErrMode::Backtrack(Error {
- input: &b"defg"[..],
- kind: ErrorKind::Verify
- }))
+ parser1.parse_peek(&b"defg"[..]),
+ Err(ErrMode::Backtrack(InputError::new(
+ &b"defg"[..],
+ ErrorKind::Verify
+ )))
);
fn parser2(i: &[u8]) -> IResult<&[u8], u32> {
crate::binary::be_u32
.verify(|val: &u32| *val < 3)
- .parse_next(i)
+ .parse_peek(i)
}
}
@@ -288,15 +290,15 @@ fn test_parser_verify_alloc() {
.verify(|s: &[u8]| s == &b"abc"[..]);
assert_eq!(
- parser1.parse_next(&b"abcd"[..]),
+ parser1.parse_peek(&b"abcd"[..]),
Ok((&b"d"[..], b"abc".to_vec()))
);
assert_eq!(
- parser1.parse_next(&b"defg"[..]),
- Err(ErrMode::Backtrack(Error {
- input: &b"defg"[..],
- kind: ErrorKind::Verify
- }))
+ parser1.parse_peek(&b"defg"[..]),
+ Err(ErrMode::Backtrack(InputError::new(
+ &b"defg"[..],
+ ErrorKind::Verify
+ )))
);
}
@@ -306,26 +308,20 @@ fn fail_test() {
let b = "another string";
assert_eq!(
- fail::<_, &str, _>(a),
- Err(ErrMode::Backtrack(Error {
- input: a,
- kind: ErrorKind::Fail
- }))
+ fail::<_, &str, _>.parse_peek(a),
+ Err(ErrMode::Backtrack(InputError::new(a, ErrorKind::Fail)))
);
assert_eq!(
- fail::<_, &str, _>(b),
- Err(ErrMode::Backtrack(Error {
- input: b,
- kind: ErrorKind::Fail
- }))
+ fail::<_, &str, _>.parse_peek(b),
+ Err(ErrMode::Backtrack(InputError::new(b, ErrorKind::Fail)))
);
}
#[test]
fn complete() {
fn err_test(i: &[u8]) -> IResult<&[u8], &[u8]> {
- let (i, _) = "ijkl".parse_next(i)?;
- "mnop".parse_next(i)
+ let (i, _) = "ijkl".parse_peek(i)?;
+ "mnop".parse_peek(i)
}
let a = &b"ijklmn"[..];
@@ -333,7 +329,7 @@ fn complete() {
assert_eq!(
res_a,
Err(ErrMode::Backtrack(error_position!(
- &b"mn"[..],
+ &&b"mn"[..],
ErrorKind::Tag
)))
);
@@ -343,7 +339,7 @@ fn complete() {
fn separated_pair_test() {
#[allow(clippy::type_complexity)]
fn sep_pair_abc_def(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, (&[u8], &[u8])> {
- separated_pair("abc", ",", "def").parse_next(i)
+ separated_pair("abc", ",", "def").parse_peek(i)
}
assert_eq!(
@@ -361,21 +357,21 @@ fn separated_pair_test() {
assert_eq!(
sep_pair_abc_def(Partial::new(&b"xxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
sep_pair_abc_def(Partial::new(&b"xxx,def"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx,def"[..]),
+ &Partial::new(&b"xxx,def"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
sep_pair_abc_def(Partial::new(&b"abc,xxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Tag
)))
);
@@ -384,7 +380,7 @@ fn separated_pair_test() {
#[test]
fn preceded_test() {
fn preceded_abcd_efgh(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- preceded("abcd", "efgh").parse_next(i)
+ preceded("abcd", "efgh").parse_peek(i)
}
assert_eq!(
@@ -402,21 +398,21 @@ fn preceded_test() {
assert_eq!(
preceded_abcd_efgh(Partial::new(&b"xxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
preceded_abcd_efgh(Partial::new(&b"xxxxdef"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxxxdef"[..]),
+ &Partial::new(&b"xxxxdef"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
preceded_abcd_efgh(Partial::new(&b"abcdxxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Tag
)))
);
@@ -425,7 +421,7 @@ fn preceded_test() {
#[test]
fn terminated_test() {
fn terminated_abcd_efgh(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- terminated("abcd", "efgh").parse_next(i)
+ terminated("abcd", "efgh").parse_peek(i)
}
assert_eq!(
@@ -443,21 +439,21 @@ fn terminated_test() {
assert_eq!(
terminated_abcd_efgh(Partial::new(&b"xxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
terminated_abcd_efgh(Partial::new(&b"xxxxdef"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxxxdef"[..]),
+ &Partial::new(&b"xxxxdef"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
terminated_abcd_efgh(Partial::new(&b"abcdxxxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxxx"[..]),
+ &Partial::new(&b"xxxx"[..]),
ErrorKind::Tag
)))
);
@@ -466,7 +462,7 @@ fn terminated_test() {
#[test]
fn delimited_test() {
fn delimited_abc_def_ghi(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- delimited("abc", "def", "ghi").parse_next(i)
+ delimited("abc", "def", "ghi").parse_peek(i)
}
assert_eq!(
@@ -488,28 +484,28 @@ fn delimited_test() {
assert_eq!(
delimited_abc_def_ghi(Partial::new(&b"xxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
delimited_abc_def_ghi(Partial::new(&b"xxxdefghi"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxxdefghi"[..]),
+ &Partial::new(&b"xxxdefghi"[..]),
ErrorKind::Tag
),))
);
assert_eq!(
delimited_abc_def_ghi(Partial::new(&b"abcxxxghi"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxxghi"[..]),
+ &Partial::new(&b"xxxghi"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
delimited_abc_def_ghi(Partial::new(&b"abcdefxxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Tag
)))
);
@@ -520,7 +516,7 @@ fn delimited_test() {
fn alt_test() {
#[cfg(feature = "alloc")]
use crate::{
- error::ParseError,
+ error::ParserError,
lib::std::{
fmt::Debug,
string::{String, ToString},
@@ -546,12 +542,12 @@ fn alt_test() {
}
#[cfg(feature = "alloc")]
- impl<I: Debug> ParseError<I> for ErrorStr {
- fn from_error_kind(input: I, kind: ErrorKind) -> Self {
+ impl<I: Debug> ParserError<I> for ErrorStr {
+ fn from_error_kind(input: &I, kind: ErrorKind) -> Self {
ErrorStr(format!("custom error message: ({:?}, {:?})", input, kind))
}
- fn append(self, input: I, kind: ErrorKind) -> Self {
+ fn append(self, input: &I, kind: ErrorKind) -> Self {
ErrorStr(format!(
"custom error message: ({:?}, {:?}) - {:?}",
input, kind, self
@@ -560,7 +556,7 @@ fn alt_test() {
}
fn work(input: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
- Ok((&b""[..], input))
+ Ok(input.peek_finish())
}
#[allow(unused_variables)]
@@ -573,13 +569,19 @@ fn alt_test() {
}
fn alt1(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
- alt((dont_work, dont_work)).parse_next(i)
+ alt((unpeek(dont_work), unpeek(dont_work))).parse_peek(i)
}
fn alt2(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
- alt((dont_work, work)).parse_next(i)
+ alt((unpeek(dont_work), unpeek(work))).parse_peek(i)
}
fn alt3(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
- alt((dont_work, dont_work, work2, dont_work)).parse_next(i)
+ alt((
+ unpeek(dont_work),
+ unpeek(dont_work),
+ unpeek(work2),
+ unpeek(dont_work),
+ ))
+ .parse_peek(i)
}
//named!(alt1, alt!(dont_work | dont_work));
//named!(alt2, alt!(dont_work | work));
@@ -589,7 +591,7 @@ fn alt_test() {
assert_eq!(
alt1(a),
Err(ErrMode::Backtrack(error_node_position!(
- a,
+ &a,
ErrorKind::Alt,
ErrorStr("abcd".to_string())
)))
@@ -598,7 +600,7 @@ fn alt_test() {
assert_eq!(alt3(a), Ok((a, &b""[..])));
fn alt4(i: &[u8]) -> IResult<&[u8], &[u8]> {
- alt(("abcd", "efgh")).parse_next(i)
+ alt(("abcd", "efgh")).parse_peek(i)
}
let b = &b"efgh"[..];
assert_eq!(alt4(a), Ok((&b""[..], a)));
@@ -608,7 +610,7 @@ fn alt_test() {
#[test]
fn alt_incomplete() {
fn alt1(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- alt(("a", "bc", "def")).parse_next(i)
+ alt(("a", "bc", "def")).parse_peek(i)
}
let a = &b""[..];
@@ -630,7 +632,7 @@ fn alt_incomplete() {
assert_eq!(
alt1(Partial::new(a)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(a),
+ &Partial::new(a),
ErrorKind::Tag
)))
);
@@ -650,7 +652,7 @@ fn alt_incomplete() {
fn permutation_test() {
#[allow(clippy::type_complexity)]
fn perm(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, (&[u8], &[u8], &[u8])> {
- permutation(("abcd", "efg", "hi")).parse_next(i)
+ permutation(("abcd", "efg", "hi")).parse_peek(i)
}
let expected = (&b"abcd"[..], &b"efg"[..], &b"hi"[..]);
@@ -675,9 +677,9 @@ fn permutation_test() {
assert_eq!(
perm(Partial::new(d)),
Err(ErrMode::Backtrack(error_node_position!(
- Partial::new(&b"efgxyzabcdefghi"[..]),
+ &Partial::new(&b"efgxyzabcdefghi"[..]),
ErrorKind::Alt,
- error_position!(Partial::new(&b"xyzabcdefghi"[..]), ErrorKind::Tag)
+ error_position!(&Partial::new(&b"xyzabcdefghi"[..]), ErrorKind::Tag)
)))
);
@@ -692,13 +694,13 @@ fn permutation_test() {
#[cfg(feature = "alloc")]
fn separated0_test() {
fn multi(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- separated0("abcd", ",").parse_next(i)
+ separated0("abcd", ",").parse_peek(i)
}
fn multi_empty(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- separated0("", ",").parse_next(i)
+ separated0("", ",").parse_peek(i)
}
fn multi_longsep(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- separated0("abcd", "..").parse_next(i)
+ separated0("abcd", "..").parse_peek(i)
}
let a = &b"abcdef"[..];
@@ -748,7 +750,7 @@ fn separated0_test() {
#[cfg_attr(debug_assertions, should_panic)]
fn separated0_empty_sep_test() {
fn empty_sep(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- separated0("abc", "").parse_next(i)
+ separated0("abc", "").parse_peek(i)
}
let i = &b"abcabc"[..];
@@ -757,7 +759,7 @@ fn separated0_empty_sep_test() {
assert_eq!(
empty_sep(Partial::new(i)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(i_err_pos),
+ &Partial::new(i_err_pos),
ErrorKind::Assert
)))
);
@@ -767,10 +769,10 @@ fn separated0_empty_sep_test() {
#[cfg(feature = "alloc")]
fn separated1_test() {
fn multi(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- separated1("abcd", ",").parse_next(i)
+ separated1("abcd", ",").parse_peek(i)
}
fn multi_longsep(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- separated1("abcd", "..").parse_next(i)
+ separated1("abcd", "..").parse_peek(i)
}
let a = &b"abcdef"[..];
@@ -789,7 +791,7 @@ fn separated1_test() {
assert_eq!(
multi(Partial::new(c)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(c),
+ &Partial::new(c),
ErrorKind::Tag
)))
);
@@ -817,7 +819,7 @@ fn separated1_test() {
#[cfg(feature = "alloc")]
fn repeat0_test() {
fn multi(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- repeat(0.., "abcd").parse_next(i)
+ repeat(0.., "abcd").parse_peek(i)
}
assert_eq!(
@@ -851,13 +853,13 @@ fn repeat0_test() {
#[cfg_attr(debug_assertions, should_panic)]
fn repeat0_empty_test() {
fn multi_empty(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- repeat(0.., "").parse_next(i)
+ repeat(0.., "").parse_peek(i)
}
assert_eq!(
multi_empty(Partial::new(&b"abcdef"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"abcdef"[..]),
+ &Partial::new(&b"abcdef"[..]),
ErrorKind::Assert
)))
);
@@ -867,7 +869,7 @@ fn repeat0_empty_test() {
#[cfg(feature = "alloc")]
fn repeat1_test() {
fn multi(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- repeat(1.., "abcd").parse_next(i)
+ repeat(1.., "abcd").parse_peek(i)
}
let a = &b"abcdef"[..];
@@ -885,7 +887,7 @@ fn repeat1_test() {
assert_eq!(
multi(Partial::new(c)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(c),
+ &Partial::new(c),
ErrorKind::Tag
)))
);
@@ -900,7 +902,7 @@ fn repeat1_test() {
fn repeat_till_test() {
#[allow(clippy::type_complexity)]
fn multi(i: &[u8]) -> IResult<&[u8], (Vec<&[u8]>, &[u8])> {
- repeat_till0("abcd", "efgh").parse_next(i)
+ repeat_till0("abcd", "efgh").parse_peek(i)
}
let a = b"abcdabcdefghabcd";
@@ -914,9 +916,9 @@ fn repeat_till_test() {
assert_eq!(
multi(&c[..]),
Err(ErrMode::Backtrack(error_node_position!(
- &c[..],
+ &&c[..],
ErrorKind::Many,
- error_position!(&c[..], ErrorKind::Tag)
+ error_position!(&&c[..], ErrorKind::Tag)
)))
);
}
@@ -926,23 +928,23 @@ fn repeat_till_test() {
fn infinite_many() {
fn tst(input: &[u8]) -> IResult<&[u8], &[u8]> {
println!("input: {:?}", input);
- Err(ErrMode::Backtrack(error_position!(input, ErrorKind::Tag)))
+ Err(ErrMode::Backtrack(error_position!(&input, ErrorKind::Tag)))
}
// should not go into an infinite loop
fn multi0(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
- repeat(0.., tst).parse_next(i)
+ repeat(0.., unpeek(tst)).parse_peek(i)
}
let a = &b"abcdef"[..];
assert_eq!(multi0(a), Ok((a, Vec::new())));
fn multi1(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
- repeat(1.., tst).parse_next(i)
+ repeat(1.., unpeek(tst)).parse_peek(i)
}
let a = &b"abcdef"[..];
assert_eq!(
multi1(a),
- Err(ErrMode::Backtrack(error_position!(a, ErrorKind::Tag)))
+ Err(ErrMode::Backtrack(error_position!(&a, ErrorKind::Tag)))
);
}
@@ -950,7 +952,7 @@ fn infinite_many() {
#[cfg(feature = "alloc")]
fn repeat_test() {
fn multi(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- repeat(2..=4, "Abcd").parse_next(i)
+ repeat(2..=4, "Abcd").parse_peek(i)
}
let a = &b"Abcdef"[..];
@@ -962,7 +964,7 @@ fn repeat_test() {
assert_eq!(
multi(Partial::new(a)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"ef"[..]),
+ &Partial::new(&b"ef"[..]),
ErrorKind::Tag
)))
);
@@ -992,7 +994,7 @@ fn repeat_test() {
fn count_test() {
const TIMES: usize = 2;
fn cnt_2(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- repeat(TIMES, "abc").parse_next(i)
+ repeat(TIMES, "abc").parse_peek(i)
}
assert_eq!(
@@ -1010,21 +1012,21 @@ fn count_test() {
assert_eq!(
cnt_2(Partial::new(&b"xxx"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxx"[..]),
+ &Partial::new(&b"xxx"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
cnt_2(Partial::new(&b"xxxabcabcdef"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxxabcabcdef"[..]),
+ &Partial::new(&b"xxxabcabcdef"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
cnt_2(Partial::new(&b"abcxxxabcdef"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"xxxabcdef"[..]),
+ &Partial::new(&b"xxxabcdef"[..]),
ErrorKind::Tag
)))
);
@@ -1035,7 +1037,7 @@ fn count_test() {
fn count_zero() {
const TIMES: usize = 0;
fn counter_2(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
- repeat(TIMES, "abc").parse_next(i)
+ repeat(TIMES, "abc").parse_peek(i)
}
let done = &b"abcabcabcdef"[..];
@@ -1078,11 +1080,11 @@ impl<I> From<(I, ErrorKind)> for NilError {
}
}
-impl<I> ParseError<I> for NilError {
- fn from_error_kind(_: I, _: ErrorKind) -> NilError {
+impl<I> ParserError<I> for NilError {
+ fn from_error_kind(_: &I, _: ErrorKind) -> NilError {
NilError
}
- fn append(self, _: I, _: ErrorKind) -> NilError {
+ fn append(self, _: &I, _: ErrorKind) -> NilError {
NilError
}
}
@@ -1095,7 +1097,7 @@ fn fold_repeat0_test() {
acc
}
fn multi(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- fold_repeat(0.., "abcd", Vec::new, fold_into_vec).parse_next(i)
+ fold_repeat(0.., "abcd", Vec::new, fold_into_vec).parse_peek(i)
}
assert_eq!(
@@ -1133,13 +1135,13 @@ fn fold_repeat0_empty_test() {
acc
}
fn multi_empty(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- fold_repeat(0.., "", Vec::new, fold_into_vec).parse_next(i)
+ fold_repeat(0.., "", Vec::new, fold_into_vec).parse_peek(i)
}
assert_eq!(
multi_empty(Partial::new(&b"abcdef"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"abcdef"[..]),
+ &Partial::new(&b"abcdef"[..]),
ErrorKind::Assert
)))
);
@@ -1153,7 +1155,7 @@ fn fold_repeat1_test() {
acc
}
fn multi(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- fold_repeat(1.., "abcd", Vec::new, fold_into_vec).parse_next(i)
+ fold_repeat(1.., "abcd", Vec::new, fold_into_vec).parse_peek(i)
}
let a = &b"abcdef"[..];
@@ -1171,7 +1173,7 @@ fn fold_repeat1_test() {
assert_eq!(
multi(Partial::new(c)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(c),
+ &Partial::new(c),
ErrorKind::Many
)))
);
@@ -1189,7 +1191,7 @@ fn fold_repeat_test() {
acc
}
fn multi(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, Vec<&[u8]>> {
- fold_repeat(2..=4, "Abcd", Vec::new, fold_into_vec).parse_next(i)
+ fold_repeat(2..=4, "Abcd", Vec::new, fold_into_vec).parse_peek(i)
}
let a = &b"Abcdef"[..];
@@ -1201,7 +1203,7 @@ fn fold_repeat_test() {
assert_eq!(
multi(Partial::new(a)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"ef"[..]),
+ &Partial::new(&b"ef"[..]),
ErrorKind::Tag
)))
);
@@ -1229,7 +1231,7 @@ fn fold_repeat_test() {
#[test]
fn repeat0_count_test() {
fn count0_nums(i: &[u8]) -> IResult<&[u8], usize> {
- repeat(0.., (digit, ",")).parse_next(i)
+ repeat(0.., (digit, ",")).parse_peek(i)
}
assert_eq!(count0_nums(&b"123,junk"[..]), Ok((&b"junk"[..], 1)));
@@ -1247,7 +1249,7 @@ fn repeat0_count_test() {
#[test]
fn repeat1_count_test() {
fn count1_nums(i: &[u8]) -> IResult<&[u8], usize> {
- repeat(1.., (digit, ",")).parse_next(i)
+ repeat(1.., (digit, ",")).parse_peek(i)
}
assert_eq!(count1_nums(&b"123,45,junk"[..]), Ok((&b"junk"[..], 2)));
@@ -1260,7 +1262,7 @@ fn repeat1_count_test() {
assert_eq!(
count1_nums(&b"hello"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b"hello"[..],
+ &&b"hello"[..],
ErrorKind::Slice
)))
);
diff --git a/vendor/winnow/src/error.rs b/vendor/winnow/src/error.rs
index c92228621..d40e8244b 100644
--- a/vendor/winnow/src/error.rs
+++ b/vendor/winnow/src/error.rs
@@ -8,14 +8,15 @@
//! - Can be modified according to the user's needs, because some languages need a lot more information
//! - Help thread-through the [stream][crate::stream]
//!
-//! To abstract these needs away from the user, generally `winnow` parsers use the [`IResult`]
-//! alias, rather than [`Result`][std::result::Result]. [`finish`][FinishIResult::finish] is
-//! provided for top-level parsers to integrate with your application's error reporting.
+//! To abstract these needs away from the user, generally `winnow` parsers use the [`PResult`]
+//! alias, rather than [`Result`][std::result::Result]. [`Parser::parse`] is a top-level operation
+//! that can help convert to a `Result` for integrating with your application's error reporting.
//!
//! Error types include:
//! - `()`
-//! - [`Error`]
-//! - [`VerboseError`]
+//! - [`ErrorKind`]
+//! - [`InputError`] (mostly for testing)
+//! - [`ContextError`]
//! - [Custom errors][crate::_topic::error]
#[cfg(feature = "alloc")]
@@ -23,8 +24,8 @@ use crate::lib::std::borrow::ToOwned;
use crate::lib::std::fmt;
use core::num::NonZeroUsize;
+use crate::stream::AsBStr;
use crate::stream::Stream;
-use crate::stream::StreamIsPartial;
#[allow(unused_imports)] // Here for intra-doc links
use crate::Parser;
@@ -33,100 +34,26 @@ use crate::Parser;
/// - `Ok((I, O))` is the remaining [input][crate::stream] and the parsed value
/// - [`Err(ErrMode<E>)`][ErrMode] is the error along with how to respond to it
///
-/// By default, the error type (`E`) is [`Error`]
+/// By default, the error type (`E`) is [`InputError`]
///
-/// At the top-level of your parser, you can use the [`FinishIResult::finish`] method to convert
-/// it to a more common result type
-pub type IResult<I, O, E = Error<I>> = Result<(I, O), ErrMode<E>>;
-
-/// Extension trait to convert a parser's [`IResult`] to a more manageable type
-#[deprecated(since = "0.4.0", note = "Replaced with `Parser::parse`")]
-pub trait FinishIResult<I, O, E> {
- /// Converts the parser's [`IResult`] to a type that is more consumable by callers.
- ///
- /// Errors if the parser is not at the [end of input][crate::combinator::eof]. See
- /// [`FinishIResult::finish_err`] if the remaining input is needed.
- ///
- /// # Panic
- ///
- /// If the result is `Err(ErrMode::Incomplete(_))`, this method will panic.
- /// - **Complete parsers:** It will not be an issue, `Incomplete` is never used
- /// - **Partial parsers:** `Incomplete` will be returned if there's not enough data
- /// for the parser to decide, and you should gather more data before parsing again.
- /// Once the parser returns either `Ok(_)`, `Err(ErrMode::Backtrack(_))` or `Err(ErrMode::Cut(_))`,
- /// you can get out of the parsing loop and call `finish_err()` on the parser's result
- ///
- /// # Example
- ///
- /// ```rust
- /// # #[cfg(feature = "std")] {
- /// use winnow::prelude::*;
- /// use winnow::ascii::hex_uint;
- /// use winnow::error::Error;
- ///
- /// struct Hex(u64);
- ///
- /// fn parse(value: &str) -> Result<Hex, Error<String>> {
- /// hex_uint.map(Hex).parse_next(value).finish().map_err(Error::into_owned)
- /// }
- /// # }
- /// ```
- #[deprecated(since = "0.4.0", note = "Replaced with `Parser::parse`")]
- fn finish(self) -> Result<O, E>;
-
- /// Converts the parser's [`IResult`] to a type that is more consumable by errors.
- ///
- /// It keeps the same `Ok` branch, and merges `ErrMode::Backtrack` and `ErrMode::Cut` into the `Err`
- /// side.
- ///
- /// # Panic
- ///
- /// If the result is `Err(ErrMode::Incomplete(_))`, this method will panic as [`ErrMode::Incomplete`]
- /// should only be set when the input is [`StreamIsPartial<false>`] which this isn't implemented
- /// for.
- #[deprecated(since = "0.4.0", note = "Replaced with `Parser::parse`")]
- fn finish_err(self) -> Result<(I, O), E>;
-}
-
-#[allow(deprecated)]
-impl<I, O, E> FinishIResult<I, O, E> for IResult<I, O, E>
-where
- I: Stream,
- // Force users to deal with `Incomplete` when `StreamIsPartial<true>`
- I: StreamIsPartial,
- I: Clone,
- E: ParseError<I>,
-{
- fn finish(self) -> Result<O, E> {
- debug_assert!(
- !I::is_partial_supported(),
- "partial streams need to handle `ErrMode::Incomplete`"
- );
+/// [`Parser::parse`] is a top-level operation that can help convert to a `Result` for integrating
+/// with your application's error reporting.
+pub type IResult<I, O, E = InputError<I>> = PResult<(I, O), E>;
- let (i, o) = self.finish_err()?;
- crate::combinator::eof(i).finish_err()?;
- Ok(o)
- }
-
- fn finish_err(self) -> Result<(I, O), E> {
- debug_assert!(
- !I::is_partial_supported(),
- "partial streams need to handle `ErrMode::Incomplete`"
- );
-
- match self {
- Ok(res) => Ok(res),
- Err(ErrMode::Backtrack(e)) | Err(ErrMode::Cut(e)) => Err(e),
- Err(ErrMode::Incomplete(_)) => {
- panic!("complete parsers should not report `Err(ErrMode::Incomplete(_))`")
- }
- }
- }
-}
+/// Holds the result of [`Parser`]
+///
+/// - `Ok(O)` is the parsed value
+/// - [`Err(ErrMode<E>)`][ErrMode] is the error along with how to respond to it
+///
+/// By default, the error type (`E`) is [`ErrorKind`].
+///
+/// [`Parser::parse`] is a top-level operation that can help convert to a `Result` for integrating
+/// with your application's error reporting.
+pub type PResult<O, E = ContextError> = Result<O, ErrMode<E>>;
/// Contains information on needed data if a parser returned `Incomplete`
///
-/// **Note:** This is only possible for `Stream` that are [partial][`StreamIsPartial`],
+/// **Note:** This is only possible for `Stream` that are [partial][`crate::stream::StreamIsPartial`],
/// like [`Partial`][crate::Partial].
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
@@ -169,7 +96,7 @@ pub enum ErrMode<E> {
///
/// More data needs to be buffered before retrying the parse.
///
- /// This must only be set when the [`Stream`] is [partial][`StreamIsPartial`], like with
+ /// This must only be set when the [`Stream`][crate::stream::Stream] is [partial][`crate::stream::StreamIsPartial`], like with
/// [`Partial`][crate::Partial]
///
/// Convert this into an `Backtrack` with [`Parser::complete_err`]
@@ -232,22 +159,33 @@ impl<E> ErrMode<E> {
{
self.map(ErrorConvert::convert)
}
+
+ /// Unwrap the mode, returning the underlying error
+ ///
+ /// Returns `None` for [`ErrMode::Incomplete`]
+ #[cfg_attr(debug_assertions, track_caller)]
+ pub fn into_inner(self) -> Option<E> {
+ match self {
+ ErrMode::Backtrack(e) | ErrMode::Cut(e) => Some(e),
+ ErrMode::Incomplete(_) => None,
+ }
+ }
}
-impl<I, E: ParseError<I>> ParseError<I> for ErrMode<E> {
- fn from_error_kind(input: I, kind: ErrorKind) -> Self {
+impl<I, E: ParserError<I>> ParserError<I> for ErrMode<E> {
+ fn from_error_kind(input: &I, kind: ErrorKind) -> Self {
ErrMode::Backtrack(E::from_error_kind(input, kind))
}
#[cfg_attr(debug_assertions, track_caller)]
- fn assert(input: I, message: &'static str) -> Self
+ fn assert(input: &I, message: &'static str) -> Self
where
I: crate::lib::std::fmt::Debug,
{
ErrMode::Backtrack(E::assert(input, message))
}
- fn append(self, input: I, kind: ErrorKind) -> Self {
+ fn append(self, input: &I, kind: ErrorKind) -> Self {
match self {
ErrMode::Backtrack(e) => ErrMode::Backtrack(e.append(input, kind)),
e => e,
@@ -267,24 +205,24 @@ impl<I, EXT, E> FromExternalError<I, EXT> for ErrMode<E>
where
E: FromExternalError<I, EXT>,
{
- fn from_external_error(input: I, kind: ErrorKind, e: EXT) -> Self {
+ fn from_external_error(input: &I, kind: ErrorKind, e: EXT) -> Self {
ErrMode::Backtrack(E::from_external_error(input, kind, e))
}
}
-impl<T> ErrMode<Error<T>> {
- /// Maps `ErrMode<Error<T>>` to `ErrMode<Error<U>>` with the given `F: T -> U`
- pub fn map_input<U, F>(self, f: F) -> ErrMode<Error<U>>
+impl<T: Clone> ErrMode<InputError<T>> {
+ /// Maps `ErrMode<InputError<T>>` to `ErrMode<InputError<U>>` with the given `F: T -> U`
+ pub fn map_input<U: Clone, F>(self, f: F) -> ErrMode<InputError<U>>
where
F: FnOnce(T) -> U,
{
match self {
ErrMode::Incomplete(n) => ErrMode::Incomplete(n),
- ErrMode::Cut(Error { input, kind }) => ErrMode::Cut(Error {
+ ErrMode::Cut(InputError { input, kind }) => ErrMode::Cut(InputError {
input: f(input),
kind,
}),
- ErrMode::Backtrack(Error { input, kind }) => ErrMode::Backtrack(Error {
+ ErrMode::Backtrack(InputError { input, kind }) => ErrMode::Backtrack(InputError {
input: f(input),
kind,
}),
@@ -312,13 +250,13 @@ where
///
/// It provides methods to create an error from some combinators,
/// and combine existing errors in combinators like `alt`.
-pub trait ParseError<I>: Sized {
+pub trait ParserError<I>: Sized {
/// Creates an error from the input position and an [`ErrorKind`]
- fn from_error_kind(input: I, kind: ErrorKind) -> Self;
+ fn from_error_kind(input: &I, kind: ErrorKind) -> Self;
/// Process a parser assertion
#[cfg_attr(debug_assertions, track_caller)]
- fn assert(input: I, _message: &'static str) -> Self
+ fn assert(input: &I, _message: &'static str) -> Self
where
I: crate::lib::std::fmt::Debug,
{
@@ -328,11 +266,11 @@ pub trait ParseError<I>: Sized {
Self::from_error_kind(input, ErrorKind::Assert)
}
- /// Like [`ParseError::from_error_kind`] but merges it with the existing error.
+ /// Like [`ParserError::from_error_kind`] but merges it with the existing error.
///
/// This is useful when backtracking through a parse tree, accumulating error context on the
/// way.
- fn append(self, input: I, kind: ErrorKind) -> Self;
+ fn append(self, input: &I, kind: ErrorKind) -> Self;
/// Combines errors from two different parse branches.
///
@@ -346,12 +284,13 @@ pub trait ParseError<I>: Sized {
/// Used by [`Parser::context`] to add custom data to error while backtracking
///
/// May be implemented multiple times for different kinds of context.
-pub trait ContextError<I, C = &'static str>: Sized {
+pub trait AddContext<I, C = &'static str>: Sized {
/// Append to an existing error custom data
///
/// This is used mainly by [`Parser::context`], to add user friendly information
/// to errors when backtracking through a parse tree
- fn add_context(self, _input: I, _ctx: C) -> Self {
+ #[inline]
+ fn add_context(self, _input: &I, _ctx: C) -> Self {
self
}
}
@@ -360,8 +299,8 @@ pub trait ContextError<I, C = &'static str>: Sized {
///
/// This trait is required by the [`Parser::try_map`] combinator.
pub trait FromExternalError<I, E> {
- /// Like [`ParseError::from_error_kind`] but also include an external error.
- fn from_external_error(input: I, kind: ErrorKind, e: E) -> Self;
+ /// Like [`ParserError::from_error_kind`] but also include an external error.
+ fn from_external_error(input: &I, kind: ErrorKind, e: E) -> Self;
}
/// Equivalent of `From` implementation to avoid orphan rules in bits parsers
@@ -370,70 +309,85 @@ pub trait ErrorConvert<E> {
fn convert(self) -> E;
}
-/// Default error type, only contains the error' location and kind
+/// Capture input on error
+///
+/// This is useful for testing of generic parsers to ensure the error happens at the right
+/// location.
///
-/// This is a low-overhead error that only provides basic information. For less overhead, see
-/// `()`. Fore more information, see [`VerboseError`].
-///:w
/// **Note:** [context][Parser::context] and inner errors (like from [`Parser::try_map`]) will be
/// dropped.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
-pub struct Error<I> {
+pub struct InputError<I: Clone> {
/// The input stream, pointing to the location where the error occurred
pub input: I,
/// A rudimentary error kind
pub kind: ErrorKind,
}
-impl<I> Error<I> {
+impl<I: Clone> InputError<I> {
/// Creates a new basic error
- pub fn new(input: I, kind: ErrorKind) -> Error<I> {
- Error { input, kind }
+ #[inline]
+ pub fn new(input: I, kind: ErrorKind) -> Self {
+ Self { input, kind }
}
}
#[cfg(feature = "alloc")]
-impl<'i, I: ToOwned + ?Sized> Error<&'i I> {
+impl<'i, I: Clone + ToOwned + ?Sized> InputError<&'i I>
+where
+ <I as ToOwned>::Owned: Clone,
+{
/// Obtaining ownership
- pub fn into_owned(self) -> Error<<I as ToOwned>::Owned> {
- Error {
+ pub fn into_owned(self) -> InputError<<I as ToOwned>::Owned> {
+ InputError {
input: self.input.to_owned(),
kind: self.kind,
}
}
}
-impl<I> ParseError<I> for Error<I> {
- fn from_error_kind(input: I, kind: ErrorKind) -> Self {
- Error { input, kind }
+impl<I: Clone> ParserError<I> for InputError<I> {
+ #[inline]
+ fn from_error_kind(input: &I, kind: ErrorKind) -> Self {
+ Self {
+ input: input.clone(),
+ kind,
+ }
}
- fn append(self, _: I, _: ErrorKind) -> Self {
+ #[inline]
+ fn append(self, _: &I, _: ErrorKind) -> Self {
self
}
}
-impl<I, C> ContextError<I, C> for Error<I> {}
+impl<I: Clone, C> AddContext<I, C> for InputError<I> {}
-impl<I, E> FromExternalError<I, E> for Error<I> {
+impl<I: Clone, E> FromExternalError<I, E> for InputError<I> {
/// Create a new error from an input position and an external error
- fn from_external_error(input: I, kind: ErrorKind, _e: E) -> Self {
- Error { input, kind }
+ #[inline]
+ fn from_external_error(input: &I, kind: ErrorKind, _e: E) -> Self {
+ Self {
+ input: input.clone(),
+ kind,
+ }
}
}
-impl<I> ErrorConvert<Error<(I, usize)>> for Error<I> {
- fn convert(self) -> Error<(I, usize)> {
- Error {
+impl<I: Clone> ErrorConvert<InputError<(I, usize)>> for InputError<I> {
+ #[inline]
+ fn convert(self) -> InputError<(I, usize)> {
+ InputError {
input: (self.input, 0),
kind: self.kind,
}
}
}
-impl<I> ErrorConvert<Error<I>> for Error<(I, usize)> {
- fn convert(self) -> Error<I> {
- Error {
+impl<I: Clone> ErrorConvert<InputError<I>> for InputError<(I, usize)> {
+ #[inline]
+ fn convert(self) -> InputError<I> {
+ InputError {
input: self.input.0,
kind: self.kind,
}
@@ -441,217 +395,254 @@ impl<I> ErrorConvert<Error<I>> for Error<(I, usize)> {
}
/// The Display implementation allows the `std::error::Error` implementation
-impl<I: fmt::Display> fmt::Display for Error<I> {
+impl<I: Clone + fmt::Display> fmt::Display for InputError<I> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "error {:?} at: {}", self.kind, self.input)
+ write!(f, "{} error starting at: {}", self.kind, self.input)
}
}
#[cfg(feature = "std")]
-impl<I: fmt::Debug + fmt::Display + Sync + Send + 'static> std::error::Error for Error<I> {}
+impl<I: Clone + fmt::Debug + fmt::Display + Sync + Send + 'static> std::error::Error
+ for InputError<I>
+{
+}
-impl<I> ParseError<I> for () {
- fn from_error_kind(_: I, _: ErrorKind) -> Self {}
+impl<I> ParserError<I> for () {
+ #[inline]
+ fn from_error_kind(_: &I, _: ErrorKind) -> Self {}
- fn append(self, _: I, _: ErrorKind) -> Self {}
+ #[inline]
+ fn append(self, _: &I, _: ErrorKind) -> Self {}
}
-impl<I, C> ContextError<I, C> for () {}
+impl<I, C> AddContext<I, C> for () {}
impl<I, E> FromExternalError<I, E> for () {
- fn from_external_error(_input: I, _kind: ErrorKind, _e: E) -> Self {}
+ #[inline]
+ fn from_external_error(_input: &I, _kind: ErrorKind, _e: E) -> Self {}
}
impl ErrorConvert<()> for () {
+ #[inline]
fn convert(self) {}
}
-/// Accumulates error information while backtracking
-///
-/// For less overhead (and information), see [`Error`].
-///
-/// [`convert_error`] provides an example of how to render this for end-users.
-///
-/// **Note:** This will only capture the last failed branch for combinators like
-/// [`alt`][crate::combinator::alt].
-#[cfg(feature = "alloc")]
-#[derive(Clone, Debug, Eq, PartialEq)]
-pub struct VerboseError<I> {
- /// Accumulated error information
- pub errors: crate::lib::std::vec::Vec<(I, VerboseErrorKind)>,
+/// Accumulate context while backtracking errors
+#[derive(Debug)]
+pub struct ContextError<C = StrContext> {
+ #[cfg(feature = "alloc")]
+ context: crate::lib::std::vec::Vec<C>,
+ #[cfg(not(feature = "alloc"))]
+ context: core::marker::PhantomData<C>,
+ #[cfg(feature = "std")]
+ cause: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
}
-#[cfg(feature = "alloc")]
-impl<'i, I: ToOwned + ?Sized> VerboseError<&'i I> {
- /// Obtaining ownership
- pub fn into_owned(self) -> VerboseError<<I as ToOwned>::Owned> {
- #[allow(clippy::redundant_clone)] // false positive
- VerboseError {
- errors: self
- .errors
- .into_iter()
- .map(|(i, k)| (i.to_owned(), k))
- .collect(),
+impl<C> ContextError<C> {
+ /// Create an empty error
+ #[inline]
+ pub fn new() -> Self {
+ Self {
+ context: Default::default(),
+ #[cfg(feature = "std")]
+ cause: None,
}
}
+
+ /// Access context from [`Parser::context`]
+ #[inline]
+ #[cfg(feature = "alloc")]
+ pub fn context(&self) -> impl Iterator<Item = &C> {
+ self.context.iter()
+ }
+
+ /// Originating [`std::error::Error`]
+ #[inline]
+ #[cfg(feature = "std")]
+ pub fn cause(&self) -> Option<&(dyn std::error::Error + Send + Sync + 'static)> {
+ self.cause.as_deref()
+ }
}
-#[cfg(feature = "alloc")]
-#[derive(Clone, Debug, Eq, PartialEq)]
-/// Error context for `VerboseError`
-pub enum VerboseErrorKind {
- /// Static string added by the `context` function
- Context(&'static str),
- /// Error kind given by various parsers
- Winnow(ErrorKind),
+impl<C> Default for ContextError<C> {
+ #[inline]
+ fn default() -> Self {
+ Self::new()
+ }
}
-#[cfg(feature = "alloc")]
-impl<I> ParseError<I> for VerboseError<I> {
- fn from_error_kind(input: I, kind: ErrorKind) -> Self {
- VerboseError {
- errors: vec![(input, VerboseErrorKind::Winnow(kind))],
- }
+impl<I, C> ParserError<I> for ContextError<C> {
+ #[inline]
+ fn from_error_kind(_input: &I, _kind: ErrorKind) -> Self {
+ Self::new()
}
- fn append(mut self, input: I, kind: ErrorKind) -> Self {
- self.errors.push((input, VerboseErrorKind::Winnow(kind)));
+ #[inline]
+ fn append(self, _input: &I, _kind: ErrorKind) -> Self {
self
}
-}
-#[cfg(feature = "alloc")]
-impl<I> ContextError<I, &'static str> for VerboseError<I> {
- fn add_context(mut self, input: I, ctx: &'static str) -> Self {
- self.errors.push((input, VerboseErrorKind::Context(ctx)));
- self
+ #[inline]
+ fn or(self, other: Self) -> Self {
+ other
}
}
-#[cfg(feature = "alloc")]
-impl<I, E> FromExternalError<I, E> for VerboseError<I> {
- /// Create a new error from an input position and an external error
- fn from_external_error(input: I, kind: ErrorKind, _e: E) -> Self {
- Self::from_error_kind(input, kind)
+impl<C, I> AddContext<I, C> for ContextError<C> {
+ #[inline]
+ fn add_context(mut self, _input: &I, ctx: C) -> Self {
+ #[cfg(feature = "alloc")]
+ self.context.push(ctx);
+ self
}
}
-#[cfg(feature = "alloc")]
-impl<I> ErrorConvert<VerboseError<I>> for VerboseError<(I, usize)> {
- fn convert(self) -> VerboseError<I> {
- VerboseError {
- errors: self.errors.into_iter().map(|(i, e)| (i.0, e)).collect(),
+#[cfg(feature = "std")]
+impl<C, I, E: std::error::Error + Send + Sync + 'static> FromExternalError<I, E>
+ for ContextError<C>
+{
+ #[inline]
+ fn from_external_error(_input: &I, _kind: ErrorKind, e: E) -> Self {
+ let mut err = Self::new();
+ {
+ err.cause = Some(Box::new(e));
}
+ err
}
}
-#[cfg(feature = "alloc")]
-impl<I> ErrorConvert<VerboseError<(I, usize)>> for VerboseError<I> {
- fn convert(self) -> VerboseError<(I, usize)> {
- VerboseError {
- errors: self.errors.into_iter().map(|(i, e)| ((i, 0), e)).collect(),
- }
+// HACK: This is more general than `std`, making the features non-additive
+#[cfg(not(feature = "std"))]
+impl<C, I, E: Send + Sync + 'static> FromExternalError<I, E> for ContextError<C> {
+ #[inline]
+ fn from_external_error(_input: &I, _kind: ErrorKind, _e: E) -> Self {
+ let err = Self::new();
+ err
}
}
-#[cfg(feature = "alloc")]
-impl<I: fmt::Display> fmt::Display for VerboseError<I> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- writeln!(f, "Parse error:")?;
- for (input, error) in &self.errors {
- match error {
- VerboseErrorKind::Winnow(e) => writeln!(f, "{:?} at: {}", e, input)?,
- VerboseErrorKind::Context(s) => writeln!(f, "in section '{}', at: {}", s, input)?,
+// For tests
+impl<C: core::cmp::PartialEq> core::cmp::PartialEq for ContextError<C> {
+ fn eq(&self, other: &Self) -> bool {
+ #[cfg(feature = "alloc")]
+ {
+ if self.context != other.context {
+ return false;
+ }
+ }
+ #[cfg(feature = "std")]
+ {
+ if self.cause.as_ref().map(ToString::to_string)
+ != other.cause.as_ref().map(ToString::to_string)
+ {
+ return false;
}
}
- Ok(())
+ true
}
}
-#[cfg(feature = "std")]
-impl<I: fmt::Debug + fmt::Display + Sync + Send + 'static> std::error::Error for VerboseError<I> {}
+impl crate::lib::std::fmt::Display for ContextError<StrContext> {
+ fn fmt(&self, f: &mut crate::lib::std::fmt::Formatter<'_>) -> crate::lib::std::fmt::Result {
+ #[cfg(feature = "alloc")]
+ {
+ let expression = self.context().find_map(|c| match c {
+ StrContext::Label(c) => Some(c),
+ _ => None,
+ });
+ let expected = self
+ .context()
+ .filter_map(|c| match c {
+ StrContext::Expected(c) => Some(c),
+ _ => None,
+ })
+ .collect::<crate::lib::std::vec::Vec<_>>();
-/// Transforms a `VerboseError` into a trace with input position information
-#[cfg(feature = "alloc")]
-pub fn convert_error<I: core::ops::Deref<Target = str>>(
- input: I,
- e: VerboseError<I>,
-) -> crate::lib::std::string::String {
- use crate::lib::std::fmt::Write;
- use crate::stream::Offset;
+ let mut newline = false;
- let mut result = crate::lib::std::string::String::new();
+ if let Some(expression) = expression {
+ newline = true;
- for (i, (substring, kind)) in e.errors.iter().enumerate() {
- let offset = input.offset_to(substring);
+ write!(f, "invalid {}", expression)?;
+ }
- if input.is_empty() {
- match kind {
- VerboseErrorKind::Context(s) => {
- write!(&mut result, "{}: in {}, got empty input\n\n", i, s)
+ if !expected.is_empty() {
+ if newline {
+ writeln!(f)?;
}
- VerboseErrorKind::Winnow(e) => {
- write!(&mut result, "{}: in {:?}, got empty input\n\n", i, e)
+ newline = true;
+
+ write!(f, "expected ")?;
+ for (i, expected) in expected.iter().enumerate() {
+ if i != 0 {
+ write!(f, ", ")?;
+ }
+ write!(f, "{}", expected)?;
}
}
- } else {
- let prefix = &input.as_bytes()[..offset];
-
- // Count the number of newlines in the first `offset` bytes of input
- let line_number = prefix.iter().filter(|&&b| b == b'\n').count() + 1;
-
- // Find the line that includes the subslice:
- // Find the *last* newline before the substring starts
- let line_begin = prefix
- .iter()
- .rev()
- .position(|&b| b == b'\n')
- .map(|pos| offset - pos)
- .unwrap_or(0);
-
- // Find the full line after that newline
- let line = input[line_begin..]
- .lines()
- .next()
- .unwrap_or(&input[line_begin..])
- .trim_end();
-
- // The (1-indexed) column number is the offset of our substring into that line
- let column_number = line.offset_to(substring) + 1;
-
- match kind {
- VerboseErrorKind::Context(s) => write!(
- &mut result,
- "{i}: at line {line_number}, in {context}:\n\
- {line}\n\
- {caret:>column$}\n\n",
- i = i,
- line_number = line_number,
- context = s,
- line = line,
- caret = '^',
- column = column_number,
- ),
- VerboseErrorKind::Winnow(e) => write!(
- &mut result,
- "{i}: at line {line_number}, in {kind:?}:\n\
- {line}\n\
- {caret:>column$}\n\n",
- i = i,
- line_number = line_number,
- kind = e,
- line = line,
- caret = '^',
- column = column_number,
- ),
+ #[cfg(feature = "std")]
+ {
+ if let Some(cause) = self.cause() {
+ if newline {
+ writeln!(f)?;
+ }
+ write!(f, "{}", cause)?;
+ }
}
}
- // Because `write!` to a `String` is infallible, this `unwrap` is fine.
- .unwrap();
+
+ Ok(())
+ }
+}
+
+/// Additional parse context for [`ContextError`] added via [`Parser::context`]
+#[derive(Clone, Debug, PartialEq, Eq)]
+#[non_exhaustive]
+pub enum StrContext {
+ /// Description of what is currently being parsed
+ Label(&'static str),
+ /// Grammar item that was expected
+ Expected(StrContextValue),
+}
+
+/// See [`StrContext`]
+#[derive(Clone, Debug, PartialEq, Eq)]
+#[non_exhaustive]
+pub enum StrContextValue {
+ /// A [`char`] token
+ CharLiteral(char),
+ /// A [`&str`] token
+ StringLiteral(&'static str),
+ /// A description of what was being parsed
+ Description(&'static str),
+}
+
+impl From<char> for StrContextValue {
+ fn from(inner: char) -> Self {
+ Self::CharLiteral(inner)
}
+}
- result
+impl From<&'static str> for StrContextValue {
+ fn from(inner: &'static str) -> Self {
+ Self::StringLiteral(inner)
+ }
+}
+
+impl crate::lib::std::fmt::Display for StrContextValue {
+ fn fmt(&self, f: &mut crate::lib::std::fmt::Formatter<'_>) -> crate::lib::std::fmt::Result {
+ match self {
+ Self::CharLiteral('\n') => "newline".fmt(f),
+ Self::CharLiteral('`') => "'`'".fmt(f),
+ Self::CharLiteral(c) if c.is_ascii_control() => {
+ write!(f, "`{}`", c.escape_debug())
+ }
+ Self::CharLiteral(c) => write!(f, "`{}`", c),
+ Self::StringLiteral(c) => write!(f, "`{}`", c),
+ Self::Description(c) => write!(f, "{}", c),
+ }
+ }
}
/// Provide some minor debug context for errors
@@ -692,31 +683,255 @@ impl ErrorKind {
}
}
+impl<I> ParserError<I> for ErrorKind {
+ fn from_error_kind(_input: &I, kind: ErrorKind) -> Self {
+ kind
+ }
+
+ fn append(self, _: &I, _: ErrorKind) -> Self {
+ self
+ }
+}
+
+impl<I, C> AddContext<I, C> for ErrorKind {}
+
+impl<I, E> FromExternalError<I, E> for ErrorKind {
+ /// Create a new error from an input position and an external error
+ fn from_external_error(_input: &I, kind: ErrorKind, _e: E) -> Self {
+ kind
+ }
+}
+
+/// The Display implementation allows the `std::error::Error` implementation
+impl fmt::Display for ErrorKind {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "error {:?}", self)
+ }
+}
+
+#[cfg(feature = "std")]
+impl std::error::Error for ErrorKind {}
+
+/// See [`Parser::parse`]
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct ParseError<I, E> {
+ input: I,
+ offset: usize,
+ inner: E,
+}
+
+impl<I: Stream, E: ParserError<I>> ParseError<I, E> {
+ pub(crate) fn new(mut input: I, start: I::Checkpoint, inner: E) -> Self {
+ let offset = input.offset_from(&start);
+ input.reset(start);
+ Self {
+ input,
+ offset,
+ inner,
+ }
+ }
+}
+
+impl<I, E> ParseError<I, E> {
+ /// The [`Stream`] at the initial location when parsing started
+ #[inline]
+ pub fn input(&self) -> &I {
+ &self.input
+ }
+
+ /// The location in [`ParseError::input`] where parsing failed
+ #[inline]
+ pub fn offset(&self) -> usize {
+ self.offset
+ }
+
+ /// The original [`ParserError`]
+ #[inline]
+ pub fn inner(&self) -> &E {
+ &self.inner
+ }
+}
+
+impl<I, E> core::fmt::Display for ParseError<I, E>
+where
+ I: AsBStr,
+ E: core::fmt::Display,
+{
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ let input = self.input.as_bstr();
+ let span_start = self.offset;
+ let span_end = span_start;
+ #[cfg(feature = "std")]
+ if input.contains(&b'\n') {
+ let (line_idx, col_idx) = translate_position(input, span_start);
+ let line_num = line_idx + 1;
+ let col_num = col_idx + 1;
+ let gutter = line_num.to_string().len();
+ let content = input
+ .split(|c| *c == b'\n')
+ .nth(line_idx)
+ .expect("valid line number");
+
+ writeln!(f, "parse error at line {}, column {}", line_num, col_num)?;
+ // |
+ for _ in 0..=gutter {
+ write!(f, " ")?;
+ }
+ writeln!(f, "|")?;
+
+ // 1 | 00:32:00.a999999
+ write!(f, "{} | ", line_num)?;
+ writeln!(f, "{}", String::from_utf8_lossy(content))?;
+
+ // | ^
+ for _ in 0..=gutter {
+ write!(f, " ")?;
+ }
+ write!(f, "|")?;
+ for _ in 0..=col_idx {
+ write!(f, " ")?;
+ }
+ // The span will be empty at eof, so we need to make sure we always print at least
+ // one `^`
+ write!(f, "^")?;
+ for _ in (span_start + 1)..(span_end.min(span_start + content.len())) {
+ write!(f, "^")?;
+ }
+ writeln!(f)?;
+ } else {
+ let content = input;
+ writeln!(f, "{}", String::from_utf8_lossy(content))?;
+ for _ in 0..=span_start {
+ write!(f, " ")?;
+ }
+ // The span will be empty at eof, so we need to make sure we always print at least
+ // one `^`
+ write!(f, "^")?;
+ for _ in (span_start + 1)..(span_end.min(span_start + content.len())) {
+ write!(f, "^")?;
+ }
+ writeln!(f)?;
+ }
+ write!(f, "{}", self.inner)?;
+
+ Ok(())
+ }
+}
+
+#[cfg(feature = "std")]
+fn translate_position(input: &[u8], index: usize) -> (usize, usize) {
+ if input.is_empty() {
+ return (0, index);
+ }
+
+ let safe_index = index.min(input.len() - 1);
+ let column_offset = index - safe_index;
+ let index = safe_index;
+
+ let nl = input[0..index]
+ .iter()
+ .rev()
+ .enumerate()
+ .find(|(_, b)| **b == b'\n')
+ .map(|(nl, _)| index - nl - 1);
+ let line_start = match nl {
+ Some(nl) => nl + 1,
+ None => 0,
+ };
+ let line = input[0..line_start].iter().filter(|b| **b == b'\n').count();
+ let line = line;
+
+ // HACK: This treats byte offset and column offsets the same
+ let column = std::str::from_utf8(&input[line_start..=index])
+ .map(|s| s.chars().count() - 1)
+ .unwrap_or_else(|_| index - line_start);
+ let column = column + column_offset;
+
+ (line, column)
+}
+
+#[cfg(test)]
+#[cfg(feature = "std")]
+mod test_translate_position {
+ use super::*;
+
+ #[test]
+ fn empty() {
+ let input = b"";
+ let index = 0;
+ let position = translate_position(&input[..], index);
+ assert_eq!(position, (0, 0));
+ }
+
+ #[test]
+ fn start() {
+ let input = b"Hello";
+ let index = 0;
+ let position = translate_position(&input[..], index);
+ assert_eq!(position, (0, 0));
+ }
+
+ #[test]
+ fn end() {
+ let input = b"Hello";
+ let index = input.len() - 1;
+ let position = translate_position(&input[..], index);
+ assert_eq!(position, (0, input.len() - 1));
+ }
+
+ #[test]
+ fn after() {
+ let input = b"Hello";
+ let index = input.len();
+ let position = translate_position(&input[..], index);
+ assert_eq!(position, (0, input.len()));
+ }
+
+ #[test]
+ fn first_line() {
+ let input = b"Hello\nWorld\n";
+ let index = 2;
+ let position = translate_position(&input[..], index);
+ assert_eq!(position, (0, 2));
+ }
+
+ #[test]
+ fn end_of_line() {
+ let input = b"Hello\nWorld\n";
+ let index = 5;
+ let position = translate_position(&input[..], index);
+ assert_eq!(position, (0, 5));
+ }
+
+ #[test]
+ fn start_of_second_line() {
+ let input = b"Hello\nWorld\n";
+ let index = 6;
+ let position = translate_position(&input[..], index);
+ assert_eq!(position, (1, 0));
+ }
+
+ #[test]
+ fn second_line() {
+ let input = b"Hello\nWorld\n";
+ let index = 8;
+ let position = translate_position(&input[..], index);
+ assert_eq!(position, (1, 2));
+ }
+}
+
/// Creates a parse error from a [`ErrorKind`]
/// and the position in the input
#[cfg(test)]
macro_rules! error_position(
($input:expr, $code:expr) => ({
- $crate::error::ParseError::from_error_kind($input, $code)
+ $crate::error::ParserError::from_error_kind($input, $code)
});
);
#[cfg(test)]
macro_rules! error_node_position(
($input:expr, $code:expr, $next:expr) => ({
- $crate::error::ParseError::append($next, $input, $code)
+ $crate::error::ParserError::append($next, $input, $code)
});
);
-
-#[cfg(test)]
-#[cfg(feature = "alloc")]
-mod tests {
- use super::*;
-
- #[test]
- fn convert_error_panic() {
- let input = "";
-
- let _result: IResult<_, _, VerboseError<&str>> = 'x'.parse_next(input);
- }
-}
diff --git a/vendor/winnow/src/lib.rs b/vendor/winnow/src/lib.rs
index 3b6066230..5614b7f11 100644
--- a/vendor/winnow/src/lib.rs
+++ b/vendor/winnow/src/lib.rs
@@ -137,7 +137,7 @@
#![allow(clippy::unnested_or_patterns)]
#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
#[cfg(feature = "alloc")]
-#[macro_use]
+#[cfg_attr(test, macro_use)]
extern crate alloc;
#[cfg(doctest)]
extern crate doc_comment;
@@ -201,14 +201,7 @@ pub mod stream;
pub mod ascii;
pub mod binary;
-pub mod bits;
-pub mod branch;
-pub mod bytes;
-pub mod character;
pub mod combinator;
-pub mod multi;
-pub mod number;
-pub mod sequence;
pub mod token;
pub mod trace;
@@ -220,7 +213,7 @@ pub mod _tutorial;
/// Core concepts available for glob import
///
/// Including
-/// - [`FinishIResult`]
+/// - [`StreamIsPartial`][crate::stream::StreamIsPartial]
/// - [`Parser`]
///
/// ## Example
@@ -228,7 +221,7 @@ pub mod _tutorial;
/// ```rust
/// use winnow::prelude::*;
///
-/// fn parse_data(input: &str) -> IResult<&str, u64> {
+/// fn parse_data(input: &mut &str) -> PResult<u64> {
/// // ...
/// # winnow::ascii::dec_uint(input)
/// }
@@ -240,15 +233,13 @@ pub mod _tutorial;
/// ```
pub mod prelude {
pub use crate::stream::StreamIsPartial as _;
- #[allow(deprecated)]
- pub use crate::FinishIResult as _;
pub use crate::IResult;
+ pub use crate::PResult;
pub use crate::Parser;
}
-#[allow(deprecated)]
-pub use error::FinishIResult;
pub use error::IResult;
+pub use error::PResult;
pub use parser::*;
pub use stream::BStr;
pub use stream::Bytes;
diff --git a/vendor/winnow/src/macros.rs b/vendor/winnow/src/macros.rs
index 8a38ef25c..b3078c605 100644
--- a/vendor/winnow/src/macros.rs
+++ b/vendor/winnow/src/macros.rs
@@ -17,11 +17,11 @@
/// # use winnow::combinator::success;
/// # use winnow::combinator::fail;
///
-/// fn escaped(input: &str) -> IResult<&str, char> {
+/// fn escaped(input: &mut &str) -> PResult<char> {
/// preceded('\\', escape_seq_char).parse_next(input)
/// }
///
-/// fn escape_seq_char(input: &str) -> IResult<&str, char> {
+/// fn escape_seq_char(input: &mut &str) -> PResult<char> {
/// dispatch! {any;
/// 'b' => success('\u{8}'),
/// 'f' => success('\u{c}'),
@@ -35,15 +35,15 @@
/// .parse_next(input)
/// }
///
-/// assert_eq!(escaped.parse_next("\\nHello"), Ok(("Hello", '\n')));
+/// assert_eq!(escaped.parse_peek("\\nHello"), Ok(("Hello", '\n')));
/// ```
#[macro_export]
macro_rules! dispatch {
($match_parser: expr; $( $pat:pat $(if $pred:expr)? => $expr: expr ),+ $(,)? ) => {
- $crate::trace::trace("dispatch", move |i|
+ $crate::trace::trace("dispatch", move |i: &mut _|
{
use $crate::Parser;
- let (i, initial) = $match_parser.parse_next(i)?;
+ let initial = $match_parser.parse_next(i)?;
match initial {
$(
$pat $(if $pred)? => $expr.parse_next(i),
diff --git a/vendor/winnow/src/multi.rs b/vendor/winnow/src/multi.rs
deleted file mode 100644
index 3e92f70be..000000000
--- a/vendor/winnow/src/multi.rs
+++ /dev/null
@@ -1,124 +0,0 @@
-//! Deprecated, see [`combinator`]
-#![deprecated(since = "0.4.2", note = "Replaced with `combinator`")]
-
-use crate::binary;
-use crate::combinator;
-use crate::error::ParseError;
-use crate::stream::Accumulate;
-use crate::stream::Stream;
-use crate::Parser;
-
-/// Deprecated, replaced by [`combinator::repeat`]
-#[deprecated(since = "0.4.2", note = "Replaced with `combinator::repeat`")]
-#[inline(always)]
-pub fn many0<I, O, C, E, F>(f: F) -> impl Parser<I, C, E>
-where
- I: Stream,
- C: Accumulate<O>,
- F: Parser<I, O, E>,
- E: ParseError<I>,
-{
- combinator::repeat(0.., f)
-}
-
-/// Deprecated, replaced by [`combinator::repeat`]
-#[deprecated(since = "0.4.2", note = "Replaced with `combinator::repeat`")]
-#[inline(always)]
-pub fn many1<I, O, C, E, F>(f: F) -> impl Parser<I, C, E>
-where
- I: Stream,
- C: Accumulate<O>,
- F: Parser<I, O, E>,
- E: ParseError<I>,
-{
- combinator::repeat(1.., f)
-}
-
-/// Deprecated, replaced by [`combinator::repeat_till0`]
-#[deprecated(since = "0.4.2", note = "Replaced with `combinator::repeat_till0`")]
-#[inline(always)]
-pub fn many_till0<I, O, C, P, E, F, G>(f: F, g: G) -> impl Parser<I, (C, P), E>
-where
- I: Stream,
- C: Accumulate<O>,
- F: Parser<I, O, E>,
- G: Parser<I, P, E>,
- E: ParseError<I>,
-{
- combinator::repeat_till0(f, g)
-}
-
-pub use combinator::separated0;
-pub use combinator::separated1;
-pub use combinator::separated_foldl1;
-#[cfg(feature = "alloc")]
-pub use combinator::separated_foldr1;
-
-/// Deprecated, replaced by [`combinator::repeat`]
-#[deprecated(since = "0.4.2", note = "Replaced with `combinator::repeat`")]
-#[inline(always)]
-pub fn many_m_n<I, O, C, E, F>(min: usize, max: usize, parse: F) -> impl Parser<I, C, E>
-where
- I: Stream,
- C: Accumulate<O>,
- F: Parser<I, O, E>,
- E: ParseError<I>,
-{
- combinator::repeat(min..=max, parse)
-}
-
-#[allow(deprecated)]
-pub use combinator::count;
-pub use combinator::fill;
-
-/// Deprecated, replaced by [`combinator::fold_repeat`]
-#[deprecated(since = "0.4.2", note = "Replaced with `combinator::fold_repeat`")]
-#[inline(always)]
-pub fn fold_many0<I, O, E, F, G, H, R>(f: F, init: H, g: G) -> impl Parser<I, R, E>
-where
- I: Stream,
- F: Parser<I, O, E>,
- G: FnMut(R, O) -> R,
- H: FnMut() -> R,
- E: ParseError<I>,
-{
- combinator::fold_repeat(0.., f, init, g)
-}
-
-/// Deprecated, replaced by [`combinator::fold_repeat`]
-#[deprecated(since = "0.4.2", note = "Replaced with `combinator::fold_repeat`")]
-#[inline(always)]
-pub fn fold_many1<I, O, E, F, G, H, R>(f: F, init: H, g: G) -> impl Parser<I, R, E>
-where
- I: Stream,
- F: Parser<I, O, E>,
- G: FnMut(R, O) -> R,
- H: FnMut() -> R,
- E: ParseError<I>,
-{
- combinator::fold_repeat(1.., f, init, g)
-}
-
-/// Deprecated, replaced by [`combinator::fold_repeat`]
-#[deprecated(since = "0.4.2", note = "Replaced with `combinator::fold_repeat`")]
-#[inline(always)]
-pub fn fold_many_m_n<I, O, E, F, G, H, R>(
- min: usize,
- max: usize,
- parse: F,
- init: H,
- fold: G,
-) -> impl Parser<I, R, E>
-where
- I: Stream,
- F: Parser<I, O, E>,
- G: FnMut(R, O) -> R,
- H: FnMut() -> R,
- E: ParseError<I>,
-{
- combinator::fold_repeat(min..=max, parse, init, fold)
-}
-
-pub use binary::length_count;
-pub use binary::length_data;
-pub use binary::length_value;
diff --git a/vendor/winnow/src/number.rs b/vendor/winnow/src/number.rs
deleted file mode 100644
index 2aa8da425..000000000
--- a/vendor/winnow/src/number.rs
+++ /dev/null
@@ -1,509 +0,0 @@
-//! Deprecated, see [`binary`]
-#![deprecated(since = "0.4.2", note = "Replaced with `binary`")]
-#![allow(clippy::match_same_arms)]
-
-use crate::binary;
-use crate::error::ParseError;
-use crate::stream::{AsBytes, Stream, StreamIsPartial};
-use crate::IResult;
-use crate::Parser;
-
-pub use binary::Endianness;
-
-/// Deprecated, see [`binary::be_u8`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_u8`")]
-#[inline(always)]
-pub fn be_u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
-{
- binary::be_u8(input)
-}
-
-/// Deprecated, see [`binary::be_u16`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_u16`")]
-#[inline(always)]
-pub fn be_u16<I, E: ParseError<I>>(input: I) -> IResult<I, u16, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_u16(input)
-}
-
-/// Deprecated, see [`binary::be_u24`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_u24`")]
-#[inline(always)]
-pub fn be_u24<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_u24(input)
-}
-
-/// Deprecated, see [`binary::be_u32`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_u32`")]
-#[inline(always)]
-pub fn be_u32<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_u32(input)
-}
-
-/// Deprecated, see [`binary::be_u64`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_u64`")]
-#[inline(always)]
-pub fn be_u64<I, E: ParseError<I>>(input: I) -> IResult<I, u64, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_u64(input)
-}
-
-/// Deprecated, see [`binary::be_u128`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_u128`")]
-#[inline(always)]
-pub fn be_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_u128(input)
-}
-
-/// Deprecated, see [`binary::be_i8`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_i8`")]
-#[inline(always)]
-pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
-{
- binary::be_i8(input)
-}
-
-/// Deprecated, see [`binary::be_i16`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_i16`")]
-#[inline(always)]
-pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_i16(input)
-}
-
-/// Deprecated, see [`binary::be_i24`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_i24`")]
-#[inline(always)]
-pub fn be_i24<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_i24(input)
-}
-
-/// Deprecated, see [`binary::be_i32`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_i32`")]
-#[inline(always)]
-pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_i32(input)
-}
-
-/// Deprecated, see [`binary::be_i64`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_i64`")]
-#[inline(always)]
-pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_i64(input)
-}
-
-/// Deprecated, see [`binary::be_i128`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_i128`")]
-#[inline(always)]
-pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_i128(input)
-}
-
-/// Deprecated, see [`binary::le_u8`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_u8`")]
-#[inline(always)]
-pub fn le_u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
-{
- binary::le_u8(input)
-}
-
-/// Deprecated, see [`binary::le_u16`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_u16`")]
-#[inline(always)]
-pub fn le_u16<I, E: ParseError<I>>(input: I) -> IResult<I, u16, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_u16(input)
-}
-
-/// Deprecated, see [`binary::le_u24`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_u24`")]
-#[inline(always)]
-pub fn le_u24<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_u24(input)
-}
-
-/// Deprecated, see [`binary::le_u32`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_u32`")]
-#[inline(always)]
-pub fn le_u32<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_u32(input)
-}
-
-/// Deprecated, see [`binary::le_u64`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_u64`")]
-#[inline(always)]
-pub fn le_u64<I, E: ParseError<I>>(input: I) -> IResult<I, u64, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_u64(input)
-}
-
-/// Deprecated, see [`binary::le_u128`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_u128`")]
-#[inline(always)]
-pub fn le_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_u128(input)
-}
-
-/// Deprecated, see [`binary::le_i8`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_i8`")]
-#[inline(always)]
-pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
-{
- binary::le_i8(input)
-}
-
-/// Deprecated, see [`binary::le_i16`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_i16`")]
-#[inline(always)]
-pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_i16(input)
-}
-
-/// Deprecated, see [`binary::le_i24`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_i24`")]
-#[inline(always)]
-pub fn le_i24<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_i24(input)
-}
-
-/// Deprecated, see [`binary::le_i32`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_i32`")]
-#[inline(always)]
-pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_i32(input)
-}
-
-/// Deprecated, see [`binary::le_i64`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_i64`")]
-#[inline(always)]
-pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_i64(input)
-}
-
-/// Deprecated, see [`binary::le_i128`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_i128`")]
-#[inline(always)]
-pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_i128(input)
-}
-
-/// Deprecated, see [`binary::u8`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::u8`")]
-#[inline(always)]
-pub fn u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
-{
- binary::u8.parse_next(input)
-}
-
-/// Deprecated, see [`binary::u16`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::u16`")]
-#[inline(always)]
-pub fn u16<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, u16, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::u16(endian)
-}
-
-/// Deprecated, see [`binary::u24`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::u24`")]
-#[inline(always)]
-pub fn u24<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, u32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::u24(endian)
-}
-
-/// Deprecated, see [`binary::u32`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::u32`")]
-#[inline(always)]
-pub fn u32<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, u32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::u32(endian)
-}
-
-/// Deprecated, see [`binary::u64`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::u64`")]
-#[inline(always)]
-pub fn u64<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, u64, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::u64(endian)
-}
-
-/// Deprecated, see [`binary::u128`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::u128`")]
-#[inline(always)]
-pub fn u128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, u128, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::u128(endian)
-}
-
-/// Deprecated, see [`binary::i8`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::i8`")]
-#[inline(always)]
-pub fn i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
-{
- binary::i8.parse_next(input)
-}
-
-/// Deprecated, see [`binary::i16`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::i16`")]
-#[inline(always)]
-pub fn i16<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, i16, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::i16(endian)
-}
-
-/// Deprecated, see [`binary::i24`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::i24`")]
-#[inline(always)]
-pub fn i24<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, i32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::i24(endian)
-}
-
-/// Deprecated, see [`binary::i32`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::i32`")]
-#[inline(always)]
-pub fn i32<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, i32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::i32(endian)
-}
-
-/// Deprecated, see [`binary::i64`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::i64`")]
-#[inline(always)]
-pub fn i64<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, i64, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::i64(endian)
-}
-
-/// Deprecated, see [`binary::i128`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::i128`")]
-#[inline(always)]
-pub fn i128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, i128, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::i128(endian)
-}
-
-/// Deprecated, see [`binary::be_f32`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_f32`")]
-#[inline(always)]
-pub fn be_f32<I, E: ParseError<I>>(input: I) -> IResult<I, f32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_f32(input)
-}
-
-/// Deprecated, see [`binary::be_f64`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::be_f64`")]
-#[inline(always)]
-pub fn be_f64<I, E: ParseError<I>>(input: I) -> IResult<I, f64, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::be_f64(input)
-}
-
-/// Deprecated, see [`binary::le_f32`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_f32`")]
-#[inline(always)]
-pub fn le_f32<I, E: ParseError<I>>(input: I) -> IResult<I, f32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_f32(input)
-}
-
-/// Deprecated, see [`binary::le_f64`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::le_f64`")]
-#[inline(always)]
-pub fn le_f64<I, E: ParseError<I>>(input: I) -> IResult<I, f64, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::le_f64(input)
-}
-
-/// Deprecated, see [`binary::f32`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::f32`")]
-#[inline(always)]
-pub fn f32<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, f32, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::f32(endian)
-}
-
-/// Deprecated, see [`binary::f64`]
-#[deprecated(since = "0.4.2", note = "Replaced with `binary::f64`")]
-#[inline(always)]
-pub fn f64<I, E: ParseError<I>>(endian: crate::number::Endianness) -> impl Parser<I, f64, E>
-where
- I: StreamIsPartial,
- I: Stream<Token = u8>,
- <I as Stream>::Slice: AsBytes,
-{
- binary::f64(endian)
-}
diff --git a/vendor/winnow/src/parser.rs b/vendor/winnow/src/parser.rs
index 15d892864..d160a8ef8 100644
--- a/vendor/winnow/src/parser.rs
+++ b/vendor/winnow/src/parser.rs
@@ -1,8 +1,8 @@
//! Basic types to build the parsers
use crate::combinator::*;
-use crate::error::{ContextError, FromExternalError, IResult, ParseError};
-use crate::stream::{AsChar, Compare, Location, Offset, ParseSlice, Stream, StreamIsPartial};
+use crate::error::{AddContext, FromExternalError, IResult, PResult, ParseError, ParserError};
+use crate::stream::{AsChar, Compare, Location, ParseSlice, Stream, StreamIsPartial};
/// Core trait for parsing
///
@@ -10,12 +10,12 @@ use crate::stream::{AsChar, Compare, Location, Offset, ParseSlice, Stream, Strea
/// ```rust
/// use winnow::prelude::*;
///
-/// fn success(input: &str) -> IResult<&str, ()> {
+/// fn success(input: &mut &str) -> PResult<()> {
/// let output = ();
-/// Ok((input, output))
+/// Ok(output)
/// }
///
-/// let (input, output) = success.parse_next("Hello").unwrap();
+/// let (input, output) = success.parse_peek("Hello").unwrap();
/// assert_eq!(input, "Hello"); // We didn't consume any input
/// ```
///
@@ -23,14 +23,14 @@ use crate::stream::{AsChar, Compare, Location, Offset, ParseSlice, Stream, Strea
/// ```rust
/// use winnow::prelude::*;
///
-/// fn success<O: Clone>(output: O) -> impl FnMut(&str) -> IResult<&str, O> {
-/// move |input: &str| {
+/// fn success<O: Clone>(output: O) -> impl FnMut(&mut &str) -> PResult<O> {
+/// move |input: &mut &str| {
/// let output = output.clone();
-/// Ok((input, output))
+/// Ok(output)
/// }
/// }
///
-/// let (input, output) = success("World").parse_next("Hello").unwrap();
+/// let (input, output) = success("World").parse_peek("Hello").unwrap();
/// assert_eq!(input, "Hello"); // We didn't consume any input
/// assert_eq!(output, "World");
/// ```
@@ -41,23 +41,49 @@ use crate::stream::{AsChar, Compare, Location, Offset, ParseSlice, Stream, Strea
pub trait Parser<I, O, E> {
/// Parse all of `input`, generating `O` from it
#[inline]
- fn parse(&mut self, input: I) -> Result<O, E>
+ fn parse(&mut self, mut input: I) -> Result<O, ParseError<I, E>>
where
+ Self: core::marker::Sized,
I: Stream,
// Force users to deal with `Incomplete` when `StreamIsPartial<true>`
I: StreamIsPartial,
I: Clone,
- E: ParseError<I>,
+ E: ParserError<I>,
{
- #![allow(deprecated)]
- use crate::error::FinishIResult;
- self.parse_next(input).finish()
+ debug_assert!(
+ !I::is_partial_supported(),
+ "partial streams need to handle `ErrMode::Incomplete`"
+ );
+
+ let start = input.checkpoint();
+ let (o, _) = (self.by_ref(), crate::combinator::eof)
+ .parse_next(&mut input)
+ .map_err(|e| {
+ let e = e
+ .into_inner()
+ .expect("complete parsers should not report `ErrMode::Incomplete(_)`");
+ ParseError::new(input, start, e)
+ })?;
+ Ok(o)
}
/// Take tokens from the [`Stream`], turning it into the output
///
/// This includes advancing the [`Stream`] to the next location.
- fn parse_next(&mut self, input: I) -> IResult<I, O, E>;
+ ///
+ /// On error, `input` will be left pointing at the error location.
+ fn parse_next(&mut self, input: &mut I) -> PResult<O, E>;
+
+ /// Take tokens from the [`Stream`], turning it into the output
+ ///
+ /// This includes advancing the [`Stream`] to the next location.
+ #[inline(always)]
+ fn parse_peek(&mut self, mut input: I) -> IResult<I, O, E> {
+ match self.parse_next(&mut input) {
+ Ok(o) => Ok((input, o)),
+ Err(err) => Err(err),
+ }
+ }
/// Treat `&mut Self` as a parser
///
@@ -70,18 +96,17 @@ pub trait Parser<I, O, E> {
/// [`Parser::complete_err`]:
/// ```rust,compile_fail
/// # use winnow::prelude::*;
- /// # use winnow::IResult;
/// # use winnow::Parser;
- /// # use winnow::error::ParseError;
+ /// # use winnow::error::ParserError;
/// # use winnow::binary::length_data;
- /// pub fn length_value<'i, O, E: ParseError<&'i [u8]>>(
+ /// pub fn length_value<'i, O, E: ParserError<&'i [u8]>>(
/// mut f: impl Parser<&'i [u8], usize, E>,
/// mut g: impl Parser<&'i [u8], O, E>
- /// ) -> impl FnMut(&'i [u8]) -> IResult<&'i [u8], O, E> {
- /// move |i: &'i [u8]| {
- /// let (i, data) = length_data(f).parse_next(i)?;
- /// let (_, o) = g.complete().parse_next(data)?;
- /// Ok((i, o))
+ /// ) -> impl Parser<&'i [u8], O, E> {
+ /// move |i: &mut &'i [u8]| {
+ /// let mut data = length_data(f).parse_next(i)?;
+ /// let o = g.complete_err().parse_next(&mut data)?;
+ /// Ok(o)
/// }
/// }
/// ```
@@ -89,18 +114,17 @@ pub trait Parser<I, O, E> {
/// By adding `by_ref`, we can make this work:
/// ```rust
/// # use winnow::prelude::*;
- /// # use winnow::IResult;
/// # use winnow::Parser;
- /// # use winnow::error::ParseError;
+ /// # use winnow::error::ParserError;
/// # use winnow::binary::length_data;
- /// pub fn length_value<'i, O, E: ParseError<&'i [u8]>>(
+ /// pub fn length_value<'i, O, E: ParserError<&'i [u8]>>(
/// mut f: impl Parser<&'i [u8], usize, E>,
/// mut g: impl Parser<&'i [u8], O, E>
- /// ) -> impl FnMut(&'i [u8]) -> IResult<&'i [u8], O, E> {
- /// move |i: &'i [u8]| {
- /// let (i, data) = length_data(f.by_ref()).parse_next(i)?;
- /// let (_, o) = g.by_ref().complete_err().parse_next(data)?;
- /// Ok((i, o))
+ /// ) -> impl Parser<&'i [u8], O, E> {
+ /// move |i: &mut &'i [u8]| {
+ /// let mut data = length_data(f.by_ref()).parse_next(i)?;
+ /// let o = g.by_ref().complete_err().parse_next(&mut data)?;
+ /// Ok(o)
/// }
/// }
/// ```
@@ -116,14 +140,14 @@ pub trait Parser<I, O, E> {
/// # Example
///
/// ```rust
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult, Parser};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError, Parser};
/// use winnow::ascii::alpha1;
/// # fn main() {
///
/// let mut parser = alpha1.value(1234);
///
- /// assert_eq!(parser.parse_next("abcd"), Ok(("", 1234)));
- /// assert_eq!(parser.parse_next("123abcd;"), Err(ErrMode::Backtrack(Error::new("123abcd;", ErrorKind::Slice))));
+ /// assert_eq!(parser.parse_peek("abcd"), Ok(("", 1234)));
+ /// assert_eq!(parser.parse_peek("123abcd;"), Err(ErrMode::Backtrack(InputError::new("123abcd;", ErrorKind::Slice))));
/// # }
/// ```
#[doc(alias = "to")]
@@ -140,14 +164,14 @@ pub trait Parser<I, O, E> {
/// # Example
///
/// ```rust
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult, Parser};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError, Parser};
/// use winnow::ascii::alpha1;
/// # fn main() {
///
/// let mut parser = alpha1.void();
///
- /// assert_eq!(parser.parse_next("abcd"), Ok(("", ())));
- /// assert_eq!(parser.parse_next("123abcd;"), Err(ErrMode::Backtrack(Error::new("123abcd;", ErrorKind::Slice))));
+ /// assert_eq!(parser.parse_peek("abcd"), Ok(("", ())));
+ /// assert_eq!(parser.parse_peek("123abcd;"), Err(ErrMode::Backtrack(InputError::new("123abcd;", ErrorKind::Slice))));
/// # }
/// ```
fn void(self) -> Void<Self, I, O, E>
@@ -162,19 +186,19 @@ pub trait Parser<I, O, E> {
/// # Example
///
/// ```rust
- /// # use winnow::IResult;
- /// # use winnow::Parser;
+ /// # use winnow::prelude::*;
+ /// # use winnow::error::InputError;
/// use winnow::ascii::alpha1;
/// # fn main() {
///
- /// fn parser1(i: &str) -> IResult<&str, &str> {
+ /// fn parser1<'s>(i: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
/// alpha1(i)
/// }
///
/// let mut parser2 = parser1.output_into();
///
/// // the parser converts the &str output of the child parser into a Vec<u8>
- /// let bytes: IResult<&str, Vec<u8>> = parser2.parse_next("abcd");
+ /// let bytes: IResult<&str, Vec<u8>> = parser2.parse_peek("abcd");
/// assert_eq!(bytes, Ok(("", vec![97, 98, 99, 100])));
/// # }
/// ```
@@ -191,22 +215,22 @@ pub trait Parser<I, O, E> {
/// # Example
///
/// ```rust
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult, Parser};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError, Parser};
/// use winnow::ascii::{alpha1};
/// use winnow::combinator::separated_pair;
/// # fn main() {
///
/// let mut parser = separated_pair(alpha1, ',', alpha1).recognize();
///
- /// assert_eq!(parser.parse_next("abcd,efgh"), Ok(("", "abcd,efgh")));
- /// assert_eq!(parser.parse_next("abcd;"),Err(ErrMode::Backtrack(Error::new(";", ErrorKind::Verify))));
+ /// assert_eq!(parser.parse_peek("abcd,efgh"), Ok(("", "abcd,efgh")));
+ /// assert_eq!(parser.parse_peek("abcd;"),Err(ErrMode::Backtrack(InputError::new(";", ErrorKind::Verify))));
/// # }
/// ```
#[doc(alias = "concat")]
fn recognize(self) -> Recognize<Self, I, O, E>
where
Self: core::marker::Sized,
- I: Stream + Offset,
+ I: Stream,
{
Recognize::new(self)
}
@@ -225,36 +249,33 @@ pub trait Parser<I, O, E> {
///
/// ```rust
/// # use winnow::prelude::*;
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError};
/// use winnow::ascii::{alpha1};
/// use winnow::token::tag;
/// use winnow::combinator::separated_pair;
///
- /// fn inner_parser(input: &str) -> IResult<&str, bool> {
+ /// fn inner_parser<'s>(input: &mut &'s str) -> PResult<bool, InputError<&'s str>> {
/// "1234".value(true).parse_next(input)
/// }
///
- /// # fn main() {
- ///
/// let mut consumed_parser = separated_pair(alpha1, ',', alpha1).value(true).with_recognized();
///
- /// assert_eq!(consumed_parser.parse_next("abcd,efgh1"), Ok(("1", (true, "abcd,efgh"))));
- /// assert_eq!(consumed_parser.parse_next("abcd;"),Err(ErrMode::Backtrack(Error::new(";", ErrorKind::Verify))));
+ /// assert_eq!(consumed_parser.parse_peek("abcd,efgh1"), Ok(("1", (true, "abcd,efgh"))));
+ /// assert_eq!(consumed_parser.parse_peek("abcd;"),Err(ErrMode::Backtrack(InputError::new(";", ErrorKind::Verify))));
///
/// // the second output (representing the consumed input)
/// // should be the same as that of the `recognize` parser.
/// let mut recognize_parser = inner_parser.recognize();
/// let mut consumed_parser = inner_parser.with_recognized().map(|(output, consumed)| consumed);
///
- /// assert_eq!(recognize_parser.parse_next("1234"), consumed_parser.parse_next("1234"));
- /// assert_eq!(recognize_parser.parse_next("abcd"), consumed_parser.parse_next("abcd"));
- /// # }
+ /// assert_eq!(recognize_parser.parse_peek("1234"), consumed_parser.parse_peek("1234"));
+ /// assert_eq!(recognize_parser.parse_peek("abcd"), consumed_parser.parse_peek("abcd"));
/// ```
#[doc(alias = "consumed")]
fn with_recognized(self) -> WithRecognized<Self, I, O, E>
where
Self: core::marker::Sized,
- I: Stream + Offset,
+ I: Stream,
{
WithRecognized::new(self)
}
@@ -265,7 +286,7 @@ pub trait Parser<I, O, E> {
///
/// ```rust
/// # use winnow::prelude::*;
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, stream::Stream};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError, stream::Stream};
/// use winnow::stream::Located;
/// use winnow::ascii::alpha1;
/// use winnow::combinator::separated_pair;
@@ -273,7 +294,7 @@ pub trait Parser<I, O, E> {
/// let mut parser = separated_pair(alpha1.span(), ',', alpha1.span());
///
/// assert_eq!(parser.parse(Located::new("abcd,efgh")), Ok((0..4, 5..9)));
- /// assert_eq!(parser.parse_next(Located::new("abcd;")),Err(ErrMode::Backtrack(Error::new(Located::new("abcd;").next_slice(4).0, ErrorKind::Verify))));
+ /// assert_eq!(parser.parse_peek(Located::new("abcd;")),Err(ErrMode::Backtrack(InputError::new(Located::new("abcd;").peek_slice(4).0, ErrorKind::Verify))));
/// ```
fn span(self) -> Span<Self, I, O, E>
where
@@ -297,13 +318,13 @@ pub trait Parser<I, O, E> {
///
/// ```rust
/// # use winnow::prelude::*;
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult, stream::Stream};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError, stream::Stream};
/// use winnow::stream::Located;
/// use winnow::ascii::alpha1;
/// use winnow::token::tag;
/// use winnow::combinator::separated_pair;
///
- /// fn inner_parser(input: Located<&str>) -> IResult<Located<&str>, bool> {
+ /// fn inner_parser<'s>(input: &mut Located<&'s str>) -> PResult<bool, InputError<Located<&'s str>>> {
/// "1234".value(true).parse_next(input)
/// }
///
@@ -312,15 +333,15 @@ pub trait Parser<I, O, E> {
/// let mut consumed_parser = separated_pair(alpha1.value(1).with_span(), ',', alpha1.value(2).with_span());
///
/// assert_eq!(consumed_parser.parse(Located::new("abcd,efgh")), Ok(((1, 0..4), (2, 5..9))));
- /// assert_eq!(consumed_parser.parse_next(Located::new("abcd;")),Err(ErrMode::Backtrack(Error::new(Located::new("abcd;").next_slice(4).0, ErrorKind::Verify))));
+ /// assert_eq!(consumed_parser.parse_peek(Located::new("abcd;")),Err(ErrMode::Backtrack(InputError::new(Located::new("abcd;").peek_slice(4).0, ErrorKind::Verify))));
///
/// // the second output (representing the consumed input)
/// // should be the same as that of the `span` parser.
/// let mut recognize_parser = inner_parser.span();
/// let mut consumed_parser = inner_parser.with_span().map(|(output, consumed)| consumed);
///
- /// assert_eq!(recognize_parser.parse_next(Located::new("1234")), consumed_parser.parse_next(Located::new("1234")));
- /// assert_eq!(recognize_parser.parse_next(Located::new("abcd")), consumed_parser.parse_next(Located::new("abcd")));
+ /// assert_eq!(recognize_parser.parse_peek(Located::new("1234")), consumed_parser.parse_peek(Located::new("1234")));
+ /// assert_eq!(recognize_parser.parse_peek(Located::new("abcd")), consumed_parser.parse_peek(Located::new("abcd")));
/// # }
/// ```
fn with_span(self) -> WithSpan<Self, I, O, E>
@@ -336,17 +357,17 @@ pub trait Parser<I, O, E> {
/// # Example
///
/// ```rust
- /// use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult,Parser};
+ /// use winnow::{error::ErrMode,error::ErrorKind, error::InputError, Parser};
/// use winnow::ascii::digit1;
/// # fn main() {
///
/// let mut parser = digit1.map(|s: &str| s.len());
///
/// // the parser will count how many characters were returned by digit1
- /// assert_eq!(parser.parse_next("123456"), Ok(("", 6)));
+ /// assert_eq!(parser.parse_peek("123456"), Ok(("", 6)));
///
/// // this will fail if digit1 fails
- /// assert_eq!(parser.parse_next("abc"), Err(ErrMode::Backtrack(Error::new("abc", ErrorKind::Slice))));
+ /// assert_eq!(parser.parse_peek("abc"), Err(ErrMode::Backtrack(InputError::new("abc", ErrorKind::Slice))));
/// # }
/// ```
fn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
@@ -362,63 +383,51 @@ pub trait Parser<I, O, E> {
/// # Example
///
/// ```rust
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult, Parser};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError, Parser};
/// use winnow::ascii::digit1;
/// # fn main() {
///
/// let mut parse = digit1.try_map(|s: &str| s.parse::<u8>());
///
/// // the parser will convert the result of digit1 to a number
- /// assert_eq!(parse.parse_next("123"), Ok(("", 123)));
+ /// assert_eq!(parse.parse_peek("123"), Ok(("", 123)));
///
/// // this will fail if digit1 fails
- /// assert_eq!(parse.parse_next("abc"), Err(ErrMode::Backtrack(Error::new("abc", ErrorKind::Slice))));
+ /// assert_eq!(parse.parse_peek("abc"), Err(ErrMode::Backtrack(InputError::new("abc", ErrorKind::Slice))));
///
/// // this will fail if the mapped function fails (a `u8` is too small to hold `123456`)
- /// assert_eq!(parse.parse_next("123456"), Err(ErrMode::Backtrack(Error::new("123456", ErrorKind::Verify))));
+ /// assert_eq!(parse.parse_peek("123456"), Err(ErrMode::Backtrack(InputError::new("123456", ErrorKind::Verify))));
/// # }
/// ```
fn try_map<G, O2, E2>(self, map: G) -> TryMap<Self, G, I, O, O2, E, E2>
where
Self: core::marker::Sized,
G: FnMut(O) -> Result<O2, E2>,
- I: Clone,
+ I: Stream,
E: FromExternalError<I, E2>,
{
TryMap::new(self, map)
}
- /// Deprecated, see [`Parser::try_map`]
- #[deprecated(since = "0.4.2", note = "Replaced with `Parser::try_map`")]
- fn map_res<G, O2, E2>(self, map: G) -> MapRes<Self, G, I, O, O2, E, E2>
- where
- Self: core::marker::Sized,
- G: FnMut(O) -> Result<O2, E2>,
- I: Clone,
- E: FromExternalError<I, E2>,
- {
- self.try_map(map)
- }
-
/// Apply both [`Parser::verify`] and [`Parser::map`].
///
/// # Example
///
/// ```rust
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult, Parser};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError, Parser};
/// use winnow::ascii::digit1;
/// # fn main() {
///
/// let mut parse = digit1.verify_map(|s: &str| s.parse::<u8>().ok());
///
/// // the parser will convert the result of digit1 to a number
- /// assert_eq!(parse.parse_next("123"), Ok(("", 123)));
+ /// assert_eq!(parse.parse_peek("123"), Ok(("", 123)));
///
/// // this will fail if digit1 fails
- /// assert_eq!(parse.parse_next("abc"), Err(ErrMode::Backtrack(Error::new("abc", ErrorKind::Slice))));
+ /// assert_eq!(parse.parse_peek("abc"), Err(ErrMode::Backtrack(InputError::new("abc", ErrorKind::Slice))));
///
/// // this will fail if the mapped function fails (a `u8` is too small to hold `123456`)
- /// assert_eq!(parse.parse_next("123456"), Err(ErrMode::Backtrack(Error::new("123456", ErrorKind::Verify))));
+ /// assert_eq!(parse.parse_peek("123456"), Err(ErrMode::Backtrack(InputError::new("123456", ErrorKind::Verify))));
/// # }
/// ```
#[doc(alias = "satisfy_map")]
@@ -428,8 +437,8 @@ pub trait Parser<I, O, E> {
where
Self: core::marker::Sized,
G: FnMut(O) -> Option<O2>,
- I: Clone,
- E: ParseError<I>,
+ I: Stream,
+ E: ParserError<I>,
{
VerifyMap::new(self, map)
}
@@ -439,32 +448,32 @@ pub trait Parser<I, O, E> {
/// # Example
///
/// ```rust
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult, Parser};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError, PResult, Parser};
/// use winnow::token::take;
/// use winnow::binary::u8;
///
- /// fn length_data(input: &[u8]) -> IResult<&[u8], &[u8]> {
+ /// fn length_data<'s>(input: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> {
/// u8.flat_map(take).parse_next(input)
/// }
///
- /// assert_eq!(length_data.parse_next(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..])));
- /// assert_eq!(length_data.parse_next(&[4, 0, 1, 2][..]), Err(ErrMode::Backtrack(Error::new(&[0, 1, 2][..], ErrorKind::Slice))));
+ /// assert_eq!(length_data.parse_peek(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..])));
+ /// assert_eq!(length_data.parse_peek(&[4, 0, 1, 2][..]), Err(ErrMode::Backtrack(InputError::new(&[0, 1, 2][..], ErrorKind::Slice))));
/// ```
///
/// which is the same as
/// ```rust
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult, Parser};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError, PResult, Parser};
/// use winnow::token::take;
/// use winnow::binary::u8;
///
- /// fn length_data(input: &[u8]) -> IResult<&[u8], &[u8]> {
- /// let (input, length) = u8.parse_next(input)?;
- /// let (input, data) = take(length).parse_next(input)?;
- /// Ok((input, data))
+ /// fn length_data<'s>(input: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> {
+ /// let length = u8.parse_next(input)?;
+ /// let data = take(length).parse_next(input)?;
+ /// Ok(data)
/// }
///
- /// assert_eq!(length_data.parse_next(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..])));
- /// assert_eq!(length_data.parse_next(&[4, 0, 1, 2][..]), Err(ErrMode::Backtrack(Error::new(&[0, 1, 2][..], ErrorKind::Slice))));
+ /// assert_eq!(length_data.parse_peek(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..])));
+ /// assert_eq!(length_data.parse_peek(&[4, 0, 1, 2][..]), Err(ErrMode::Backtrack(InputError::new(&[0, 1, 2][..], ErrorKind::Slice))));
/// ```
fn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
where
@@ -480,16 +489,16 @@ pub trait Parser<I, O, E> {
/// # Example
///
/// ```rust
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult, Parser};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError, Parser};
/// use winnow::ascii::digit1;
/// use winnow::token::take;
/// # fn main() {
///
/// let mut digits = take(5u8).and_then(digit1);
///
- /// assert_eq!(digits.parse_next("12345"), Ok(("", "12345")));
- /// assert_eq!(digits.parse_next("123ab"), Ok(("", "123")));
- /// assert_eq!(digits.parse_next("123"), Err(ErrMode::Backtrack(Error::new("123", ErrorKind::Slice))));
+ /// assert_eq!(digits.parse_peek("12345"), Ok(("", "12345")));
+ /// assert_eq!(digits.parse_peek("123ab"), Ok(("", "123")));
+ /// assert_eq!(digits.parse_peek("123"), Err(ErrMode::Backtrack(InputError::new("123", ErrorKind::Slice))));
/// # }
/// ```
fn and_then<G, O2>(self, inner: G) -> AndThen<Self, G, I, O, O2, E>
@@ -497,6 +506,7 @@ pub trait Parser<I, O, E> {
Self: core::marker::Sized,
G: Parser<O, O2, E>,
O: StreamIsPartial,
+ I: Stream,
{
AndThen::new(self, inner)
}
@@ -507,18 +517,18 @@ pub trait Parser<I, O, E> {
///
/// ```rust
/// # use winnow::prelude::*;
- /// use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult,Parser};
+ /// use winnow::{error::ErrMode,error::ErrorKind, error::InputError, Parser};
/// use winnow::ascii::digit1;
///
- /// fn parser(input: &str) -> IResult<&str, u64> {
+ /// fn parser<'s>(input: &mut &'s str) -> PResult<u64, InputError<&'s str>> {
/// digit1.parse_to().parse_next(input)
/// }
///
/// // the parser will count how many characters were returned by digit1
- /// assert_eq!(parser.parse_next("123456"), Ok(("", 123456)));
+ /// assert_eq!(parser.parse_peek("123456"), Ok(("", 123456)));
///
/// // this will fail if digit1 fails
- /// assert_eq!(parser.parse_next("abc"), Err(ErrMode::Backtrack(Error::new("abc", ErrorKind::Slice))));
+ /// assert_eq!(parser.parse_peek("abc"), Err(ErrMode::Backtrack(InputError::new("abc", ErrorKind::Slice))));
/// ```
#[doc(alias = "from_str")]
fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>
@@ -526,7 +536,7 @@ pub trait Parser<I, O, E> {
Self: core::marker::Sized,
I: Stream,
O: ParseSlice<O2>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
ParseTo::new(self)
}
@@ -539,15 +549,15 @@ pub trait Parser<I, O, E> {
/// # Example
///
/// ```rust
- /// # use winnow::{error::ErrMode,error::ErrorKind, error::Error, IResult, Parser};
+ /// # use winnow::{error::ErrMode,error::ErrorKind, error::InputError, Parser};
/// # use winnow::ascii::alpha1;
/// # fn main() {
///
/// let mut parser = alpha1.verify(|s: &str| s.len() == 4);
///
- /// assert_eq!(parser.parse_next("abcd"), Ok(("", "abcd")));
- /// assert_eq!(parser.parse_next("abcde"), Err(ErrMode::Backtrack(Error::new("abcde", ErrorKind::Verify))));
- /// assert_eq!(parser.parse_next("123abcd;"),Err(ErrMode::Backtrack(Error::new("123abcd;", ErrorKind::Slice))));
+ /// assert_eq!(parser.parse_peek("abcd"), Ok(("", "abcd")));
+ /// assert_eq!(parser.parse_peek("abcde"), Err(ErrMode::Backtrack(InputError::new("abcde", ErrorKind::Verify))));
+ /// assert_eq!(parser.parse_peek("123abcd;"),Err(ErrMode::Backtrack(InputError::new("123abcd;", ErrorKind::Slice))));
/// # }
/// ```
#[doc(alias = "satisfy")]
@@ -556,10 +566,10 @@ pub trait Parser<I, O, E> {
where
Self: core::marker::Sized,
G: Fn(&O2) -> bool,
- I: Clone,
+ I: Stream,
O: crate::lib::std::borrow::Borrow<O2>,
O2: ?Sized,
- E: ParseError<I>,
+ E: ParserError<I>,
{
Verify::new(self, filter)
}
@@ -573,7 +583,7 @@ pub trait Parser<I, O, E> {
where
Self: core::marker::Sized,
I: Stream,
- E: ContextError<I, C>,
+ E: AddContext<I, C>,
C: Clone + crate::lib::std::fmt::Debug,
{
Context::new(self, context)
@@ -584,14 +594,14 @@ pub trait Parser<I, O, E> {
/// # Example
///
/// ```rust
- /// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, stream::Partial, Parser};
+ /// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, stream::Partial, Parser};
/// # use winnow::token::take;
/// # fn main() {
///
/// let mut parser = take(5u8).complete_err();
///
- /// assert_eq!(parser.parse_next(Partial::new("abcdefg")), Ok((Partial::new("fg"), "abcde")));
- /// assert_eq!(parser.parse_next(Partial::new("abcd")), Err(ErrMode::Backtrack(Error::new(Partial::new("abcd"), ErrorKind::Complete))));
+ /// assert_eq!(parser.parse_peek(Partial::new("abcdefg")), Ok((Partial::new("fg"), "abcde")));
+ /// assert_eq!(parser.parse_peek(Partial::new("abcd")), Err(ErrMode::Backtrack(InputError::new(Partial::new("abcd"), ErrorKind::Complete))));
/// # }
/// ```
fn complete_err(self) -> CompleteErr<Self>
@@ -613,10 +623,11 @@ pub trait Parser<I, O, E> {
impl<'a, I, O, E, F> Parser<I, O, E> for F
where
- F: FnMut(I) -> IResult<I, O, E> + 'a,
+ F: FnMut(&mut I) -> PResult<O, E> + 'a,
+ I: Stream,
{
#[inline(always)]
- fn parse_next(&mut self, i: I) -> IResult<I, O, E> {
+ fn parse_next(&mut self, i: &mut I) -> PResult<O, E> {
self(i)
}
}
@@ -627,23 +638,23 @@ where
///
/// ```
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::{ErrorKind, Error}};
-/// fn parser(i: &[u8]) -> IResult<&[u8], u8> {
+/// # use winnow::{error::ErrMode, error::{ErrorKind, InputError}};
+/// fn parser<'s>(i: &mut &'s [u8]) -> PResult<u8, InputError<&'s [u8]>> {
/// b'a'.parse_next(i)
/// }
-/// assert_eq!(parser(&b"abc"[..]), Ok((&b"bc"[..], b'a')));
-/// assert_eq!(parser(&b" abc"[..]), Err(ErrMode::Backtrack(Error::new(&b" abc"[..], ErrorKind::Verify))));
-/// assert_eq!(parser(&b"bc"[..]), Err(ErrMode::Backtrack(Error::new(&b"bc"[..], ErrorKind::Verify))));
-/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&b""[..], ErrorKind::Token))));
+/// assert_eq!(parser.parse_peek(&b"abc"[..]), Ok((&b"bc"[..], b'a')));
+/// assert_eq!(parser.parse_peek(&b" abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b" abc"[..], ErrorKind::Verify))));
+/// assert_eq!(parser.parse_peek(&b"bc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"bc"[..], ErrorKind::Verify))));
+/// assert_eq!(parser.parse_peek(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&b""[..], ErrorKind::Token))));
/// ```
impl<I, E> Parser<I, u8, E> for u8
where
I: StreamIsPartial,
I: Stream<Token = u8>,
- E: ParseError<I>,
+ E: ParserError<I>,
{
#[inline(always)]
- fn parse_next(&mut self, i: I) -> IResult<I, u8, E> {
+ fn parse_next(&mut self, i: &mut I) -> PResult<u8, E> {
crate::token::one_of(*self).parse_next(i)
}
}
@@ -654,24 +665,24 @@ where
///
/// ```
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::{ErrorKind, Error}};
-/// fn parser(i: &str) -> IResult<&str, char> {
+/// # use winnow::{error::ErrMode, error::{ErrorKind, InputError}};
+/// fn parser<'s>(i: &mut &'s str) -> PResult<char, InputError<&'s str>> {
/// 'a'.parse_next(i)
/// }
-/// assert_eq!(parser("abc"), Ok(("bc", 'a')));
-/// assert_eq!(parser(" abc"), Err(ErrMode::Backtrack(Error::new(" abc", ErrorKind::Verify))));
-/// assert_eq!(parser("bc"), Err(ErrMode::Backtrack(Error::new("bc", ErrorKind::Verify))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(parser.parse_peek("abc"), Ok(("bc", 'a')));
+/// assert_eq!(parser.parse_peek(" abc"), Err(ErrMode::Backtrack(InputError::new(" abc", ErrorKind::Verify))));
+/// assert_eq!(parser.parse_peek("bc"), Err(ErrMode::Backtrack(InputError::new("bc", ErrorKind::Verify))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
/// ```
impl<I, E> Parser<I, <I as Stream>::Token, E> for char
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
- E: ParseError<I>,
+ <I as Stream>::Token: AsChar + Clone,
+ E: ParserError<I>,
{
#[inline(always)]
- fn parse_next(&mut self, i: I) -> IResult<I, <I as Stream>::Token, E> {
+ fn parse_next(&mut self, i: &mut I) -> PResult<<I as Stream>::Token, E> {
crate::token::one_of(*self).parse_next(i)
}
}
@@ -681,26 +692,26 @@ where
/// # Example
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::combinator::alt;
/// # use winnow::token::take;
///
-/// fn parser(s: &[u8]) -> IResult<&[u8], &[u8]> {
+/// fn parser<'s>(s: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> {
/// alt((&"Hello"[..], take(5usize))).parse_next(s)
/// }
///
-/// assert_eq!(parser(&b"Hello, World!"[..]), Ok((&b", World!"[..], &b"Hello"[..])));
-/// assert_eq!(parser(&b"Something"[..]), Ok((&b"hing"[..], &b"Somet"[..])));
-/// assert_eq!(parser(&b"Some"[..]), Err(ErrMode::Backtrack(Error::new(&b"Some"[..], ErrorKind::Slice))));
-/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&b""[..], ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(&b"Hello, World!"[..]), Ok((&b", World!"[..], &b"Hello"[..])));
+/// assert_eq!(parser.parse_peek(&b"Something"[..]), Ok((&b"hing"[..], &b"Somet"[..])));
+/// assert_eq!(parser.parse_peek(&b"Some"[..]), Err(ErrMode::Backtrack(InputError::new(&b"Some"[..], ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&b""[..], ErrorKind::Slice))));
/// ```
-impl<'s, I, E: ParseError<I>> Parser<I, <I as Stream>::Slice, E> for &'s [u8]
+impl<'s, I, E: ParserError<I>> Parser<I, <I as Stream>::Slice, E> for &'s [u8]
where
I: Compare<&'s [u8]> + StreamIsPartial,
I: Stream,
{
#[inline(always)]
- fn parse_next(&mut self, i: I) -> IResult<I, <I as Stream>::Slice, E> {
+ fn parse_next(&mut self, i: &mut I) -> PResult<<I as Stream>::Slice, E> {
crate::token::tag(*self).parse_next(i)
}
}
@@ -710,26 +721,26 @@ where
/// # Example
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::combinator::alt;
/// # use winnow::token::take;
///
-/// fn parser(s: &[u8]) -> IResult<&[u8], &[u8]> {
+/// fn parser<'s>(s: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> {
/// alt((b"Hello", take(5usize))).parse_next(s)
/// }
///
-/// assert_eq!(parser(&b"Hello, World!"[..]), Ok((&b", World!"[..], &b"Hello"[..])));
-/// assert_eq!(parser(&b"Something"[..]), Ok((&b"hing"[..], &b"Somet"[..])));
-/// assert_eq!(parser(&b"Some"[..]), Err(ErrMode::Backtrack(Error::new(&b"Some"[..], ErrorKind::Slice))));
-/// assert_eq!(parser(&b""[..]), Err(ErrMode::Backtrack(Error::new(&b""[..], ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(&b"Hello, World!"[..]), Ok((&b", World!"[..], &b"Hello"[..])));
+/// assert_eq!(parser.parse_peek(&b"Something"[..]), Ok((&b"hing"[..], &b"Somet"[..])));
+/// assert_eq!(parser.parse_peek(&b"Some"[..]), Err(ErrMode::Backtrack(InputError::new(&b"Some"[..], ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&b""[..], ErrorKind::Slice))));
/// ```
-impl<'s, I, E: ParseError<I>, const N: usize> Parser<I, <I as Stream>::Slice, E> for &'s [u8; N]
+impl<'s, I, E: ParserError<I>, const N: usize> Parser<I, <I as Stream>::Slice, E> for &'s [u8; N]
where
I: Compare<&'s [u8; N]> + StreamIsPartial,
I: Stream,
{
#[inline(always)]
- fn parse_next(&mut self, i: I) -> IResult<I, <I as Stream>::Slice, E> {
+ fn parse_next(&mut self, i: &mut I) -> PResult<<I as Stream>::Slice, E> {
crate::token::tag(*self).parse_next(i)
}
}
@@ -739,51 +750,51 @@ where
/// # Example
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}};
/// # use winnow::combinator::alt;
/// # use winnow::token::take;
///
-/// fn parser(s: &str) -> IResult<&str, &str> {
+/// fn parser<'s>(s: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
/// alt(("Hello", take(5usize))).parse_next(s)
/// }
///
-/// assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
-/// assert_eq!(parser("Something"), Ok(("hing", "Somet")));
-/// assert_eq!(parser("Some"), Err(ErrMode::Backtrack(Error::new("Some", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("Hello, World!"), Ok((", World!", "Hello")));
+/// assert_eq!(parser.parse_peek("Something"), Ok(("hing", "Somet")));
+/// assert_eq!(parser.parse_peek("Some"), Err(ErrMode::Backtrack(InputError::new("Some", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
-impl<'s, I, E: ParseError<I>> Parser<I, <I as Stream>::Slice, E> for &'s str
+impl<'s, I, E: ParserError<I>> Parser<I, <I as Stream>::Slice, E> for &'s str
where
I: Compare<&'s str> + StreamIsPartial,
I: Stream,
{
#[inline(always)]
- fn parse_next(&mut self, i: I) -> IResult<I, <I as Stream>::Slice, E> {
+ fn parse_next(&mut self, i: &mut I) -> PResult<<I as Stream>::Slice, E> {
crate::token::tag(*self).parse_next(i)
}
}
-impl<I, E: ParseError<I>> Parser<I, (), E> for () {
+impl<I, E: ParserError<I>> Parser<I, (), E> for () {
#[inline(always)]
- fn parse_next(&mut self, i: I) -> IResult<I, (), E> {
- Ok((i, ()))
+ fn parse_next(&mut self, _i: &mut I) -> PResult<(), E> {
+ Ok(())
}
}
macro_rules! impl_parser_for_tuple {
($($parser:ident $output:ident),+) => (
#[allow(non_snake_case)]
- impl<I, $($output),+, E: ParseError<I>, $($parser),+> Parser<I, ($($output),+,), E> for ($($parser),+,)
+ impl<I, $($output),+, E: ParserError<I>, $($parser),+> Parser<I, ($($output),+,), E> for ($($parser),+,)
where
$($parser: Parser<I, $output, E>),+
{
#[inline(always)]
- fn parse_next(&mut self, i: I) -> IResult<I, ($($output),+,), E> {
+ fn parse_next(&mut self, i: &mut I) -> PResult<($($output),+,), E> {
let ($(ref mut $parser),+,) = *self;
- $(let(i, $output) = $parser.parse_next(i)?;)+
+ $(let $output = $parser.parse_next(i)?;)+
- Ok((i, ($($output),+,)))
+ Ok(($($output),+,))
}
}
)
@@ -832,8 +843,25 @@ use alloc::boxed::Box;
#[cfg(feature = "alloc")]
impl<'a, I, O, E> Parser<I, O, E> for Box<dyn Parser<I, O, E> + 'a> {
#[inline(always)]
- fn parse_next(&mut self, input: I) -> IResult<I, O, E> {
- (**self).parse_next(input)
+ fn parse_next(&mut self, i: &mut I) -> PResult<O, E> {
+ (**self).parse_next(i)
+ }
+}
+
+/// Convert a [`Parser::parse_peek`] style parse function to be a [`Parser`]
+#[inline(always)]
+pub fn unpeek<'a, I, O, E>(
+ mut peek: impl FnMut(I) -> IResult<I, O, E> + 'a,
+) -> impl FnMut(&mut I) -> PResult<O, E>
+where
+ I: Clone,
+{
+ move |input| match peek((*input).clone()) {
+ Ok((i, o)) => {
+ *input = i;
+ Ok(o)
+ }
+ Err(err) => Err(err),
}
}
@@ -842,8 +870,8 @@ mod tests {
use super::*;
use crate::binary::be_u16;
use crate::error::ErrMode;
- use crate::error::Error;
use crate::error::ErrorKind;
+ use crate::error::InputError;
use crate::error::Needed;
use crate::token::take;
use crate::Partial;
@@ -878,13 +906,13 @@ mod tests {
use crate::error::ErrorKind;
let mut parser = (alpha1,);
- assert_eq!(parser.parse_next("abc123def"), Ok(("123def", ("abc",))));
+ assert_eq!(parser.parse_peek("abc123def"), Ok(("123def", ("abc",))));
assert_eq!(
- parser.parse_next("123def"),
- Err(ErrMode::Backtrack(Error {
- input: "123def",
- kind: ErrorKind::Slice
- }))
+ parser.parse_peek("123def"),
+ Err(ErrMode::Backtrack(InputError::new(
+ "123def",
+ ErrorKind::Slice
+ )))
);
}
@@ -892,7 +920,7 @@ mod tests {
fn tuple_test() {
#[allow(clippy::type_complexity)]
fn tuple_3(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, (u16, &[u8], &[u8])> {
- (be_u16, take(3u8), "fg").parse_next(i)
+ (be_u16, take(3u8), "fg").parse_peek(i)
}
assert_eq!(
@@ -913,7 +941,7 @@ mod tests {
assert_eq!(
tuple_3(Partial::new(&b"abcdejk"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"jk"[..]),
+ &Partial::new(&b"jk"[..]),
ErrorKind::Tag
)))
);
@@ -921,11 +949,11 @@ mod tests {
#[test]
fn unit_type() {
- fn parser(i: &str) -> IResult<&str, ()> {
+ fn parser(i: &mut &str) -> PResult<()> {
().parse_next(i)
}
- assert_eq!(parser.parse_next("abxsbsh"), Ok(("abxsbsh", ())));
- assert_eq!(parser.parse_next("sdfjakdsas"), Ok(("sdfjakdsas", ())));
- assert_eq!(parser.parse_next(""), Ok(("", ())));
+ assert_eq!(parser.parse_peek("abxsbsh"), Ok(("abxsbsh", ())));
+ assert_eq!(parser.parse_peek("sdfjakdsas"), Ok(("sdfjakdsas", ())));
+ assert_eq!(parser.parse_peek(""), Ok(("", ())));
}
}
diff --git a/vendor/winnow/src/sequence.rs b/vendor/winnow/src/sequence.rs
deleted file mode 100644
index 2d7af28e9..000000000
--- a/vendor/winnow/src/sequence.rs
+++ /dev/null
@@ -1,9 +0,0 @@
-//! Deprecated, see [`combinator`]
-#![deprecated(since = "0.4.2", note = "Replaced with `combinator`")]
-
-use crate::combinator;
-
-pub use combinator::delimited;
-pub use combinator::preceded;
-pub use combinator::separated_pair;
-pub use combinator::terminated;
diff --git a/vendor/winnow/src/stream/mod.rs b/vendor/winnow/src/stream/mod.rs
index 3d7a41e09..fcacbd78f 100644
--- a/vendor/winnow/src/stream/mod.rs
+++ b/vendor/winnow/src/stream/mod.rs
@@ -11,13 +11,16 @@
use core::num::NonZeroUsize;
-use crate::error::{ErrMode, ErrorKind, Needed, ParseError};
+use crate::error::Needed;
use crate::lib::std::iter::{Cloned, Enumerate};
use crate::lib::std::slice::Iter;
use crate::lib::std::str::from_utf8;
use crate::lib::std::str::CharIndices;
use crate::lib::std::str::FromStr;
-use crate::IResult;
+
+#[allow(unused_imports)]
+#[cfg(feature = "unstable-doc")]
+use crate::error::ErrMode;
#[cfg(feature = "alloc")]
use crate::lib::std::collections::BTreeMap;
@@ -103,7 +106,7 @@ where
}
fn location(&self) -> usize {
- self.initial.offset_to(&self.input)
+ self.input.offset_from(&self.initial)
}
}
@@ -156,9 +159,9 @@ impl<I: crate::lib::std::fmt::Display> crate::lib::std::fmt::Display for Located
///
/// type Stream<'is> = Stateful<&'is str, State<'is>>;
///
-/// fn word(i: Stream<'_>) -> IResult<Stream<'_>, &str> {
+/// fn word<'s>(i: &mut Stream<'s>) -> PResult<&'s str> {
/// i.state.count();
-/// alpha1(i)
+/// alpha1.parse_next(i)
/// }
///
/// let data = "Hello";
@@ -218,48 +221,48 @@ impl<I: crate::lib::std::fmt::Display, S> crate::lib::std::fmt::Display for Stat
/// Here is how it works in practice:
///
/// ```rust
-/// # use winnow::{IResult, error::ErrMode, error::Needed, error::{Error, ErrorKind}, token, ascii, stream::Partial};
+/// # use winnow::{PResult, error::ErrMode, error::Needed, error::{InputError, ErrorKind}, token, ascii, stream::Partial};
/// # use winnow::prelude::*;
///
-/// fn take_partial(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
+/// fn take_partial<'s>(i: &mut Partial<&'s [u8]>) -> PResult<&'s [u8], InputError<Partial<&'s [u8]>>> {
/// token::take(4u8).parse_next(i)
/// }
///
-/// fn take_complete(i: &[u8]) -> IResult<&[u8], &[u8]> {
+/// fn take_complete<'s>(i: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> {
/// token::take(4u8).parse_next(i)
/// }
///
/// // both parsers will take 4 bytes as expected
-/// assert_eq!(take_partial(Partial::new(&b"abcde"[..])), Ok((Partial::new(&b"e"[..]), &b"abcd"[..])));
-/// assert_eq!(take_complete(&b"abcde"[..]), Ok((&b"e"[..], &b"abcd"[..])));
+/// assert_eq!(take_partial.parse_peek(Partial::new(&b"abcde"[..])), Ok((Partial::new(&b"e"[..]), &b"abcd"[..])));
+/// assert_eq!(take_complete.parse_peek(&b"abcde"[..]), Ok((&b"e"[..], &b"abcd"[..])));
///
/// // if the input is smaller than 4 bytes, the partial parser
/// // will return `Incomplete` to indicate that we need more data
-/// assert_eq!(take_partial(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(take_partial.parse_peek(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
///
/// // but the complete parser will return an error
-/// assert_eq!(take_complete(&b"abc"[..]), Err(ErrMode::Backtrack(Error::new(&b"abc"[..], ErrorKind::Slice))));
+/// assert_eq!(take_complete.parse_peek(&b"abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"abc"[..], ErrorKind::Slice))));
///
/// // the alpha0 function recognizes 0 or more alphabetic characters
-/// fn alpha0_partial(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// ascii::alpha0(i)
+/// fn alpha0_partial<'s>(i: &mut Partial<&'s str>) -> PResult<&'s str, InputError<Partial<&'s str>>> {
+/// ascii::alpha0.parse_next(i)
/// }
///
-/// fn alpha0_complete(i: &str) -> IResult<&str, &str> {
-/// ascii::alpha0(i)
+/// fn alpha0_complete<'s>(i: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// ascii::alpha0.parse_next(i)
/// }
///
/// // if there's a clear limit to the recognized characters, both parsers work the same way
-/// assert_eq!(alpha0_partial(Partial::new("abcd;")), Ok((Partial::new(";"), "abcd")));
-/// assert_eq!(alpha0_complete("abcd;"), Ok((";", "abcd")));
+/// assert_eq!(alpha0_partial.parse_peek(Partial::new("abcd;")), Ok((Partial::new(";"), "abcd")));
+/// assert_eq!(alpha0_complete.parse_peek("abcd;"), Ok((";", "abcd")));
///
/// // but when there's no limit, the partial version returns `Incomplete`, because it cannot
/// // know if more input data should be recognized. The whole input could be "abcd;", or
/// // "abcde;"
-/// assert_eq!(alpha0_partial(Partial::new("abcd")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(alpha0_partial.parse_peek(Partial::new("abcd")), Err(ErrMode::Incomplete(Needed::new(1))));
///
/// // while the complete version knows that all of the data is there
-/// assert_eq!(alpha0_complete("abcd"), Ok(("", "abcd")));
+/// assert_eq!(alpha0_complete.parse_peek("abcd"), Ok(("", "abcd")));
/// ```
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Partial<I> {
@@ -402,7 +405,7 @@ where
}
/// Core definition for parser input state
-pub trait Stream: Offset + Clone + crate::lib::std::fmt::Debug {
+pub trait Stream: Offset<<Self as Stream>::Checkpoint> + crate::lib::std::fmt::Debug {
/// The smallest unit being parsed
///
/// Example: `u8` for `&[u8]` or `char` for `&str`
@@ -415,13 +418,26 @@ pub trait Stream: Offset + Clone + crate::lib::std::fmt::Debug {
/// Iterate with the offset from the current location
type IterOffsets: Iterator<Item = (usize, Self::Token)>;
+ /// A parse location within the stream
+ type Checkpoint: Offset + Clone + crate::lib::std::fmt::Debug;
+
/// Iterate with the offset from the current location
fn iter_offsets(&self) -> Self::IterOffsets;
/// Returns the offaet to the end of the input
fn eof_offset(&self) -> usize;
/// Split off the next token from the input
- fn next_token(&self) -> Option<(Self, Self::Token)>;
+ fn next_token(&mut self) -> Option<Self::Token>;
+ /// Split off the next token from the input
+ #[inline(always)]
+ fn peek_token(&self) -> Option<(Self, Self::Token)>
+ where
+ Self: Clone,
+ {
+ let mut peek = self.clone();
+ let token = peek.next_token()?;
+ Some((peek, token))
+ }
/// Finds the offset of the next matching token
fn offset_for<P>(&self, predicate: P) -> Option<usize>
@@ -448,7 +464,45 @@ pub trait Stream: Offset + Clone + crate::lib::std::fmt::Debug {
/// * Indexes must uphold invariants of the stream, like for `str` they must lie on UTF-8
/// sequence boundaries.
///
- fn next_slice(&self, offset: usize) -> (Self, Self::Slice);
+ fn next_slice(&mut self, offset: usize) -> Self::Slice;
+ /// Split off a slice of tokens from the input
+ #[inline(always)]
+ fn peek_slice(&self, offset: usize) -> (Self, Self::Slice)
+ where
+ Self: Clone,
+ {
+ let mut peek = self.clone();
+ let slice = peek.next_slice(offset);
+ (peek, slice)
+ }
+
+ /// Advance to the end of the stream
+ #[inline(always)]
+ fn finish(&mut self) -> Self::Slice {
+ self.next_slice(self.eof_offset())
+ }
+ /// Advance to the end of the stream
+ #[inline(always)]
+ fn peek_finish(&self) -> (Self, Self::Slice)
+ where
+ Self: Clone,
+ {
+ let mut peek = self.clone();
+ let slice = peek.finish();
+ (peek, slice)
+ }
+
+ /// Save the current parse location within the stream
+ fn checkpoint(&self) -> Self::Checkpoint;
+ /// Revert the stream to a prior [`Self::Checkpoint`]
+ ///
+ /// # Panic
+ ///
+ /// May panic if an invalid [`Self::Checkpoint`] is provided
+ fn reset(&mut self, checkpoint: Self::Checkpoint);
+
+ /// Return the inner-most stream
+ fn raw(&self) -> &dyn crate::lib::std::fmt::Debug;
}
impl<'i, T> Stream for &'i [T]
@@ -460,6 +514,8 @@ where
type IterOffsets = Enumerate<Cloned<Iter<'i, T>>>;
+ type Checkpoint = Checkpoint<Self>;
+
#[inline(always)]
fn iter_offsets(&self) -> Self::IterOffsets {
self.iter().cloned().enumerate()
@@ -470,9 +526,10 @@ where
}
#[inline(always)]
- fn next_token(&self) -> Option<(Self, Self::Token)> {
- self.split_first()
- .map(|(token, next)| (next, token.clone()))
+ fn next_token(&mut self) -> Option<Self::Token> {
+ let (token, next) = self.split_first()?;
+ *self = next;
+ Some(token.clone())
}
#[inline(always)]
@@ -491,9 +548,24 @@ where
}
}
#[inline(always)]
- fn next_slice(&self, offset: usize) -> (Self, Self::Slice) {
+ fn next_slice(&mut self, offset: usize) -> Self::Slice {
let (slice, next) = self.split_at(offset);
- (next, slice)
+ *self = next;
+ slice
+ }
+
+ #[inline(always)]
+ fn checkpoint(&self) -> Self::Checkpoint {
+ Checkpoint(*self)
+ }
+ #[inline(always)]
+ fn reset(&mut self, checkpoint: Self::Checkpoint) {
+ *self = checkpoint.0;
+ }
+
+ #[inline(always)]
+ fn raw(&self) -> &dyn crate::lib::std::fmt::Debug {
+ self
}
}
@@ -503,6 +575,8 @@ impl<'i> Stream for &'i str {
type IterOffsets = CharIndices<'i>;
+ type Checkpoint = Checkpoint<Self>;
+
#[inline(always)]
fn iter_offsets(&self) -> Self::IterOffsets {
self.char_indices()
@@ -513,10 +587,11 @@ impl<'i> Stream for &'i str {
}
#[inline(always)]
- fn next_token(&self) -> Option<(Self, Self::Token)> {
+ fn next_token(&mut self) -> Option<Self::Token> {
let c = self.chars().next()?;
let offset = c.len();
- Some((&self[offset..], c))
+ *self = &self[offset..];
+ Some(c)
}
#[inline(always)]
@@ -548,9 +623,24 @@ impl<'i> Stream for &'i str {
}
}
#[inline(always)]
- fn next_slice(&self, offset: usize) -> (Self, Self::Slice) {
+ fn next_slice(&mut self, offset: usize) -> Self::Slice {
let (slice, next) = self.split_at(offset);
- (next, slice)
+ *self = next;
+ slice
+ }
+
+ #[inline(always)]
+ fn checkpoint(&self) -> Self::Checkpoint {
+ Checkpoint(*self)
+ }
+ #[inline(always)]
+ fn reset(&mut self, checkpoint: Self::Checkpoint) {
+ *self = checkpoint.0;
+ }
+
+ #[inline(always)]
+ fn raw(&self) -> &dyn crate::lib::std::fmt::Debug {
+ self
}
}
@@ -560,6 +650,8 @@ impl<'i> Stream for &'i Bytes {
type IterOffsets = Enumerate<Cloned<Iter<'i, u8>>>;
+ type Checkpoint = Checkpoint<Self>;
+
#[inline(always)]
fn iter_offsets(&self) -> Self::IterOffsets {
self.iter().cloned().enumerate()
@@ -570,11 +662,13 @@ impl<'i> Stream for &'i Bytes {
}
#[inline(always)]
- fn next_token(&self) -> Option<(Self, Self::Token)> {
+ fn next_token(&mut self) -> Option<Self::Token> {
if self.is_empty() {
None
} else {
- Some((Bytes::from_bytes(&self[1..]), self[0]))
+ let token = self[0];
+ *self = &self[1..];
+ Some(token)
}
}
@@ -594,9 +688,24 @@ impl<'i> Stream for &'i Bytes {
}
}
#[inline(always)]
- fn next_slice(&self, offset: usize) -> (Self, Self::Slice) {
- let (next, slice) = (&self.0).next_slice(offset);
- (Bytes::from_bytes(next), slice)
+ fn next_slice(&mut self, offset: usize) -> Self::Slice {
+ let (slice, next) = self.0.split_at(offset);
+ *self = Bytes::from_bytes(next);
+ slice
+ }
+
+ #[inline(always)]
+ fn checkpoint(&self) -> Self::Checkpoint {
+ Checkpoint(*self)
+ }
+ #[inline(always)]
+ fn reset(&mut self, checkpoint: Self::Checkpoint) {
+ *self = checkpoint.0;
+ }
+
+ #[inline(always)]
+ fn raw(&self) -> &dyn crate::lib::std::fmt::Debug {
+ self
}
}
@@ -606,6 +715,8 @@ impl<'i> Stream for &'i BStr {
type IterOffsets = Enumerate<Cloned<Iter<'i, u8>>>;
+ type Checkpoint = Checkpoint<Self>;
+
#[inline(always)]
fn iter_offsets(&self) -> Self::IterOffsets {
self.iter().cloned().enumerate()
@@ -616,11 +727,13 @@ impl<'i> Stream for &'i BStr {
}
#[inline(always)]
- fn next_token(&self) -> Option<(Self, Self::Token)> {
+ fn next_token(&mut self) -> Option<Self::Token> {
if self.is_empty() {
None
} else {
- Some((BStr::from_bytes(&self[1..]), self[0]))
+ let token = self[0];
+ *self = &self[1..];
+ Some(token)
}
}
@@ -640,21 +753,38 @@ impl<'i> Stream for &'i BStr {
}
}
#[inline(always)]
- fn next_slice(&self, offset: usize) -> (Self, Self::Slice) {
- let (next, slice) = (&self.0).next_slice(offset);
- (BStr::from_bytes(next), slice)
+ fn next_slice(&mut self, offset: usize) -> Self::Slice {
+ let (slice, next) = self.0.split_at(offset);
+ *self = BStr::from_bytes(next);
+ slice
+ }
+
+ #[inline(always)]
+ fn checkpoint(&self) -> Self::Checkpoint {
+ Checkpoint(*self)
+ }
+ #[inline(always)]
+ fn reset(&mut self, checkpoint: Self::Checkpoint) {
+ *self = checkpoint.0;
+ }
+
+ #[inline(always)]
+ fn raw(&self) -> &dyn crate::lib::std::fmt::Debug {
+ self
}
}
impl<I> Stream for (I, usize)
where
- I: Stream<Token = u8>,
+ I: Stream<Token = u8> + Clone,
{
type Token = bool;
type Slice = (I::Slice, usize, usize);
type IterOffsets = BitOffsets<I>;
+ type Checkpoint = Checkpoint<(I::Checkpoint, usize)>;
+
#[inline(always)]
fn iter_offsets(&self) -> Self::IterOffsets {
BitOffsets {
@@ -673,7 +803,7 @@ where
}
#[inline(always)]
- fn next_token(&self) -> Option<(Self, Self::Token)> {
+ fn next_token(&mut self) -> Option<Self::Token> {
next_bit(self)
}
@@ -683,7 +813,7 @@ where
P: Fn(Self::Token) -> bool,
{
self.iter_offsets()
- .find_map(|(o, b)| predicate(b).then(|| o))
+ .find_map(|(o, b)| predicate(b).then_some(o))
}
#[inline(always)]
fn offset_at(&self, tokens: usize) -> Result<usize, Needed> {
@@ -697,11 +827,28 @@ where
}
}
#[inline(always)]
- fn next_slice(&self, offset: usize) -> (Self, Self::Slice) {
+ fn next_slice(&mut self, offset: usize) -> Self::Slice {
let byte_offset = (offset + self.1) / 8;
let end_offset = (offset + self.1) % 8;
- let (i, s) = self.0.next_slice(byte_offset);
- ((i, end_offset), (s, self.1, end_offset))
+ let s = self.0.next_slice(byte_offset);
+ let start_offset = self.1;
+ self.1 = end_offset;
+ (s, start_offset, end_offset)
+ }
+
+ #[inline(always)]
+ fn checkpoint(&self) -> Self::Checkpoint {
+ Checkpoint((self.0.checkpoint(), self.1))
+ }
+ #[inline(always)]
+ fn reset(&mut self, checkpoint: Self::Checkpoint) {
+ self.0.reset(checkpoint.0 .0);
+ self.1 = checkpoint.0 .1;
+ }
+
+ #[inline(always)]
+ fn raw(&self) -> &dyn crate::lib::std::fmt::Debug {
+ &self.0
}
}
@@ -713,37 +860,40 @@ pub struct BitOffsets<I> {
impl<I> Iterator for BitOffsets<I>
where
- I: Stream<Token = u8>,
+ I: Stream<Token = u8> + Clone,
{
type Item = (usize, bool);
fn next(&mut self) -> Option<Self::Item> {
- let (next, b) = next_bit(&self.i)?;
+ let b = next_bit(&mut self.i)?;
let o = self.o;
- self.i = next;
self.o += 1;
Some((o, b))
}
}
-fn next_bit<I>(i: &(I, usize)) -> Option<((I, usize), bool)>
+fn next_bit<I>(i: &mut (I, usize)) -> Option<bool>
where
- I: Stream<Token = u8>,
+ I: Stream<Token = u8> + Clone,
{
if i.eof_offset() == 0 {
return None;
}
+ let offset = i.1;
- let i = i.clone();
- let (next_i, byte) = i.0.next_token()?;
- let bit = (byte >> i.1) & 0x1 == 0x1;
+ let mut next_i = i.0.clone();
+ let byte = next_i.next_token()?;
+ let bit = (byte >> offset) & 0x1 == 0x1;
- let next_offset = i.1 + 1;
+ let next_offset = offset + 1;
if next_offset == 8 {
- Some(((next_i, 0), bit))
+ i.0 = next_i;
+ i.1 = 0;
+ Some(bit)
} else {
- Some(((i.0, next_offset), bit))
+ i.1 = next_offset;
+ Some(bit)
}
}
@@ -753,6 +903,8 @@ impl<I: Stream> Stream for Located<I> {
type IterOffsets = <I as Stream>::IterOffsets;
+ type Checkpoint = Checkpoint<I::Checkpoint>;
+
#[inline(always)]
fn iter_offsets(&self) -> Self::IterOffsets {
self.input.iter_offsets()
@@ -763,15 +915,8 @@ impl<I: Stream> Stream for Located<I> {
}
#[inline(always)]
- fn next_token(&self) -> Option<(Self, Self::Token)> {
- let (next, token) = self.input.next_token()?;
- Some((
- Self {
- initial: self.initial.clone(),
- input: next,
- },
- token,
- ))
+ fn next_token(&mut self) -> Option<Self::Token> {
+ self.input.next_token()
}
#[inline(always)]
@@ -786,15 +931,22 @@ impl<I: Stream> Stream for Located<I> {
self.input.offset_at(tokens)
}
#[inline(always)]
- fn next_slice(&self, offset: usize) -> (Self, Self::Slice) {
- let (next, slice) = self.input.next_slice(offset);
- (
- Self {
- initial: self.initial.clone(),
- input: next,
- },
- slice,
- )
+ fn next_slice(&mut self, offset: usize) -> Self::Slice {
+ self.input.next_slice(offset)
+ }
+
+ #[inline(always)]
+ fn checkpoint(&self) -> Self::Checkpoint {
+ Checkpoint(self.input.checkpoint())
+ }
+ #[inline(always)]
+ fn reset(&mut self, checkpoint: Self::Checkpoint) {
+ self.input.reset(checkpoint.0);
+ }
+
+ #[inline(always)]
+ fn raw(&self) -> &dyn crate::lib::std::fmt::Debug {
+ &self.input
}
}
@@ -804,6 +956,8 @@ impl<I: Stream, S: Clone + crate::lib::std::fmt::Debug> Stream for Stateful<I, S
type IterOffsets = <I as Stream>::IterOffsets;
+ type Checkpoint = Checkpoint<I::Checkpoint>;
+
#[inline(always)]
fn iter_offsets(&self) -> Self::IterOffsets {
self.input.iter_offsets()
@@ -814,15 +968,8 @@ impl<I: Stream, S: Clone + crate::lib::std::fmt::Debug> Stream for Stateful<I, S
}
#[inline(always)]
- fn next_token(&self) -> Option<(Self, Self::Token)> {
- let (next, token) = self.input.next_token()?;
- Some((
- Self {
- input: next,
- state: self.state.clone(),
- },
- token,
- ))
+ fn next_token(&mut self) -> Option<Self::Token> {
+ self.input.next_token()
}
#[inline(always)]
@@ -837,15 +984,22 @@ impl<I: Stream, S: Clone + crate::lib::std::fmt::Debug> Stream for Stateful<I, S
self.input.offset_at(tokens)
}
#[inline(always)]
- fn next_slice(&self, offset: usize) -> (Self, Self::Slice) {
- let (next, slice) = self.input.next_slice(offset);
- (
- Self {
- input: next,
- state: self.state.clone(),
- },
- slice,
- )
+ fn next_slice(&mut self, offset: usize) -> Self::Slice {
+ self.input.next_slice(offset)
+ }
+
+ #[inline(always)]
+ fn checkpoint(&self) -> Self::Checkpoint {
+ Checkpoint(self.input.checkpoint())
+ }
+ #[inline(always)]
+ fn reset(&mut self, checkpoint: Self::Checkpoint) {
+ self.input.reset(checkpoint.0);
+ }
+
+ #[inline(always)]
+ fn raw(&self) -> &dyn crate::lib::std::fmt::Debug {
+ &self.input
}
}
@@ -855,6 +1009,8 @@ impl<I: Stream> Stream for Partial<I> {
type IterOffsets = <I as Stream>::IterOffsets;
+ type Checkpoint = Checkpoint<I::Checkpoint>;
+
#[inline(always)]
fn iter_offsets(&self) -> Self::IterOffsets {
self.input.iter_offsets()
@@ -865,15 +1021,8 @@ impl<I: Stream> Stream for Partial<I> {
}
#[inline(always)]
- fn next_token(&self) -> Option<(Self, Self::Token)> {
- let (next, token) = self.input.next_token()?;
- Some((
- Partial {
- input: next,
- partial: self.partial,
- },
- token,
- ))
+ fn next_token(&mut self) -> Option<Self::Token> {
+ self.input.next_token()
}
#[inline(always)]
@@ -888,15 +1037,22 @@ impl<I: Stream> Stream for Partial<I> {
self.input.offset_at(tokens)
}
#[inline(always)]
- fn next_slice(&self, offset: usize) -> (Self, Self::Slice) {
- let (next, slice) = self.input.next_slice(offset);
- (
- Partial {
- input: next,
- partial: self.partial,
- },
- slice,
- )
+ fn next_slice(&mut self, offset: usize) -> Self::Slice {
+ self.input.next_slice(offset)
+ }
+
+ #[inline(always)]
+ fn checkpoint(&self) -> Self::Checkpoint {
+ Checkpoint(self.input.checkpoint())
+ }
+ #[inline(always)]
+ fn reset(&mut self, checkpoint: Self::Checkpoint) {
+ self.input.reset(checkpoint.0);
+ }
+
+ #[inline(always)]
+ fn raw(&self) -> &dyn crate::lib::std::fmt::Debug {
+ &self.input
}
}
@@ -1119,24 +1275,16 @@ where
}
/// Useful functions to calculate the offset between slices and show a hexdump of a slice
-pub trait Offset {
- /// Offset between the first byte of self and the first byte of the argument
- fn offset_to(&self, second: &Self) -> usize;
+pub trait Offset<Start = Self> {
+ /// Offset between the first byte of `start` and the first byte of `self`
+ fn offset_from(&self, start: &Start) -> usize;
}
impl<'a, T> Offset for &'a [T] {
- #[inline(always)]
- fn offset_to(&self, second: &Self) -> usize {
- (*self).offset_to(*second)
- }
-}
-
-/// Convenience implementation to accept `&[T]` instead of `&&[T]` as above
-impl<T> Offset for [T] {
#[inline]
- fn offset_to(&self, second: &Self) -> usize {
- let fst = self.as_ptr();
- let snd = second.as_ptr();
+ fn offset_from(&self, start: &Self) -> usize {
+ let fst = (*start).as_ptr();
+ let snd = (*self).as_ptr();
debug_assert!(
fst <= snd,
@@ -1146,46 +1294,55 @@ impl<T> Offset for [T] {
}
}
-impl<'a> Offset for &'a str {
+impl<'a, T> Offset<<&'a [T] as Stream>::Checkpoint> for &'a [T]
+where
+ T: Clone + crate::lib::std::fmt::Debug,
+{
#[inline(always)]
- fn offset_to(&self, second: &Self) -> usize {
- self.as_bytes().offset_to(second.as_bytes())
+ fn offset_from(&self, other: &<&'a [T] as Stream>::Checkpoint) -> usize {
+ self.checkpoint().offset_from(other)
}
}
-/// Convenience implementation to accept `&str` instead of `&&str` as above
-impl Offset for str {
+impl<'a> Offset for &'a str {
#[inline(always)]
- fn offset_to(&self, second: &Self) -> usize {
- self.as_bytes().offset_to(second.as_bytes())
+ fn offset_from(&self, start: &Self) -> usize {
+ self.as_bytes().offset_from(&start.as_bytes())
}
}
-impl Offset for Bytes {
+impl<'a> Offset<<&'a str as Stream>::Checkpoint> for &'a str {
#[inline(always)]
- fn offset_to(&self, second: &Self) -> usize {
- self.as_bytes().offset_to(second.as_bytes())
+ fn offset_from(&self, other: &<&'a str as Stream>::Checkpoint) -> usize {
+ self.checkpoint().offset_from(other)
}
}
impl<'a> Offset for &'a Bytes {
#[inline(always)]
- fn offset_to(&self, second: &Self) -> usize {
- self.as_bytes().offset_to(second.as_bytes())
+ fn offset_from(&self, start: &Self) -> usize {
+ self.as_bytes().offset_from(&start.as_bytes())
}
}
-impl Offset for BStr {
+impl<'a> Offset<<&'a Bytes as Stream>::Checkpoint> for &'a Bytes {
#[inline(always)]
- fn offset_to(&self, second: &Self) -> usize {
- self.as_bytes().offset_to(second.as_bytes())
+ fn offset_from(&self, other: &<&'a Bytes as Stream>::Checkpoint) -> usize {
+ self.checkpoint().offset_from(other)
}
}
impl<'a> Offset for &'a BStr {
#[inline(always)]
- fn offset_to(&self, second: &Self) -> usize {
- self.as_bytes().offset_to(second.as_bytes())
+ fn offset_from(&self, start: &Self) -> usize {
+ self.as_bytes().offset_from(&start.as_bytes())
+ }
+}
+
+impl<'a> Offset<<&'a BStr as Stream>::Checkpoint> for &'a BStr {
+ #[inline(always)]
+ fn offset_from(&self, other: &<&'a BStr as Stream>::Checkpoint) -> usize {
+ self.checkpoint().offset_from(other)
}
}
@@ -1194,38 +1351,90 @@ where
I: Offset,
{
#[inline(always)]
- fn offset_to(&self, other: &Self) -> usize {
- self.0.offset_to(&other.0) * 8 + other.1 - self.1
+ fn offset_from(&self, start: &Self) -> usize {
+ self.0.offset_from(&start.0) * 8 + self.1 - start.1
+ }
+}
+
+impl<I> Offset<<(I, usize) as Stream>::Checkpoint> for (I, usize)
+where
+ I: Stream<Token = u8> + Clone,
+{
+ #[inline(always)]
+ fn offset_from(&self, other: &<(I, usize) as Stream>::Checkpoint) -> usize {
+ self.checkpoint().offset_from(other)
}
}
impl<I> Offset for Located<I>
where
- I: Offset,
+ I: Stream,
{
#[inline(always)]
- fn offset_to(&self, other: &Self) -> usize {
- self.input.offset_to(&other.input)
+ fn offset_from(&self, other: &Self) -> usize {
+ self.offset_from(&other.checkpoint())
+ }
+}
+
+impl<I> Offset<<Located<I> as Stream>::Checkpoint> for Located<I>
+where
+ I: Stream,
+{
+ #[inline(always)]
+ fn offset_from(&self, other: &<Located<I> as Stream>::Checkpoint) -> usize {
+ self.checkpoint().offset_from(other)
}
}
impl<I, S> Offset for Stateful<I, S>
where
- I: Offset,
+ I: Stream,
+ S: Clone + crate::lib::std::fmt::Debug,
+{
+ #[inline(always)]
+ fn offset_from(&self, start: &Self) -> usize {
+ self.offset_from(&start.checkpoint())
+ }
+}
+
+impl<I, S> Offset<<Stateful<I, S> as Stream>::Checkpoint> for Stateful<I, S>
+where
+ I: Stream,
+ S: Clone + crate::lib::std::fmt::Debug,
{
#[inline(always)]
- fn offset_to(&self, other: &Self) -> usize {
- self.input.offset_to(&other.input)
+ fn offset_from(&self, other: &<Stateful<I, S> as Stream>::Checkpoint) -> usize {
+ self.checkpoint().offset_from(other)
}
}
impl<I> Offset for Partial<I>
where
+ I: Stream,
+{
+ #[inline(always)]
+ fn offset_from(&self, start: &Self) -> usize {
+ self.offset_from(&start.checkpoint())
+ }
+}
+
+impl<I> Offset<<Partial<I> as Stream>::Checkpoint> for Partial<I>
+where
+ I: Stream,
+{
+ #[inline(always)]
+ fn offset_from(&self, other: &<Partial<I> as Stream>::Checkpoint) -> usize {
+ self.checkpoint().offset_from(other)
+ }
+}
+
+impl<I> Offset for Checkpoint<I>
+where
I: Offset,
{
#[inline(always)]
- fn offset_to(&self, second: &Self) -> usize {
- self.input.offset_to(&second.input)
+ fn offset_from(&self, start: &Self) -> usize {
+ self.0.offset_from(&start.0)
}
}
@@ -1744,6 +1953,10 @@ where
}
}
+/// Ensure checkpoint details are kept privazte
+#[derive(Copy, Clone, Debug)]
+pub struct Checkpoint<T>(T);
+
/// A range bounded inclusively for counting parses performed
#[derive(PartialEq, Eq)]
pub struct Range {
@@ -2257,15 +2470,15 @@ impl<'a> AsChar for &'a char {
/// For example, you could implement `hex_digit0` as:
/// ```
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// # use winnow::token::take_while;
-/// fn hex_digit1(input: &str) -> IResult<&str, &str> {
+/// fn hex_digit1<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
/// take_while(1.., ('a'..='f', 'A'..='F', '0'..='9')).parse_next(input)
/// }
///
-/// assert_eq!(hex_digit1("21cZ"), Ok(("Z", "21c")));
-/// assert_eq!(hex_digit1("H2"), Err(ErrMode::Backtrack(Error::new("H2", ErrorKind::Slice))));
-/// assert_eq!(hex_digit1(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(hex_digit1.parse_peek("21cZ"), Ok(("Z", "21c")));
+/// assert_eq!(hex_digit1.parse_peek("H2"), Err(ErrMode::Backtrack(InputError::new("H2", ErrorKind::Slice))));
+/// assert_eq!(hex_digit1.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
pub trait ContainsToken<T> {
/// Returns true if self contains the token
@@ -2415,14 +2628,6 @@ impl<const LEN: usize, C: AsChar> ContainsToken<C> for [char; LEN] {
}
}
-impl<C: AsChar> ContainsToken<C> for &'_ str {
- #[inline(always)]
- fn contains_token(&self, token: C) -> bool {
- let token = token.as_char();
- self.chars().any(|i| i == token)
- }
-}
-
impl<T> ContainsToken<T> for () {
#[inline(always)]
fn contains_token(&self, _token: T) -> bool {
@@ -2464,88 +2669,6 @@ impl_contains_token_for_tuples!(
F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, F16, F17, F18, F19, F20, F21
);
-/// Looks for the first element of the input type for which the condition returns true,
-/// and returns the input up to this position.
-///
-/// *Partial version*: If no element is found matching the condition, this will return `Incomplete`
-pub(crate) fn split_at_offset_partial<P, I: Stream, E: ParseError<I>>(
- input: &I,
- predicate: P,
-) -> IResult<I, <I as Stream>::Slice, E>
-where
- P: Fn(I::Token) -> bool,
-{
- let offset = input
- .offset_for(predicate)
- .ok_or_else(|| ErrMode::Incomplete(Needed::new(1)))?;
- Ok(input.next_slice(offset))
-}
-
-/// Looks for the first element of the input type for which the condition returns true
-/// and returns the input up to this position.
-///
-/// Fails if the produced slice is empty.
-///
-/// *Partial version*: If no element is found matching the condition, this will return `Incomplete`
-pub(crate) fn split_at_offset1_partial<P, I: Stream, E: ParseError<I>>(
- input: &I,
- predicate: P,
- e: ErrorKind,
-) -> IResult<I, <I as Stream>::Slice, E>
-where
- P: Fn(I::Token) -> bool,
-{
- let offset = input
- .offset_for(predicate)
- .ok_or_else(|| ErrMode::Incomplete(Needed::new(1)))?;
- if offset == 0 {
- Err(ErrMode::from_error_kind(input.clone(), e))
- } else {
- Ok(input.next_slice(offset))
- }
-}
-
-/// Looks for the first element of the input type for which the condition returns true,
-/// and returns the input up to this position.
-///
-/// *Complete version*: If no element is found matching the condition, this will return the whole input
-pub(crate) fn split_at_offset_complete<P, I: Stream, E: ParseError<I>>(
- input: &I,
- predicate: P,
-) -> IResult<I, <I as Stream>::Slice, E>
-where
- P: Fn(I::Token) -> bool,
-{
- let offset = input
- .offset_for(predicate)
- .unwrap_or_else(|| input.eof_offset());
- Ok(input.next_slice(offset))
-}
-
-/// Looks for the first element of the input type for which the condition returns true
-/// and returns the input up to this position.
-///
-/// Fails if the produced slice is empty.
-///
-/// *Complete version*: If no element is found matching the condition, this will return the whole input
-pub(crate) fn split_at_offset1_complete<P, I: Stream, E: ParseError<I>>(
- input: &I,
- predicate: P,
- e: ErrorKind,
-) -> IResult<I, <I as Stream>::Slice, E>
-where
- P: Fn(I::Token) -> bool,
-{
- let offset = input
- .offset_for(predicate)
- .unwrap_or_else(|| input.eof_offset());
- if offset == 0 {
- Err(ErrMode::from_error_kind(input.clone(), e))
- } else {
- Ok(input.next_slice(offset))
- }
-}
-
#[cfg(feature = "simd")]
#[inline(always)]
fn memchr(token: u8, slice: &[u8]) -> Option<usize> {
diff --git a/vendor/winnow/src/stream/tests.rs b/vendor/winnow/src/stream/tests.rs
index de61df099..e653ad9e0 100644
--- a/vendor/winnow/src/stream/tests.rs
+++ b/vendor/winnow/src/stream/tests.rs
@@ -10,9 +10,9 @@ fn test_offset_u8() {
let b = &a[2..];
let c = &a[..4];
let d = &a[3..5];
- assert_eq!(a.offset_to(b), 2);
- assert_eq!(a.offset_to(c), 0);
- assert_eq!(a.offset_to(d), 3);
+ assert_eq!(b.offset_from(&a), 2);
+ assert_eq!(c.offset_from(&a), 0);
+ assert_eq!(d.offset_from(&a), 3);
}
#[test]
@@ -21,9 +21,9 @@ fn test_offset_str() {
let b = &a[7..];
let c = &a[..5];
let d = &a[5..9];
- assert_eq!(a.offset_to(b), 7);
- assert_eq!(a.offset_to(c), 0);
- assert_eq!(a.offset_to(d), 5);
+ assert_eq!(b.offset_from(&a), 7);
+ assert_eq!(c.offset_from(&a), 0);
+ assert_eq!(d.offset_from(&a), 5);
}
#[test]
@@ -37,7 +37,7 @@ fn test_bit_stream_empty() {
let actual = i.eof_offset();
assert_eq!(actual, 0);
- let actual = i.next_token();
+ let actual = i.peek_token();
assert_eq!(actual, None);
let actual = i.offset_for(|b| b);
@@ -46,7 +46,7 @@ fn test_bit_stream_empty() {
let actual = i.offset_at(1);
assert_eq!(actual, Err(Needed::new(1)));
- let (actual_input, actual_slice) = i.next_slice(0);
+ let (actual_input, actual_slice) = i.peek_slice(0);
assert_eq!(actual_input, (&b""[..], 0));
assert_eq!(actual_slice, (&b""[..], 0, 0));
}
@@ -56,7 +56,7 @@ fn test_bit_stream_empty() {
fn test_bit_offset_empty() {
let i = (&b""[..], 0);
- let actual = i.offset_to(&i);
+ let actual = i.offset_from(&i);
assert_eq!(actual, 0);
}
@@ -80,18 +80,18 @@ fn bit_stream_inner(byte_len: usize, start: usize) {
let mut curr_i = i;
let mut curr_offset = 0;
- while let Some((next_i, _token)) = curr_i.next_token() {
- let to_offset = i.offset_to(&curr_i);
+ while let Some((next_i, _token)) = curr_i.peek_token() {
+ let to_offset = curr_i.offset_from(&i);
assert_eq!(curr_offset, to_offset);
- let (slice_i, _) = i.next_slice(curr_offset);
+ let (slice_i, _) = i.peek_slice(curr_offset);
assert_eq!(curr_i, slice_i);
let at_offset = i.offset_at(curr_offset).unwrap();
assert_eq!(curr_offset, at_offset);
let eof_offset = curr_i.eof_offset();
- let (next_eof_i, eof_slice) = curr_i.next_slice(eof_offset);
+ let (next_eof_i, eof_slice) = curr_i.peek_slice(eof_offset);
assert_eq!(next_eof_i, (&b""[..], 0));
let eof_slice_i = (eof_slice.0, eof_slice.1);
assert_eq!(eof_slice_i, curr_i);
diff --git a/vendor/winnow/src/token/mod.rs b/vendor/winnow/src/token/mod.rs
index 6f99dfa8d..fba019c97 100644
--- a/vendor/winnow/src/token/mod.rs
+++ b/vendor/winnow/src/token/mod.rs
@@ -6,16 +6,13 @@ mod tests;
use crate::error::ErrMode;
use crate::error::ErrorKind;
use crate::error::Needed;
-use crate::error::ParseError;
+use crate::error::ParserError;
use crate::lib::std::result::Result::Ok;
use crate::stream::Range;
-use crate::stream::{
- split_at_offset1_complete, split_at_offset1_partial, split_at_offset_complete,
- split_at_offset_partial, Compare, CompareResult, ContainsToken, FindSlice, SliceLen, Stream,
-};
+use crate::stream::{Compare, CompareResult, ContainsToken, FindSlice, SliceLen, Stream};
use crate::stream::{StreamIsPartial, ToUsize};
use crate::trace::trace;
-use crate::IResult;
+use crate::PResult;
use crate::Parser;
/// Matches one token
@@ -27,31 +24,31 @@ use crate::Parser;
/// # Example
///
/// ```rust
-/// # use winnow::{token::any, error::ErrMode, error::{Error, ErrorKind}};
+/// # use winnow::{token::any, error::ErrMode, error::{InputError, ErrorKind}};
/// # use winnow::prelude::*;
/// fn parser(input: &str) -> IResult<&str, char> {
-/// any.parse_next(input)
+/// any.parse_peek(input)
/// }
///
/// assert_eq!(parser("abc"), Ok(("bc",'a')));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
/// ```
///
/// ```rust
-/// # use winnow::{token::any, error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{token::any, error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
-/// assert_eq!(any::<_, Error<_>>.parse_next(Partial::new("abc")), Ok((Partial::new("bc"),'a')));
-/// assert_eq!(any::<_, Error<_>>.parse_next(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(any::<_, InputError<_>>.parse_peek(Partial::new("abc")), Ok((Partial::new("bc"),'a')));
+/// assert_eq!(any::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
#[doc(alias = "token")]
-pub fn any<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Token, E>
+pub fn any<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Token, E>
where
I: StreamIsPartial,
I: Stream,
{
- trace("any", move |input: I| {
+ trace("any", move |input: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
any_::<_, _, true>(input)
} else {
@@ -61,7 +58,9 @@ where
.parse_next(input)
}
-fn any_<I, E: ParseError<I>, const PARTIAL: bool>(input: I) -> IResult<I, <I as Stream>::Token, E>
+fn any_<I, E: ParserError<I>, const PARTIAL: bool>(
+ input: &mut I,
+) -> PResult<<I as Stream>::Token, E>
where
I: StreamIsPartial,
I: Stream,
@@ -80,7 +79,7 @@ where
/// The input data will be compared to the tag combinator's argument and will return the part of
/// the input that matches the argument
///
-/// It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Tag)))` if the input doesn't match the pattern
+/// It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Tag)))` if the input doesn't match the pattern
///
/// **Note:** [`Parser`][crate::Parser] is implemented for strings and byte strings as a convenience (complete
/// only)
@@ -88,44 +87,44 @@ where
/// # Example
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// use winnow::token::tag;
///
/// fn parser(s: &str) -> IResult<&str, &str> {
-/// "Hello".parse_next(s)
+/// "Hello".parse_peek(s)
/// }
///
/// assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
-/// assert_eq!(parser("Something"), Err(ErrMode::Backtrack(Error::new("Something", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser("Something"), Err(ErrMode::Backtrack(InputError::new("Something", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// ```
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::Partial;
/// use winnow::token::tag;
///
/// fn parser(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// "Hello".parse_next(s)
+/// "Hello".parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new("Hello, World!")), Ok((Partial::new(", World!"), "Hello")));
-/// assert_eq!(parser(Partial::new("Something")), Err(ErrMode::Backtrack(Error::new(Partial::new("Something"), ErrorKind::Tag))));
-/// assert_eq!(parser(Partial::new("S")), Err(ErrMode::Backtrack(Error::new(Partial::new("S"), ErrorKind::Tag))));
+/// assert_eq!(parser(Partial::new("Something")), Err(ErrMode::Backtrack(InputError::new(Partial::new("Something"), ErrorKind::Tag))));
+/// assert_eq!(parser(Partial::new("S")), Err(ErrMode::Backtrack(InputError::new(Partial::new("S"), ErrorKind::Tag))));
/// assert_eq!(parser(Partial::new("H")), Err(ErrMode::Incomplete(Needed::new(4))));
/// ```
#[inline(always)]
#[doc(alias = "literal")]
#[doc(alias = "bytes")]
#[doc(alias = "just")]
-pub fn tag<T, I, Error: ParseError<I>>(tag: T) -> impl Parser<I, <I as Stream>::Slice, Error>
+pub fn tag<T, I, Error: ParserError<I>>(tag: T) -> impl Parser<I, <I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream + Compare<T>,
T: SliceLen + Clone,
{
- trace("tag", move |i: I| {
+ trace("tag", move |i: &mut I| {
let t = tag.clone();
if <I as StreamIsPartial>::is_partial_supported() {
tag_::<_, _, _, true>(i, t)
@@ -135,10 +134,10 @@ where
})
}
-fn tag_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- i: I,
+fn tag_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ i: &mut I,
t: T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream + Compare<T>,
@@ -162,47 +161,47 @@ where
/// The input data will be compared to the tag combinator's argument and will return the part of
/// the input that matches the argument with no regard to case.
///
-/// It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Tag)))` if the input doesn't match the pattern.
+/// It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Tag)))` if the input doesn't match the pattern.
///
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::tag_no_case;
///
/// fn parser(s: &str) -> IResult<&str, &str> {
-/// tag_no_case("hello").parse_next(s)
+/// tag_no_case("hello").parse_peek(s)
/// }
///
/// assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
/// assert_eq!(parser("hello, World!"), Ok((", World!", "hello")));
/// assert_eq!(parser("HeLlO, World!"), Ok((", World!", "HeLlO")));
-/// assert_eq!(parser("Something"), Err(ErrMode::Backtrack(Error::new("Something", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser("Something"), Err(ErrMode::Backtrack(InputError::new("Something", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::tag_no_case;
///
/// fn parser(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// tag_no_case("hello").parse_next(s)
+/// tag_no_case("hello").parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new("Hello, World!")), Ok((Partial::new(", World!"), "Hello")));
/// assert_eq!(parser(Partial::new("hello, World!")), Ok((Partial::new(", World!"), "hello")));
/// assert_eq!(parser(Partial::new("HeLlO, World!")), Ok((Partial::new(", World!"), "HeLlO")));
-/// assert_eq!(parser(Partial::new("Something")), Err(ErrMode::Backtrack(Error::new(Partial::new("Something"), ErrorKind::Tag))));
+/// assert_eq!(parser(Partial::new("Something")), Err(ErrMode::Backtrack(InputError::new(Partial::new("Something"), ErrorKind::Tag))));
/// assert_eq!(parser(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(5))));
/// ```
#[inline(always)]
#[doc(alias = "literal")]
#[doc(alias = "bytes")]
#[doc(alias = "just")]
-pub fn tag_no_case<T, I, Error: ParseError<I>>(
+pub fn tag_no_case<T, I, Error: ParserError<I>>(
tag: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
@@ -210,7 +209,7 @@ where
I: Stream + Compare<T>,
T: SliceLen + Clone,
{
- trace("tag_no_case", move |i: I| {
+ trace("tag_no_case", move |i: &mut I| {
let t = tag.clone();
if <I as StreamIsPartial>::is_partial_supported() {
tag_no_case_::<_, _, _, true>(i, t)
@@ -220,10 +219,10 @@ where
})
}
-fn tag_no_case_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- i: I,
+fn tag_no_case_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ i: &mut I,
t: T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream + Compare<T>,
@@ -231,7 +230,7 @@ where
{
let tag_len = t.slice_len();
- match (i).compare_no_case(t) {
+ match i.compare_no_case(t) {
CompareResult::Ok => Ok(i.next_slice(tag_len)),
CompareResult::Incomplete if PARTIAL && i.is_partial() => {
Err(ErrMode::Incomplete(Needed::new(tag_len - i.eof_offset())))
@@ -258,50 +257,50 @@ where
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// # use winnow::token::one_of;
-/// assert_eq!(one_of::<_, _, Error<_>>("abc").parse_next("b"), Ok(("", 'b')));
-/// assert_eq!(one_of::<_, _, Error<_>>("a").parse_next("bc"), Err(ErrMode::Backtrack(Error::new("bc", ErrorKind::Verify))));
-/// assert_eq!(one_of::<_, _, Error<_>>("a").parse_next(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(one_of::<_, _, InputError<_>>(['a', 'b', 'c']).parse_peek("b"), Ok(("", 'b')));
+/// assert_eq!(one_of::<_, _, InputError<_>>('a').parse_peek("bc"), Err(ErrMode::Backtrack(InputError::new("bc", ErrorKind::Verify))));
+/// assert_eq!(one_of::<_, _, InputError<_>>('a').parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
///
/// fn parser_fn(i: &str) -> IResult<&str, char> {
-/// one_of(|c| c == 'a' || c == 'b').parse_next(i)
+/// one_of(|c| c == 'a' || c == 'b').parse_peek(i)
/// }
/// assert_eq!(parser_fn("abc"), Ok(("bc", 'a')));
-/// assert_eq!(parser_fn("cd"), Err(ErrMode::Backtrack(Error::new("cd", ErrorKind::Verify))));
-/// assert_eq!(parser_fn(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(parser_fn("cd"), Err(ErrMode::Backtrack(InputError::new("cd", ErrorKind::Verify))));
+/// assert_eq!(parser_fn(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
/// ```
///
/// ```
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::token::one_of;
-/// assert_eq!(one_of::<_, _, Error<_>>("abc").parse_next(Partial::new("b")), Ok((Partial::new(""), 'b')));
-/// assert_eq!(one_of::<_, _, Error<_>>("a").parse_next(Partial::new("bc")), Err(ErrMode::Backtrack(Error::new(Partial::new("bc"), ErrorKind::Verify))));
-/// assert_eq!(one_of::<_, _, Error<_>>("a").parse_next(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(one_of::<_, _, InputError<_>>(['a', 'b', 'c']).parse_peek(Partial::new("b")), Ok((Partial::new(""), 'b')));
+/// assert_eq!(one_of::<_, _, InputError<_>>('a').parse_peek(Partial::new("bc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("bc"), ErrorKind::Verify))));
+/// assert_eq!(one_of::<_, _, InputError<_>>('a').parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
///
/// fn parser_fn(i: Partial<&str>) -> IResult<Partial<&str>, char> {
-/// one_of(|c| c == 'a' || c == 'b').parse_next(i)
+/// one_of(|c| c == 'a' || c == 'b').parse_peek(i)
/// }
/// assert_eq!(parser_fn(Partial::new("abc")), Ok((Partial::new("bc"), 'a')));
-/// assert_eq!(parser_fn(Partial::new("cd")), Err(ErrMode::Backtrack(Error::new(Partial::new("cd"), ErrorKind::Verify))));
+/// assert_eq!(parser_fn(Partial::new("cd")), Err(ErrMode::Backtrack(InputError::new(Partial::new("cd"), ErrorKind::Verify))));
/// assert_eq!(parser_fn(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
#[doc(alias = "char")]
#[doc(alias = "token")]
#[doc(alias = "satisfy")]
-pub fn one_of<I, T, Error: ParseError<I>>(list: T) -> impl Parser<I, <I as Stream>::Token, Error>
+pub fn one_of<I, T, Error: ParserError<I>>(list: T) -> impl Parser<I, <I as Stream>::Token, Error>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: Copy,
+ <I as Stream>::Token: Clone,
T: ContainsToken<<I as Stream>::Token>,
{
trace(
"one_of",
- any.verify(move |t: &<I as Stream>::Token| list.contains_token(*t)),
+ any.verify(move |t: &<I as Stream>::Token| list.contains_token(t.clone())),
)
}
@@ -314,40 +313,40 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// # use winnow::prelude::*;
/// # use winnow::token::none_of;
-/// assert_eq!(none_of::<_, _, Error<_>>("abc").parse_next("z"), Ok(("", 'z')));
-/// assert_eq!(none_of::<_, _, Error<_>>("ab").parse_next("a"), Err(ErrMode::Backtrack(Error::new("a", ErrorKind::Verify))));
-/// assert_eq!(none_of::<_, _, Error<_>>("a").parse_next(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(none_of::<_, _, InputError<_>>(['a', 'b', 'c']).parse_peek("z"), Ok(("", 'z')));
+/// assert_eq!(none_of::<_, _, InputError<_>>(['a', 'b']).parse_peek("a"), Err(ErrMode::Backtrack(InputError::new("a", ErrorKind::Verify))));
+/// assert_eq!(none_of::<_, _, InputError<_>>('a').parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// # use winnow::token::none_of;
-/// assert_eq!(none_of::<_, _, Error<_>>("abc").parse_next(Partial::new("z")), Ok((Partial::new(""), 'z')));
-/// assert_eq!(none_of::<_, _, Error<_>>("ab").parse_next(Partial::new("a")), Err(ErrMode::Backtrack(Error::new(Partial::new("a"), ErrorKind::Verify))));
-/// assert_eq!(none_of::<_, _, Error<_>>("a").parse_next(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(none_of::<_, _, InputError<_>>(['a', 'b', 'c']).parse_peek(Partial::new("z")), Ok((Partial::new(""), 'z')));
+/// assert_eq!(none_of::<_, _, InputError<_>>(['a', 'b']).parse_peek(Partial::new("a")), Err(ErrMode::Backtrack(InputError::new(Partial::new("a"), ErrorKind::Verify))));
+/// assert_eq!(none_of::<_, _, InputError<_>>('a').parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn none_of<I, T, Error: ParseError<I>>(list: T) -> impl Parser<I, <I as Stream>::Token, Error>
+pub fn none_of<I, T, Error: ParserError<I>>(list: T) -> impl Parser<I, <I as Stream>::Token, Error>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: Copy,
+ <I as Stream>::Token: Clone,
T: ContainsToken<<I as Stream>::Token>,
{
trace(
"none_of",
- any.verify(move |t: &<I as Stream>::Token| !list.contains_token(*t)),
+ any.verify(move |t: &<I as Stream>::Token| !list.contains_token(t.clone())),
)
}
/// Recognize the longest (m <= len <= n) input slice that matches the [pattern][ContainsToken]
///
-/// It will return an `ErrMode::Backtrack(Error::new(_, ErrorKind::Slice))` if the pattern wasn't met or is out
+/// It will return an `ErrMode::Backtrack(InputError::new(_, ErrorKind::Slice))` if the pattern wasn't met or is out
/// of range (m <= len <= n).
///
/// *Partial version* will return a `ErrMode::Incomplete(Needed::new(1))` if the pattern reaches the end of the input or is too short.
@@ -358,13 +357,13 @@ where
///
/// Zero or more tokens:
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
-/// take_while(0.., AsChar::is_alpha).parse_next(s)
+/// take_while(0.., AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
@@ -374,14 +373,14 @@ where
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn alpha(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
-/// take_while(0.., AsChar::is_alpha).parse_next(s)
+/// take_while(0.., AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(alpha(Partial::new(b"latin123")), Ok((Partial::new(&b"123"[..]), &b"latin"[..])));
@@ -392,47 +391,47 @@ where
///
/// One or more tokens:
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
-/// take_while(1.., AsChar::is_alpha).parse_next(s)
+/// take_while(1.., AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
/// assert_eq!(alpha(b"latin"), Ok((&b""[..], &b"latin"[..])));
-/// assert_eq!(alpha(b"12345"), Err(ErrMode::Backtrack(Error::new(&b"12345"[..], ErrorKind::Slice))));
+/// assert_eq!(alpha(b"12345"), Err(ErrMode::Backtrack(InputError::new(&b"12345"[..], ErrorKind::Slice))));
///
/// fn hex(s: &str) -> IResult<&str, &str> {
-/// take_while(1.., "1234567890ABCDEF").parse_next(s)
+/// take_while(1.., ('0'..='9', 'A'..='F')).parse_peek(s)
/// }
///
/// assert_eq!(hex("123 and voila"), Ok((" and voila", "123")));
/// assert_eq!(hex("DEADBEEF and others"), Ok((" and others", "DEADBEEF")));
/// assert_eq!(hex("BADBABEsomething"), Ok(("something", "BADBABE")));
/// assert_eq!(hex("D15EA5E"), Ok(("", "D15EA5E")));
-/// assert_eq!(hex(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(hex(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn alpha(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
-/// take_while(1.., AsChar::is_alpha).parse_next(s)
+/// take_while(1.., AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(alpha(Partial::new(b"latin123")), Ok((Partial::new(&b"123"[..]), &b"latin"[..])));
/// assert_eq!(alpha(Partial::new(b"latin")), Err(ErrMode::Incomplete(Needed::new(1))));
-/// assert_eq!(alpha(Partial::new(b"12345")), Err(ErrMode::Backtrack(Error::new(Partial::new(&b"12345"[..]), ErrorKind::Slice))));
+/// assert_eq!(alpha(Partial::new(b"12345")), Err(ErrMode::Backtrack(InputError::new(Partial::new(&b"12345"[..]), ErrorKind::Slice))));
///
/// fn hex(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_while(1.., "1234567890ABCDEF").parse_next(s)
+/// take_while(1.., ('0'..='9', 'A'..='F')).parse_peek(s)
/// }
///
/// assert_eq!(hex(Partial::new("123 and voila")), Ok((Partial::new(" and voila"), "123")));
@@ -444,44 +443,44 @@ where
///
/// Arbitrary amount of tokens:
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn short_alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
-/// take_while(3..=6, AsChar::is_alpha).parse_next(s)
+/// take_while(3..=6, AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(short_alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
/// assert_eq!(short_alpha(b"lengthy"), Ok((&b"y"[..], &b"length"[..])));
/// assert_eq!(short_alpha(b"latin"), Ok((&b""[..], &b"latin"[..])));
-/// assert_eq!(short_alpha(b"ed"), Err(ErrMode::Backtrack(Error::new(&b"ed"[..], ErrorKind::Slice))));
-/// assert_eq!(short_alpha(b"12345"), Err(ErrMode::Backtrack(Error::new(&b"12345"[..], ErrorKind::Slice))));
+/// assert_eq!(short_alpha(b"ed"), Err(ErrMode::Backtrack(InputError::new(&b"ed"[..], ErrorKind::Slice))));
+/// assert_eq!(short_alpha(b"12345"), Err(ErrMode::Backtrack(InputError::new(&b"12345"[..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn short_alpha(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
-/// take_while(3..=6, AsChar::is_alpha).parse_next(s)
+/// take_while(3..=6, AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(short_alpha(Partial::new(b"latin123")), Ok((Partial::new(&b"123"[..]), &b"latin"[..])));
/// assert_eq!(short_alpha(Partial::new(b"lengthy")), Ok((Partial::new(&b"y"[..]), &b"length"[..])));
/// assert_eq!(short_alpha(Partial::new(b"latin")), Err(ErrMode::Incomplete(Needed::new(1))));
/// assert_eq!(short_alpha(Partial::new(b"ed")), Err(ErrMode::Incomplete(Needed::new(1))));
-/// assert_eq!(short_alpha(Partial::new(b"12345")), Err(ErrMode::Backtrack(Error::new(Partial::new(&b"12345"[..]), ErrorKind::Slice))));
+/// assert_eq!(short_alpha(Partial::new(b"12345")), Err(ErrMode::Backtrack(InputError::new(Partial::new(&b"12345"[..]), ErrorKind::Slice))));
/// ```
#[inline(always)]
#[doc(alias = "is_a")]
#[doc(alias = "take_while0")]
#[doc(alias = "take_while1")]
-pub fn take_while<T, I, Error: ParseError<I>>(
+pub fn take_while<T, I, Error: ParserError<I>>(
range: impl Into<Range>,
list: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
@@ -494,7 +493,7 @@ where
start_inclusive,
end_inclusive,
} = range.into();
- trace("take_while", move |i: I| {
+ trace("take_while", move |i: &mut I| {
match (start_inclusive, end_inclusive) {
(0, None) => {
if <I as StreamIsPartial>::is_partial_supported() {
@@ -522,73 +521,127 @@ where
})
}
-/// Deprecated, see [`take_while`]
-#[deprecated(since = "0.4.6", note = "Replaced with `take_while`")]
-#[inline(always)]
-pub fn take_while0<T, I, Error: ParseError<I>>(
- list: T,
-) -> impl Parser<I, <I as Stream>::Slice, Error>
+fn take_while0_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ input: &mut I,
+ list: &T,
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream,
T: ContainsToken<<I as Stream>::Token>,
{
- take_while(0.., list)
+ if PARTIAL && input.is_partial() {
+ take_till0_partial(input, |c| !list.contains_token(c))
+ } else {
+ take_till0_complete(input, |c| !list.contains_token(c))
+ }
}
-/// Deprecated, see [`take_while`]
-#[deprecated(since = "0.4.6", note = "Replaced with `take_while`")]
-#[inline(always)]
-pub fn take_while1<T, I, Error: ParseError<I>>(
- list: T,
-) -> impl Parser<I, <I as Stream>::Slice, Error>
+fn take_while1_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ input: &mut I,
+ list: &T,
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream,
T: ContainsToken<<I as Stream>::Token>,
{
- take_while(1.., list)
+ let e: ErrorKind = ErrorKind::Slice;
+ if PARTIAL && input.is_partial() {
+ take_till1_partial(input, |c| !list.contains_token(c), e)
+ } else {
+ take_till1_complete(input, |c| !list.contains_token(c), e)
+ }
}
-fn take_while0_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- input: I,
- list: &T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+/// Looks for the first element of the input type for which the condition returns true,
+/// and returns the input up to this position.
+///
+/// *Partial version*: If no element is found matching the condition, this will return `Incomplete`
+fn take_till0_partial<P, I: Stream, E: ParserError<I>>(
+ input: &mut I,
+ predicate: P,
+) -> PResult<<I as Stream>::Slice, E>
where
- I: StreamIsPartial,
- I: Stream,
- T: ContainsToken<<I as Stream>::Token>,
+ P: Fn(I::Token) -> bool,
{
- if PARTIAL && input.is_partial() {
- split_at_offset_partial(&input, |c| !list.contains_token(c))
+ let offset = input
+ .offset_for(predicate)
+ .ok_or_else(|| ErrMode::Incomplete(Needed::new(1)))?;
+ Ok(input.next_slice(offset))
+}
+
+/// Looks for the first element of the input type for which the condition returns true
+/// and returns the input up to this position.
+///
+/// Fails if the produced slice is empty.
+///
+/// *Partial version*: If no element is found matching the condition, this will return `Incomplete`
+fn take_till1_partial<P, I: Stream, E: ParserError<I>>(
+ input: &mut I,
+ predicate: P,
+ e: ErrorKind,
+) -> PResult<<I as Stream>::Slice, E>
+where
+ P: Fn(I::Token) -> bool,
+{
+ let offset = input
+ .offset_for(predicate)
+ .ok_or_else(|| ErrMode::Incomplete(Needed::new(1)))?;
+ if offset == 0 {
+ Err(ErrMode::from_error_kind(input, e))
} else {
- split_at_offset_complete(&input, |c| !list.contains_token(c))
+ Ok(input.next_slice(offset))
}
}
-fn take_while1_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- input: I,
- list: &T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+/// Looks for the first element of the input type for which the condition returns true,
+/// and returns the input up to this position.
+///
+/// *Complete version*: If no element is found matching the condition, this will return the whole input
+fn take_till0_complete<P, I: Stream, E: ParserError<I>>(
+ input: &mut I,
+ predicate: P,
+) -> PResult<<I as Stream>::Slice, E>
where
- I: StreamIsPartial,
- I: Stream,
- T: ContainsToken<<I as Stream>::Token>,
+ P: Fn(I::Token) -> bool,
{
- let e: ErrorKind = ErrorKind::Slice;
- if PARTIAL && input.is_partial() {
- split_at_offset1_partial(&input, |c| !list.contains_token(c), e)
+ let offset = input
+ .offset_for(predicate)
+ .unwrap_or_else(|| input.eof_offset());
+ Ok(input.next_slice(offset))
+}
+
+/// Looks for the first element of the input type for which the condition returns true
+/// and returns the input up to this position.
+///
+/// Fails if the produced slice is empty.
+///
+/// *Complete version*: If no element is found matching the condition, this will return the whole input
+fn take_till1_complete<P, I: Stream, E: ParserError<I>>(
+ input: &mut I,
+ predicate: P,
+ e: ErrorKind,
+) -> PResult<<I as Stream>::Slice, E>
+where
+ P: Fn(I::Token) -> bool,
+{
+ let offset = input
+ .offset_for(predicate)
+ .unwrap_or_else(|| input.eof_offset());
+ if offset == 0 {
+ Err(ErrMode::from_error_kind(input, e))
} else {
- split_at_offset1_complete(&input, |c| !list.contains_token(c), e)
+ Ok(input.next_slice(offset))
}
}
-fn take_while_m_n_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- input: I,
+fn take_while_m_n_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ input: &mut I,
m: usize,
n: usize,
list: &T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream,
@@ -615,7 +668,7 @@ where
}
if PARTIAL && input.is_partial() {
if final_count == n {
- Ok(input.next_slice(input.eof_offset()))
+ Ok(input.finish())
} else {
let needed = if m > input.eof_offset() {
m - input.eof_offset()
@@ -626,7 +679,7 @@ where
}
} else {
if m <= final_count {
- Ok(input.next_slice(input.eof_offset()))
+ Ok(input.finish())
} else {
Err(ErrMode::from_error_kind(input, ErrorKind::Slice))
}
@@ -641,12 +694,12 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_till0;
///
/// fn till_colon(s: &str) -> IResult<&str, &str> {
-/// take_till0(|c| c == ':').parse_next(s)
+/// take_till0(|c| c == ':').parse_peek(s)
/// }
///
/// assert_eq!(till_colon("latin:123"), Ok((":123", "latin")));
@@ -656,13 +709,13 @@ where
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_till0;
///
/// fn till_colon(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_till0(|c| c == ':').parse_next(s)
+/// take_till0(|c| c == ':').parse_peek(s)
/// }
///
/// assert_eq!(till_colon(Partial::new("latin:123")), Ok((Partial::new(":123"), "latin")));
@@ -671,7 +724,7 @@ where
/// assert_eq!(till_colon(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn take_till0<T, I, Error: ParseError<I>>(
+pub fn take_till0<T, I, Error: ParserError<I>>(
list: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
@@ -679,18 +732,18 @@ where
I: Stream,
T: ContainsToken<<I as Stream>::Token>,
{
- trace("take_till0", move |i: I| {
+ trace("take_till0", move |i: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() && i.is_partial() {
- split_at_offset_partial(&i, |c| list.contains_token(c))
+ take_till0_partial(i, |c| list.contains_token(c))
} else {
- split_at_offset_complete(&i, |c| list.contains_token(c))
+ take_till0_complete(i, |c| list.contains_token(c))
}
})
}
/// Recognize the longest (at least 1) input slice till a [pattern][ContainsToken] is met.
///
-/// It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Slice)))` if the input is empty or the
+/// It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Slice)))` if the input is empty or the
/// predicate matches the first input.
///
/// *Partial version* will return a `ErrMode::Incomplete(Needed::new(1))` if the match reaches the
@@ -699,46 +752,46 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_till1;
///
/// fn till_colon(s: &str) -> IResult<&str, &str> {
-/// take_till1(|c| c == ':').parse_next(s)
+/// take_till1(|c| c == ':').parse_peek(s)
/// }
///
/// assert_eq!(till_colon("latin:123"), Ok((":123", "latin")));
-/// assert_eq!(till_colon(":empty matched"), Err(ErrMode::Backtrack(Error::new(":empty matched", ErrorKind::Slice))));
+/// assert_eq!(till_colon(":empty matched"), Err(ErrMode::Backtrack(InputError::new(":empty matched", ErrorKind::Slice))));
/// assert_eq!(till_colon("12345"), Ok(("", "12345")));
-/// assert_eq!(till_colon(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(till_colon(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
///
/// fn not_space(s: &str) -> IResult<&str, &str> {
-/// take_till1(" \t\r\n").parse_next(s)
+/// take_till1([' ', '\t', '\r', '\n']).parse_peek(s)
/// }
///
/// assert_eq!(not_space("Hello, World!"), Ok((" World!", "Hello,")));
/// assert_eq!(not_space("Sometimes\t"), Ok(("\t", "Sometimes")));
/// assert_eq!(not_space("Nospace"), Ok(("", "Nospace")));
-/// assert_eq!(not_space(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(not_space(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_till1;
///
/// fn till_colon(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_till1(|c| c == ':').parse_next(s)
+/// take_till1(|c| c == ':').parse_peek(s)
/// }
///
/// assert_eq!(till_colon(Partial::new("latin:123")), Ok((Partial::new(":123"), "latin")));
-/// assert_eq!(till_colon(Partial::new(":empty matched")), Err(ErrMode::Backtrack(Error::new(Partial::new(":empty matched"), ErrorKind::Slice))));
+/// assert_eq!(till_colon(Partial::new(":empty matched")), Err(ErrMode::Backtrack(InputError::new(Partial::new(":empty matched"), ErrorKind::Slice))));
/// assert_eq!(till_colon(Partial::new("12345")), Err(ErrMode::Incomplete(Needed::new(1))));
/// assert_eq!(till_colon(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
///
/// fn not_space(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_till1(" \t\r\n").parse_next(s)
+/// take_till1([' ', '\t', '\r', '\n']).parse_peek(s)
/// }
///
/// assert_eq!(not_space(Partial::new("Hello, World!")), Ok((Partial::new(" World!"), "Hello,")));
@@ -748,7 +801,7 @@ where
/// ```
#[inline(always)]
#[doc(alias = "is_not")]
-pub fn take_till1<T, I, Error: ParseError<I>>(
+pub fn take_till1<T, I, Error: ParserError<I>>(
list: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
@@ -756,19 +809,19 @@ where
I: Stream,
T: ContainsToken<<I as Stream>::Token>,
{
- trace("take_till1", move |i: I| {
+ trace("take_till1", move |i: &mut I| {
let e: ErrorKind = ErrorKind::Slice;
if <I as StreamIsPartial>::is_partial_supported() && i.is_partial() {
- split_at_offset1_partial(&i, |c| list.contains_token(c), e)
+ take_till1_partial(i, |c| list.contains_token(c), e)
} else {
- split_at_offset1_complete(&i, |c| list.contains_token(c), e)
+ take_till1_complete(i, |c| list.contains_token(c), e)
}
})
}
/// Recognize an input slice containing the first N input elements (I[..N]).
///
-/// *Complete version*: It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Slice)))` if the input is shorter than the argument.
+/// *Complete version*: It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Slice)))` if the input is shorter than the argument.
///
/// *Partial version*: if the input has less than N elements, `take` will
/// return a `ErrMode::Incomplete(Needed::new(M))` where M is the number of
@@ -780,18 +833,18 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take;
///
/// fn take6(s: &str) -> IResult<&str, &str> {
-/// take(6usize).parse_next(s)
+/// take(6usize).parse_peek(s)
/// }
///
/// assert_eq!(take6("1234567"), Ok(("7", "123456")));
/// assert_eq!(take6("things"), Ok(("", "things")));
-/// assert_eq!(take6("short"), Err(ErrMode::Backtrack(Error::new("short", ErrorKind::Slice))));
-/// assert_eq!(take6(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(take6("short"), Err(ErrMode::Backtrack(InputError::new("short", ErrorKind::Slice))));
+/// assert_eq!(take6(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// The units that are taken will depend on the input type. For example, for a
@@ -800,21 +853,21 @@ where
///
/// ```rust
/// # use winnow::prelude::*;
-/// use winnow::error::Error;
+/// use winnow::error::InputError;
/// use winnow::token::take;
///
-/// assert_eq!(take::<_, _, Error<_>>(1usize).parse_next("💙"), Ok(("", "💙")));
-/// assert_eq!(take::<_, _, Error<_>>(1usize).parse_next("💙".as_bytes()), Ok((b"\x9F\x92\x99".as_ref(), b"\xF0".as_ref())));
+/// assert_eq!(take::<_, _, InputError<_>>(1usize).parse_peek("💙"), Ok(("", "💙")));
+/// assert_eq!(take::<_, _, InputError<_>>(1usize).parse_peek("💙".as_bytes()), Ok((b"\x9F\x92\x99".as_ref(), b"\xF0".as_ref())));
/// ```
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// use winnow::token::take;
///
/// fn take6(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take(6usize).parse_next(s)
+/// take(6usize).parse_peek(s)
/// }
///
/// assert_eq!(take6(Partial::new("1234567")), Ok((Partial::new("7"), "123456")));
@@ -823,14 +876,14 @@ where
/// assert_eq!(take6(Partial::new("short")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// ```
#[inline(always)]
-pub fn take<C, I, Error: ParseError<I>>(count: C) -> impl Parser<I, <I as Stream>::Slice, Error>
+pub fn take<C, I, Error: ParserError<I>>(count: C) -> impl Parser<I, <I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream,
C: ToUsize,
{
let c = count.to_usize();
- trace("take", move |i: I| {
+ trace("take", move |i: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
take_::<_, _, true>(i, c)
} else {
@@ -839,10 +892,10 @@ where
})
}
-fn take_<I, Error: ParseError<I>, const PARTIAL: bool>(
- i: I,
+fn take_<I, Error: ParserError<I>, const PARTIAL: bool>(
+ i: &mut I,
c: usize,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream,
@@ -858,7 +911,7 @@ where
///
/// It doesn't consume the pattern.
///
-/// *Complete version*: It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Slice)))`
+/// *Complete version*: It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Slice)))`
/// if the pattern wasn't met.
///
/// *Partial version*: will return a `ErrMode::Incomplete(Needed::new(N))` if the input doesn't
@@ -867,28 +920,28 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_until0;
///
/// fn until_eof(s: &str) -> IResult<&str, &str> {
-/// take_until0("eof").parse_next(s)
+/// take_until0("eof").parse_peek(s)
/// }
///
/// assert_eq!(until_eof("hello, worldeof"), Ok(("eof", "hello, world")));
-/// assert_eq!(until_eof("hello, world"), Err(ErrMode::Backtrack(Error::new("hello, world", ErrorKind::Slice))));
-/// assert_eq!(until_eof(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(until_eof("hello, world"), Err(ErrMode::Backtrack(InputError::new("hello, world", ErrorKind::Slice))));
+/// assert_eq!(until_eof(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// assert_eq!(until_eof("1eof2eof"), Ok(("eof2eof", "1")));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_until0;
///
/// fn until_eof(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_until0("eof").parse_next(s)
+/// take_until0("eof").parse_peek(s)
/// }
///
/// assert_eq!(until_eof(Partial::new("hello, worldeof")), Ok((Partial::new("eof"), "hello, world")));
@@ -897,7 +950,7 @@ where
/// assert_eq!(until_eof(Partial::new("1eof2eof")), Ok((Partial::new("eof2eof"), "1")));
/// ```
#[inline(always)]
-pub fn take_until0<T, I, Error: ParseError<I>>(
+pub fn take_until0<T, I, Error: ParserError<I>>(
tag: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
@@ -905,7 +958,7 @@ where
I: Stream + FindSlice<T>,
T: SliceLen + Clone,
{
- trace("take_until0", move |i: I| {
+ trace("take_until0", move |i: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
take_until0_::<_, _, _, true>(i, tag.clone())
} else {
@@ -914,10 +967,10 @@ where
})
}
-fn take_until0_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- i: I,
+fn take_until0_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ i: &mut I,
t: T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream + FindSlice<T>,
@@ -934,7 +987,7 @@ where
///
/// It doesn't consume the pattern.
///
-/// *Complete version*: It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Slice)))`
+/// *Complete version*: It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Slice)))`
/// if the pattern wasn't met.
///
/// *Partial version*: will return a `ErrMode::Incomplete(Needed::new(N))` if the input doesn't
@@ -943,39 +996,39 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_until1;
///
/// fn until_eof(s: &str) -> IResult<&str, &str> {
-/// take_until1("eof").parse_next(s)
+/// take_until1("eof").parse_peek(s)
/// }
///
/// assert_eq!(until_eof("hello, worldeof"), Ok(("eof", "hello, world")));
-/// assert_eq!(until_eof("hello, world"), Err(ErrMode::Backtrack(Error::new("hello, world", ErrorKind::Slice))));
-/// assert_eq!(until_eof(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(until_eof("hello, world"), Err(ErrMode::Backtrack(InputError::new("hello, world", ErrorKind::Slice))));
+/// assert_eq!(until_eof(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// assert_eq!(until_eof("1eof2eof"), Ok(("eof2eof", "1")));
-/// assert_eq!(until_eof("eof"), Err(ErrMode::Backtrack(Error::new("eof", ErrorKind::Slice))));
+/// assert_eq!(until_eof("eof"), Err(ErrMode::Backtrack(InputError::new("eof", ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_until1;
///
/// fn until_eof(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_until1("eof").parse_next(s)
+/// take_until1("eof").parse_peek(s)
/// }
///
/// assert_eq!(until_eof(Partial::new("hello, worldeof")), Ok((Partial::new("eof"), "hello, world")));
/// assert_eq!(until_eof(Partial::new("hello, world")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// assert_eq!(until_eof(Partial::new("hello, worldeo")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// assert_eq!(until_eof(Partial::new("1eof2eof")), Ok((Partial::new("eof2eof"), "1")));
-/// assert_eq!(until_eof(Partial::new("eof")), Err(ErrMode::Backtrack(Error::new(Partial::new("eof"), ErrorKind::Slice))));
+/// assert_eq!(until_eof(Partial::new("eof")), Err(ErrMode::Backtrack(InputError::new(Partial::new("eof"), ErrorKind::Slice))));
/// ```
#[inline(always)]
-pub fn take_until1<T, I, Error: ParseError<I>>(
+pub fn take_until1<T, I, Error: ParserError<I>>(
tag: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
@@ -983,7 +1036,7 @@ where
I: Stream + FindSlice<T>,
T: SliceLen + Clone,
{
- trace("take_until1", move |i: I| {
+ trace("take_until1", move |i: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
take_until1_::<_, _, _, true>(i, tag.clone())
} else {
@@ -992,10 +1045,10 @@ where
})
}
-fn take_until1_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- i: I,
+fn take_until1_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ i: &mut I,
t: T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream + FindSlice<T>,
diff --git a/vendor/winnow/src/token/tests.rs b/vendor/winnow/src/token/tests.rs
index e1c7999c2..d9f364607 100644
--- a/vendor/winnow/src/token/tests.rs
+++ b/vendor/winnow/src/token/tests.rs
@@ -6,11 +6,12 @@ use proptest::prelude::*;
use crate::binary::length_data;
use crate::combinator::delimited;
use crate::error::ErrMode;
-use crate::error::Error;
use crate::error::ErrorKind;
+use crate::error::InputError;
use crate::error::Needed;
use crate::stream::AsChar;
use crate::token::tag;
+use crate::unpeek;
use crate::IResult;
use crate::Parser;
use crate::Partial;
@@ -18,13 +19,13 @@ use crate::Partial;
#[test]
fn complete_take_while_m_n_utf8_all_matching() {
let result: IResult<&str, &str> =
- take_while(1..=4, |c: char| c.is_alphabetic()).parse_next("øn");
+ take_while(1..=4, |c: char| c.is_alphabetic()).parse_peek("øn");
assert_eq!(result, Ok(("", "øn")));
}
#[test]
fn complete_take_while_m_n_utf8_all_matching_substring() {
- let result: IResult<&str, &str> = take_while(1, |c: char| c.is_alphabetic()).parse_next("øn");
+ let result: IResult<&str, &str> = take_while(1, |c: char| c.is_alphabetic()).parse_peek("øn");
assert_eq!(result, Ok(("n", "ø")));
}
@@ -37,7 +38,7 @@ fn model_complete_take_while_m_n(
) -> IResult<&str, &str> {
if n < m {
Err(crate::error::ErrMode::from_error_kind(
- input,
+ &input,
crate::error::ErrorKind::Slice,
))
} else if m <= valid {
@@ -45,7 +46,7 @@ fn model_complete_take_while_m_n(
Ok((&input[offset..], &input[0..offset]))
} else {
Err(crate::error::ErrMode::from_error_kind(
- input,
+ &input,
crate::error::ErrorKind::Slice,
))
}
@@ -59,7 +60,7 @@ proptest! {
let input = format!("{:a<valid$}{:b<invalid$}", "", "", valid=valid, invalid=invalid);
let expected = model_complete_take_while_m_n(m, n, valid, &input);
if m <= n {
- let actual = take_while(m..=n, |c: char| c == 'a').parse_next(input.as_str());
+ let actual = take_while(m..=n, |c: char| c == 'a').parse_peek(input.as_str());
assert_eq!(expected, actual);
}
}
@@ -69,7 +70,7 @@ proptest! {
fn partial_any_str() {
use super::any;
assert_eq!(
- any::<_, Error<Partial<&str>>>(Partial::new("Ә")),
+ any::<_, InputError<Partial<&str>>>.parse_peek(Partial::new("Ә")),
Ok((Partial::new(""), 'Ә'))
);
}
@@ -77,7 +78,7 @@ fn partial_any_str() {
#[test]
fn partial_one_of_test() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> {
- one_of("ab").parse_next(i)
+ one_of(['a', 'b']).parse_peek(i)
}
let a = &b"abcd"[..];
@@ -87,13 +88,13 @@ fn partial_one_of_test() {
assert_eq!(
f(Partial::new(b)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(b),
+ &Partial::new(b),
ErrorKind::Verify
)))
);
fn utf8(i: Partial<&str>) -> IResult<Partial<&str>, char> {
- one_of("+\u{FF0B}").parse_next(i)
+ one_of(['+', '\u{FF0B}']).parse_peek(i)
}
assert!(utf8(Partial::new("+")).is_ok());
@@ -103,14 +104,14 @@ fn partial_one_of_test() {
#[test]
fn char_byteslice() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> {
- 'c'.parse_next(i)
+ 'c'.parse_peek(i)
}
let a = &b"abcd"[..];
assert_eq!(
f(Partial::new(a)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(a),
+ &Partial::new(a),
ErrorKind::Verify
)))
);
@@ -122,14 +123,14 @@ fn char_byteslice() {
#[test]
fn char_str() {
fn f(i: Partial<&str>) -> IResult<Partial<&str>, char> {
- 'c'.parse_next(i)
+ 'c'.parse_peek(i)
}
let a = "abcd";
assert_eq!(
f(Partial::new(a)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(a),
+ &Partial::new(a),
ErrorKind::Verify
)))
);
@@ -141,14 +142,14 @@ fn char_str() {
#[test]
fn partial_none_of_test() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> {
- none_of("ab").parse_next(i)
+ none_of(['a', 'b']).parse_peek(i)
}
let a = &b"abcd"[..];
assert_eq!(
f(Partial::new(a)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(a),
+ &Partial::new(a),
ErrorKind::Verify
)))
);
@@ -160,7 +161,7 @@ fn partial_none_of_test() {
#[test]
fn partial_is_a() {
fn a_or_b(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_while(1.., "ab").parse_next(i)
+ take_while(1.., ['a', 'b']).parse_peek(i)
}
let a = Partial::new(&b"abcd"[..]);
@@ -172,7 +173,7 @@ fn partial_is_a() {
let c = Partial::new(&b"cdef"[..]);
assert_eq!(
a_or_b(c),
- Err(ErrMode::Backtrack(error_position!(c, ErrorKind::Slice)))
+ Err(ErrMode::Backtrack(error_position!(&c, ErrorKind::Slice)))
);
let d = Partial::new(&b"bacdef"[..]);
@@ -182,7 +183,7 @@ fn partial_is_a() {
#[test]
fn partial_is_not() {
fn a_or_b(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_till1("ab").parse_next(i)
+ take_till1(['a', 'b']).parse_peek(i)
}
let a = Partial::new(&b"cdab"[..]);
@@ -194,7 +195,7 @@ fn partial_is_not() {
let c = Partial::new(&b"abab"[..]);
assert_eq!(
a_or_b(c),
- Err(ErrMode::Backtrack(error_position!(c, ErrorKind::Slice)))
+ Err(ErrMode::Backtrack(error_position!(&c, ErrorKind::Slice)))
);
let d = Partial::new(&b"cdefba"[..]);
@@ -207,7 +208,7 @@ fn partial_is_not() {
#[test]
fn partial_take_until_incomplete() {
fn y(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_until0("end").parse_next(i)
+ take_until0("end").parse_peek(i)
}
assert_eq!(
y(Partial::new(&b"nd"[..])),
@@ -226,7 +227,7 @@ fn partial_take_until_incomplete() {
#[test]
fn partial_take_until_incomplete_s() {
fn ys(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_until0("end").parse_next(i)
+ take_until0("end").parse_peek(i)
}
assert_eq!(
ys(Partial::new("123en")),
@@ -244,7 +245,7 @@ fn partial_recognize() {
fn x(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
delimited("<!--", take(5_usize), "-->")
.recognize()
- .parse_next(i)
+ .parse_peek(i)
}
let r = x(Partial::new(&b"<!-- abc --> aaa"[..]));
assert_eq!(r, Ok((Partial::new(&b" aaa"[..]), &b"<!-- abc -->"[..])));
@@ -252,43 +253,43 @@ fn partial_recognize() {
let semicolon = &b";"[..];
fn ya(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- alpha.recognize().parse_next(i)
+ alpha.recognize().parse_peek(i)
}
let ra = ya(Partial::new(&b"abc;"[..]));
assert_eq!(ra, Ok((Partial::new(semicolon), &b"abc"[..])));
fn yd(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- digit.recognize().parse_next(i)
+ digit.recognize().parse_peek(i)
}
let rd = yd(Partial::new(&b"123;"[..]));
assert_eq!(rd, Ok((Partial::new(semicolon), &b"123"[..])));
fn yhd(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- hex_digit.recognize().parse_next(i)
+ hex_digit.recognize().parse_peek(i)
}
let rhd = yhd(Partial::new(&b"123abcDEF;"[..]));
assert_eq!(rhd, Ok((Partial::new(semicolon), &b"123abcDEF"[..])));
fn yod(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- oct_digit.recognize().parse_next(i)
+ oct_digit.recognize().parse_peek(i)
}
let rod = yod(Partial::new(&b"1234567;"[..]));
assert_eq!(rod, Ok((Partial::new(semicolon), &b"1234567"[..])));
fn yan(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- alphanumeric.recognize().parse_next(i)
+ alphanumeric.recognize().parse_peek(i)
}
let ran = yan(Partial::new(&b"123abc;"[..]));
assert_eq!(ran, Ok((Partial::new(semicolon), &b"123abc"[..])));
fn ys(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- space.recognize().parse_next(i)
+ space.recognize().parse_peek(i)
}
let rs = ys(Partial::new(&b" \t;"[..]));
assert_eq!(rs, Ok((Partial::new(semicolon), &b" \t"[..])));
fn yms(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- multispace.recognize().parse_next(i)
+ multispace.recognize().parse_peek(i)
}
let rms = yms(Partial::new(&b" \t\r\n;"[..]));
assert_eq!(rms, Ok((Partial::new(semicolon), &b" \t\r\n"[..])));
@@ -297,7 +298,7 @@ fn partial_recognize() {
#[test]
fn partial_take_while0() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_while(0.., AsChar::is_alpha).parse_next(i)
+ take_while(0.., AsChar::is_alpha).parse_peek(i)
}
let a = &b""[..];
let b = &b"abcd"[..];
@@ -313,7 +314,7 @@ fn partial_take_while0() {
#[test]
fn partial_take_while1() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_while(1.., AsChar::is_alpha).parse_next(i)
+ take_while(1.., AsChar::is_alpha).parse_peek(i)
}
let a = &b""[..];
let b = &b"abcd"[..];
@@ -326,7 +327,7 @@ fn partial_take_while1() {
assert_eq!(
f(Partial::new(d)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(d),
+ &Partial::new(d),
ErrorKind::Slice
)))
);
@@ -335,7 +336,7 @@ fn partial_take_while1() {
#[test]
fn partial_take_while_m_n() {
fn x(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_while(2..=4, AsChar::is_alpha).parse_next(i)
+ take_while(2..=4, AsChar::is_alpha).parse_peek(i)
}
let a = &b""[..];
let b = &b"a"[..];
@@ -355,7 +356,7 @@ fn partial_take_while_m_n() {
assert_eq!(
x(Partial::new(f)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(f),
+ &Partial::new(f),
ErrorKind::Slice
)))
);
@@ -364,7 +365,7 @@ fn partial_take_while_m_n() {
#[test]
fn partial_take_till0() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_till0(AsChar::is_alpha).parse_next(i)
+ take_till0(AsChar::is_alpha).parse_peek(i)
}
let a = &b""[..];
let b = &b"abcd"[..];
@@ -386,7 +387,7 @@ fn partial_take_till0() {
#[test]
fn partial_take_till1() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_till1(AsChar::is_alpha).parse_next(i)
+ take_till1(AsChar::is_alpha).parse_peek(i)
}
let a = &b""[..];
let b = &b"abcd"[..];
@@ -397,7 +398,7 @@ fn partial_take_till1() {
assert_eq!(
f(Partial::new(b)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(b),
+ &Partial::new(b),
ErrorKind::Slice
)))
);
@@ -411,7 +412,7 @@ fn partial_take_till1() {
#[test]
fn partial_take_while_utf8() {
fn f(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(0.., |c| c != '點').parse_next(i)
+ take_while(0.., |c| c != '點').parse_peek(i)
}
assert_eq!(
@@ -429,7 +430,7 @@ fn partial_take_while_utf8() {
);
fn g(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(0.., |c| c == '點').parse_next(i)
+ take_while(0.., |c| c == '點').parse_peek(i)
}
assert_eq!(
@@ -446,7 +447,7 @@ fn partial_take_while_utf8() {
#[test]
fn partial_take_till0_utf8() {
fn f(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_till0(|c| c == '點').parse_next(i)
+ take_till0(|c| c == '點').parse_peek(i)
}
assert_eq!(
@@ -464,7 +465,7 @@ fn partial_take_till0_utf8() {
);
fn g(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_till0(|c| c != '點').parse_next(i)
+ take_till0(|c| c != '點').parse_peek(i)
}
assert_eq!(
@@ -481,7 +482,7 @@ fn partial_take_till0_utf8() {
#[test]
fn partial_take_utf8() {
fn f(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take(3_usize).parse_next(i)
+ take(3_usize).parse_peek(i)
}
assert_eq!(
@@ -501,7 +502,7 @@ fn partial_take_utf8() {
assert_eq!(f(Partial::new("a點b")), Ok((Partial::new(""), "a點b")));
fn g(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(0.., |c| c == '點').parse_next(i)
+ take_while(0.., |c| c == '點').parse_peek(i)
}
assert_eq!(
@@ -518,7 +519,7 @@ fn partial_take_utf8() {
#[test]
fn partial_take_while_m_n_utf8_fixed() {
fn parser(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(1, |c| c == 'A' || c == '😃').parse_next(i)
+ take_while(1, |c| c == 'A' || c == '😃').parse_peek(i)
}
assert_eq!(parser(Partial::new("A!")), Ok((Partial::new("!"), "A")));
assert_eq!(parser(Partial::new("😃!")), Ok((Partial::new("!"), "😃")));
@@ -527,7 +528,7 @@ fn partial_take_while_m_n_utf8_fixed() {
#[test]
fn partial_take_while_m_n_utf8_range() {
fn parser(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(1..=2, |c| c == 'A' || c == '😃').parse_next(i)
+ take_while(1..=2, |c| c == 'A' || c == '😃').parse_peek(i)
}
assert_eq!(parser(Partial::new("A!")), Ok((Partial::new("!"), "A")));
assert_eq!(parser(Partial::new("😃!")), Ok((Partial::new("!"), "😃")));
@@ -536,7 +537,7 @@ fn partial_take_while_m_n_utf8_range() {
#[test]
fn partial_take_while_m_n_utf8_full_match_fixed() {
fn parser(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(1, |c: char| c.is_alphabetic()).parse_next(i)
+ take_while(1, |c: char| c.is_alphabetic()).parse_peek(i)
}
assert_eq!(parser(Partial::new("øn")), Ok((Partial::new("n"), "ø")));
}
@@ -544,7 +545,7 @@ fn partial_take_while_m_n_utf8_full_match_fixed() {
#[test]
fn partial_take_while_m_n_utf8_full_match_range() {
fn parser(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(1..=2, |c: char| c.is_alphabetic()).parse_next(i)
+ take_while(1..=2, |c: char| c.is_alphabetic()).parse_peek(i)
}
assert_eq!(parser(Partial::new("øn")), Ok((Partial::new(""), "øn")));
}
@@ -553,10 +554,10 @@ fn partial_take_while_m_n_utf8_full_match_range() {
#[cfg(feature = "std")]
fn partial_recognize_take_while0() {
fn x(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_while(0.., AsChar::is_alphanum).parse_next(i)
+ take_while(0.., AsChar::is_alphanum).parse_peek(i)
}
fn y(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- x.recognize().parse_next(i)
+ unpeek(x).recognize().parse_peek(i)
}
assert_eq!(
x(Partial::new(&b"ab."[..])),
@@ -573,7 +574,7 @@ fn partial_length_bytes() {
use crate::binary::le_u8;
fn x(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- length_data(le_u8).parse_next(i)
+ length_data(le_u8).parse_peek(i)
}
assert_eq!(
x(Partial::new(b"\x02..>>")),
@@ -593,8 +594,8 @@ fn partial_length_bytes() {
);
fn y(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- let (i, _) = "magic".parse_next(i)?;
- length_data(le_u8).parse_next(i)
+ let (i, _) = "magic".parse_peek(i)?;
+ length_data(le_u8).parse_peek(i)
}
assert_eq!(
y(Partial::new(b"magic\x02..>>")),
@@ -618,7 +619,7 @@ fn partial_length_bytes() {
#[test]
fn partial_case_insensitive() {
fn test(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- tag_no_case("ABcd").parse_next(i)
+ tag_no_case("ABcd").parse_peek(i)
}
assert_eq!(
test(Partial::new(&b"aBCdefgh"[..])),
@@ -639,20 +640,20 @@ fn partial_case_insensitive() {
assert_eq!(
test(Partial::new(&b"Hello"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"Hello"[..]),
+ &Partial::new(&b"Hello"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
test(Partial::new(&b"Hel"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"Hel"[..]),
+ &Partial::new(&b"Hel"[..]),
ErrorKind::Tag
)))
);
fn test2(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- tag_no_case("ABcd").parse_next(i)
+ tag_no_case("ABcd").parse_peek(i)
}
assert_eq!(
test2(Partial::new("aBCdefgh")),
@@ -673,14 +674,14 @@ fn partial_case_insensitive() {
assert_eq!(
test2(Partial::new("Hello")),
Err(ErrMode::Backtrack(error_position!(
- Partial::new("Hello"),
+ &Partial::new("Hello"),
ErrorKind::Tag
)))
);
assert_eq!(
test2(Partial::new("Hel")),
Err(ErrMode::Backtrack(error_position!(
- Partial::new("Hel"),
+ &Partial::new("Hel"),
ErrorKind::Tag
)))
);
@@ -689,10 +690,10 @@ fn partial_case_insensitive() {
#[test]
fn partial_tag_fixed_size_array() {
fn test(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- tag([0x42]).parse_next(i)
+ tag([0x42]).parse_peek(i)
}
fn test2(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- tag(&[0x42]).parse_next(i)
+ tag(&[0x42]).parse_peek(i)
}
let input = Partial::new(&[0x42, 0x00][..]);
assert_eq!(test(input), Ok((Partial::new(&b"\x00"[..]), &b"\x42"[..])));
diff --git a/vendor/winnow/src/trace/internals.rs b/vendor/winnow/src/trace/internals.rs
index 3a10204b7..b990ae7c7 100644
--- a/vendor/winnow/src/trace/internals.rs
+++ b/vendor/winnow/src/trace/internals.rs
@@ -87,17 +87,13 @@ pub fn start<I: Stream>(
};
let call_column = format!("{:depth$}> {name}{count}", "");
- let eof_offset = input.eof_offset();
- let offset = input.offset_at(input_width).unwrap_or(eof_offset);
- let (_, slice) = input.next_slice(offset);
-
// The debug version of `slice` might be wider, either due to rendering one byte as two nibbles or
// escaping in strings.
- let mut debug_slice = format!("{:#?}", slice);
+ let mut debug_slice = format!("{:#?}", input.raw());
let (debug_slice, eof) = if let Some(debug_offset) = debug_slice
.char_indices()
.enumerate()
- .find_map(|(pos, (offset, _))| (input_width <= pos).then(|| offset))
+ .find_map(|(pos, (offset, _))| (input_width <= pos).then_some(offset))
{
debug_slice.truncate(debug_offset);
let eof = "";
@@ -129,7 +125,7 @@ pub fn end(
depth: usize,
name: &dyn crate::lib::std::fmt::Display,
count: usize,
- consumed: Option<usize>,
+ consumed: usize,
severity: Severity,
) {
let gutter_style = anstyle::Style::new().bold();
@@ -146,7 +142,7 @@ pub fn end(
let (status_style, status) = match severity {
Severity::Success => {
let style = anstyle::Style::new().fg_color(Some(anstyle::AnsiColor::Green.into()));
- let status = format!("+{}", consumed.unwrap_or_default());
+ let status = format!("+{}", consumed);
(style, status)
}
Severity::Backtrack => (
diff --git a/vendor/winnow/src/trace/mod.rs b/vendor/winnow/src/trace/mod.rs
index e5eaf9451..316733e9a 100644
--- a/vendor/winnow/src/trace/mod.rs
+++ b/vendor/winnow/src/trace/mod.rs
@@ -26,23 +26,23 @@ compile_error!("`debug` requires `std`");
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed, IResult};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::token::take_while;
/// # use winnow::stream::AsChar;
/// # use winnow::prelude::*;
/// use winnow::trace::trace;
///
-/// fn short_alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
+/// fn short_alpha<'s>(s: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> {
/// trace("short_alpha",
/// take_while(3..=6, AsChar::is_alpha)
/// ).parse_next(s)
/// }
///
-/// assert_eq!(short_alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
-/// assert_eq!(short_alpha(b"lengthy"), Ok((&b"y"[..], &b"length"[..])));
-/// assert_eq!(short_alpha(b"latin"), Ok((&b""[..], &b"latin"[..])));
-/// assert_eq!(short_alpha(b"ed"), Err(ErrMode::Backtrack(Error::new(&b"ed"[..], ErrorKind::Slice))));
-/// assert_eq!(short_alpha(b"12345"), Err(ErrMode::Backtrack(Error::new(&b"12345"[..], ErrorKind::Slice))));
+/// assert_eq!(short_alpha.parse_peek(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
+/// assert_eq!(short_alpha.parse_peek(b"lengthy"), Ok((&b"y"[..], &b"length"[..])));
+/// assert_eq!(short_alpha.parse_peek(b"latin"), Ok((&b""[..], &b"latin"[..])));
+/// assert_eq!(short_alpha.parse_peek(b"ed"), Err(ErrMode::Backtrack(InputError::new(&b"ed"[..], ErrorKind::Slice))));
+/// assert_eq!(short_alpha.parse_peek(b"12345"), Err(ErrMode::Backtrack(InputError::new(&b"12345"[..], ErrorKind::Slice))));
/// ```
#[cfg_attr(not(feature = "debug"), allow(unused_variables))]
#[cfg_attr(not(feature = "debug"), allow(unused_mut))]
@@ -54,21 +54,14 @@ pub fn trace<I: Stream, O, E>(
#[cfg(feature = "debug")]
{
let mut call_count = 0;
- move |i: I| {
+ move |i: &mut I| {
let depth = internals::Depth::new();
- let original = i.clone();
- internals::start(*depth, &name, call_count, &original);
+ let original = i.checkpoint();
+ internals::start(*depth, &name, call_count, i);
let res = parser.parse_next(i);
- let consumed = res.as_ref().ok().map(|(i, _)| {
- if i.eof_offset() == 0 {
- // Sometimes, an unrelated empty string is returned which can break `offset_to`
- original.eof_offset()
- } else {
- original.offset_to(i)
- }
- });
+ let consumed = i.offset_from(&original);
let severity = internals::Severity::with_result(&res);
internals::end(*depth, &name, call_count, consumed, severity);
call_count += 1;