зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1817900 - Update nom to 7.1.3. r=emilio,supply-chain-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D170444
This commit is contained in:
Родитель
12958ab5a5
Коммит
1b107a924a
|
@ -194,7 +194,7 @@ dependencies = [
|
|||
"askama_escape",
|
||||
"mime",
|
||||
"mime_guess",
|
||||
"nom 7.1.1",
|
||||
"nom 7.1.3",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
|
@ -392,7 +392,7 @@ dependencies = [
|
|||
"libudev",
|
||||
"log",
|
||||
"memoffset 0.6.99",
|
||||
"nom 7.1.1",
|
||||
"nom 7.1.3",
|
||||
"nss-gk-api",
|
||||
"pkcs11-bindings",
|
||||
"rand 0.8.5",
|
||||
|
@ -599,7 +599,7 @@ name = "builtins-static"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bindgen 0.63.0",
|
||||
"nom 7.1.1",
|
||||
"nom 7.1.3",
|
||||
"pkcs11-bindings",
|
||||
"smallvec",
|
||||
]
|
||||
|
@ -716,7 +716,7 @@ version = "0.6.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
||||
dependencies = [
|
||||
"nom 7.1.1",
|
||||
"nom 7.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1390,7 +1390,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "9313f104b590510b46fc01c0a324fc76505c13871454d3c48490468d04c8d395"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"nom 7.1.1",
|
||||
"nom 7.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3791,14 +3791,14 @@ dependencies = [
|
|||
name = "nom"
|
||||
version = "6.99.99"
|
||||
dependencies = [
|
||||
"nom 7.1.1",
|
||||
"nom 7.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.1"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
|
@ -6341,7 +6341,7 @@ version = "4.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e79c5206e1f43a2306fd64bdb95025ee4228960f2e6c5a8b173f3caaf807741"
|
||||
dependencies = [
|
||||
"nom 7.1.1",
|
||||
"nom 7.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -1560,6 +1560,11 @@ who = "Mike Hommey <mh+mozilla@glandium.org>"
|
|||
criteria = "safe-to-deploy"
|
||||
delta = "0.25.0 -> 0.25.1"
|
||||
|
||||
[[audits.nom]]
|
||||
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
||||
criteria = "safe-to-deploy"
|
||||
delta = "7.1.1 -> 7.1.3"
|
||||
|
||||
[[audits.nss-gk-api]]
|
||||
who = "John M. Schanck <jschanck@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"CHANGELOG.md":"ee78c17c45b2cb5d50f8631a5e870e59821adc6e62d79562dc61a2f4a3e4a259","Cargo.lock":"b4d8b65e499f30eec76de02be42e8ee4c905b04286f0d7496a14880c6ec562c9","Cargo.toml":"f5b5886c898f5137c388dc46920aeb26700583eeab6857168b374c506636b7d5","LICENSE":"4dbda04344456f09a7a588140455413a9ac59b6b26a1ef7cdf9c800c012d87f0","README.md":"7387399dad4d26aee009ee73d9c171c2fce8a1b015935d263c1d1fc9b12fd61f","doc/nom_recipes.md":"a903a6d8f9e5c935f2a4cbd632f67bc46e41934d1cc8517da9b9e7f3840c9955","src/bits/complete.rs":"cf30854f6e9ed79963408d73c674f8fb5871645c1f991f4e8f1d7026e39681a3","src/bits/mod.rs":"7050e20abffc3d28a41bd1aa3ca3000fb3ee1cb6227662d2fd864b3c9143dd96","src/bits/streaming.rs":"a1ee304ab8c388553927c5c75cf839c6ded397301334bfe2e6653baec233a8fe","src/branch/mod.rs":"78b98e223d5a8104ba203dfc2d78f37d1c11bd050a19859bd3f698653512e642","src/branch/tests.rs":"9a4a7b0c38fc28881d904f8ad6757a23e543f47a4c2d6fd6a9589eeb97209088","src/bytes/complete.rs":"666fa037c63292b1616cbc04c5b414a53c705d0d2ccd8d84399bbe78f573b7e9","src/bytes/mod.rs":"055e264f71a9fa2245be652cc747cfb2c3e34c3c2ba3b75e9611be51fcebea0b","src/bytes/streaming.rs":"e716e6555fbde14bfc2d7358a3edc2191df0522bc55b1f7735f9809ceb235829","src/bytes/tests.rs":"f0d9eb90d72873346e47e5592d30093eb38cbbb5fbf2e769cda776ccfff4f887","src/character/complete.rs":"cf4784f5ecb578ccce4768d44d0a6111a92c18cba874acbbc8ccf935bccc8cd6","src/character/mod.rs":"2fc6a3b19b766a3c37328d62eedbc0c9cb9612aa1d38ececd5cc579b61725fa2","src/character/streaming.rs":"de67ec5663475bc5ffa16f12d121ce9181353b16656b90216704197fca3010fc","src/character/tests.rs":"38958a709f96f077f93a72b32d8ded0a2ad6e488d9aadbe3cf1cfd8adaec06c8","src/combinator/mod.rs":"976a7f19fad4a6685eac9ef77e50f253d59272b0774b9dd5ed74a9d011e49697","src/combinator/tests.rs":"1e56e2c1263d93bfbd244d24160a0bea41731e5158d57382e69c215427770b94","src/error.rs":"9d9bf87e76b47cfd9170f8ae50b6deeb02ff1c296aac3eb4f71ee1474dc0fba5","src/internal.rs":"0614a179d7ae01c9e84812b9a3a379ac6d014972718045f84b91a72f2d18ac01","src/lib.rs":"b20780277606306985201eb9a55d01e022f8905c3f829357b214a5bb4a4e3c9e","src/multi/mod.rs":"e75721268620f20b63d9b10fa56bf74da1b66730c70ec30fd05a913e62197680","src/multi/tests.rs":"806f89f5f347978c22e9b8cc7f8a49ad1d1fe23bff5974725b643a2ceffe8cb0","src/number/complete.rs":"2b9f339b8648884ddb0dc449be861477283d5422c17ca4b69c377cd6d12ce21b","src/number/mod.rs":"ba6eb439ee0befcc0872be7ce43b4836622af45c3dc2fc003b0d909ee42d7b20","src/number/streaming.rs":"bd0e382ad150001da5ef1d5c7f003797b3468d56fa0f577d6d31aa0259157766","src/sequence/mod.rs":"adfa5bc34db12deb9581fbc02a0ecc3e2a16a7bb0d1a65696fcec0262d3cbbff","src/sequence/tests.rs":"832d44097b79056879eca93ef10655143bc8caf6fac6364ff7ff153d3357e4ad","src/str.rs":"f26aa11f43e8a4a300ea0f310d599fab3f809102cfb29033ddf84f299ee8010c","src/traits.rs":"cc8cb6ec294abce16be82c10131552bb37deae56b893db1bdb0e666c0b0a18ff","tests/arithmetic.rs":"725efba4fc6cc811f542f3bcc8c7afd52702a66f64319d4f2796225e2e75d0ca","tests/arithmetic_ast.rs":"c7c28c988640405dd250c86045bbda75fc6ead2a769fb05eafbfbe74d97e0485","tests/css.rs":"36a2198e42e601efc611ebd6b3c6861f3ccb6a63525829ae6a2603bcdc4c2b11","tests/custom_errors.rs":"354d5a82a4f5a24b97901a3b411b4eab038c4d034047971956b9cdc12538e50d","tests/escaped.rs":"c25987ea6d9a7dde74d58a49c332d223da3a495569cb79e3fe921bce51729ead","tests/float.rs":"cdac92fb14afb75cba9d6b8f568e272a630b2cfb9f096b76c91909a3cd016869","tests/fnmut.rs":"dc9b6140eb3405d1497b05675fc4d3050785771a2afa81990d684b2edd0c9746","tests/ini.rs":"f0ce38b90057e9e0fd2329819395c420cbf1400457f9c4279414301faa38b19c","tests/ini_str.rs":"4c8f6ce3a2a245e8365837b873c25d2d8f24887313b791e2edd09a76a2d98947","tests/issues.rs":"7c348420ed836c0c79bbb4cd18e936b38f6f75d5f0a3122faee13ef3005345a4","tests/json.rs":"8672fca70b889d6243a2f0f4c99389e22200e4363f253e83a3f26620b92f765e","tests/mp4.rs":"db6568ee9ccad70a7b567295831b961b369011f66dc2dd406851208007588600","tests/multiline.rs":"aef9768beaf5042b8629599b2094712646abb23eb11fa662b5a9bf3dfa432547","tests/overflow.rs":"a249ebeebfc5228faf9bfd5241a54a8181df476c4699ef87bb7d8a2161b9fc72","tests/reborrow_fold.rs":"66230bacd8d36e1559f1dc919ae8eab3515963c4aef85a079ec56218c9a6e676"},"package":"a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"}
|
||||
{"files":{"CHANGELOG.md":"fd79f8ab367d50fd57136744fa2e0a198c279c9707c2a45f00ad1b62d0a637ab","Cargo.lock":"3b95f09a31e1fc281ef890f9623ac84f0a58bc3454a96b652d2f0682963f29b5","Cargo.toml":"9d07fd5cc339d8f7c0c164b2568164b808dee1d441b17631cb7b7d44d39ed778","LICENSE":"4dbda04344456f09a7a588140455413a9ac59b6b26a1ef7cdf9c800c012d87f0","README.md":"3cbdcb07f9ef189ad617f40423a17f1e48ee5aba3f118f261886c139d64d26ae","doc/nom_recipes.md":"a903a6d8f9e5c935f2a4cbd632f67bc46e41934d1cc8517da9b9e7f3840c9955","src/bits/complete.rs":"640bdcad311a05d94e4b3a1a8b2105c540f80864edb75de0a570f03d4055e5ed","src/bits/mod.rs":"1c6aa26887d379384c1c823684e6f8e91b59df72664eefd8ddf0b6ca5517e669","src/bits/streaming.rs":"304cc5d565cfa30075827c1d6cb173b7cb92b101d8ebe9bc50476a00c92fd5dc","src/branch/mod.rs":"dbe1ed1bb0230310adf8e8d15e6afcf8826c7a111f8429e13fe3e9ebd3fbeae0","src/branch/tests.rs":"9a4a7b0c38fc28881d904f8ad6757a23e543f47a4c2d6fd6a9589eeb97209088","src/bytes/complete.rs":"666fa037c63292b1616cbc04c5b414a53c705d0d2ccd8d84399bbe78f573b7e9","src/bytes/mod.rs":"055e264f71a9fa2245be652cc747cfb2c3e34c3c2ba3b75e9611be51fcebea0b","src/bytes/streaming.rs":"e716e6555fbde14bfc2d7358a3edc2191df0522bc55b1f7735f9809ceb235829","src/bytes/tests.rs":"f0d9eb90d72873346e47e5592d30093eb38cbbb5fbf2e769cda776ccfff4f887","src/character/complete.rs":"7eeb5f00baab7aeaf7f392e5872d141d352951a146c0396721dab71e29b4c87b","src/character/mod.rs":"2fc6a3b19b766a3c37328d62eedbc0c9cb9612aa1d38ececd5cc579b61725fa2","src/character/streaming.rs":"de67ec5663475bc5ffa16f12d121ce9181353b16656b90216704197fca3010fc","src/character/tests.rs":"38958a709f96f077f93a72b32d8ded0a2ad6e488d9aadbe3cf1cfd8adaec06c8","src/combinator/mod.rs":"f7b9c35734f10a4b46d2e2ae874628d48fa1fe0bfc9f44325a89a14b3cfaea02","src/combinator/tests.rs":"1e56e2c1263d93bfbd244d24160a0bea41731e5158d57382e69c215427770b94","src/error.rs":"9d9bf87e76b47cfd9170f8ae50b6deeb02ff1c296aac3eb4f71ee1474dc0fba5","src/internal.rs":"5e670e0f5955af13da4b9a98d444fc721d38835b4637fe8170871fefef4e04cb","src/lib.rs":"9e05f2447ef1e5e9418953300c97d297f26f8f33c0528733a7681d8cb458346e","src/macros.rs":"11ac3dee346e5bf61015f328975cf6ea6f438683eb3b8b6c7c8e6383b0c5b7af","src/multi/mod.rs":"6093bd5909ddae76309442eba3a33716d279d219e5933a0dedef977312d6c5f8","src/multi/tests.rs":"806f89f5f347978c22e9b8cc7f8a49ad1d1fe23bff5974725b643a2ceffe8cb0","src/number/complete.rs":"a4f312c200710a446986142d19ebc78727265cf2c3b07b70dd84339051040bdd","src/number/mod.rs":"ba6eb439ee0befcc0872be7ce43b4836622af45c3dc2fc003b0d909ee42d7b20","src/number/streaming.rs":"1c2137235f093857e545069d687f50712ea457fac03961f3f6ac15c0f7e40c2a","src/sequence/mod.rs":"2dff114a950965e321cafdb215a441990f35d28756b12b2891179f348268fca2","src/sequence/tests.rs":"8dc4ca519b274d4e0694b373b2710c2e947e6074d43ec6a738a74113a09379f5","src/str.rs":"f26aa11f43e8a4a300ea0f310d599fab3f809102cfb29033ddf84f299ee8010c","src/traits.rs":"01934f8a61fc3cc5a03438a10751d3b074c89e5f3bcc96df8e43cf6b09be2308","tests/arithmetic.rs":"725efba4fc6cc811f542f3bcc8c7afd52702a66f64319d4f2796225e2e75d0ca","tests/arithmetic_ast.rs":"c7c28c988640405dd250c86045bbda75fc6ead2a769fb05eafbfbe74d97e0485","tests/css.rs":"36a2198e42e601efc611ebd6b3c6861f3ccb6a63525829ae6a2603bcdc4c2b11","tests/custom_errors.rs":"354d5a82a4f5a24b97901a3b411b4eab038c4d034047971956b9cdc12538e50d","tests/escaped.rs":"c25987ea6d9a7dde74d58a49c332d223da3a495569cb79e3fe921bce51729ead","tests/float.rs":"cdac92fb14afb75cba9d6b8f568e272a630b2cfb9f096b76c91909a3cd016869","tests/fnmut.rs":"dc9b6140eb3405d1497b05675fc4d3050785771a2afa81990d684b2edd0c9746","tests/ini.rs":"f0ce38b90057e9e0fd2329819395c420cbf1400457f9c4279414301faa38b19c","tests/ini_str.rs":"4c8f6ce3a2a245e8365837b873c25d2d8f24887313b791e2edd09a76a2d98947","tests/issues.rs":"1322ffc270ba1bedf39b295eb622ead2715ab7d60db0181af5305a0429c7819e","tests/json.rs":"8672fca70b889d6243a2f0f4c99389e22200e4363f253e83a3f26620b92f765e","tests/mp4.rs":"db6568ee9ccad70a7b567295831b961b369011f66dc2dd406851208007588600","tests/multiline.rs":"aef9768beaf5042b8629599b2094712646abb23eb11fa662b5a9bf3dfa432547","tests/overflow.rs":"a249ebeebfc5228faf9bfd5241a54a8181df476c4699ef87bb7d8a2161b9fc72","tests/reborrow_fold.rs":"66230bacd8d36e1559f1dc919ae8eab3515963c4aef85a079ec56218c9a6e676"},"package":"d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"}
|
|
@ -6,6 +6,71 @@
|
|||
|
||||
### Changed
|
||||
|
||||
## 7.1.3 - 2023-01-15
|
||||
|
||||
### Thanks
|
||||
|
||||
- @Shadow53
|
||||
|
||||
### Fixed
|
||||
|
||||
- panic in `many` and `count` combinators when the output type is zero sized
|
||||
|
||||
## 7.1.2 - 2023-01-01
|
||||
|
||||
### Thanks
|
||||
|
||||
- @joubs
|
||||
- @Fyko
|
||||
- @LoganDark
|
||||
- @darnuria
|
||||
- @jkugelman
|
||||
- @barower
|
||||
- @puzzlewolf
|
||||
- @epage
|
||||
- @cky
|
||||
- @wolthom
|
||||
- @w1ll-i-code
|
||||
|
||||
### Changed
|
||||
|
||||
- documentation fixes
|
||||
- tests fixes
|
||||
- limit the initial capacity of the result vector of `many_m_n` to 64kiB
|
||||
- bits parser now accept `Parser` implementors instead of only functions
|
||||
|
||||
### Added
|
||||
|
||||
- implement `Tuple` parsing for the unit type as a special case
|
||||
- implement `ErrorConvert` on the unit type to make it usable as error type for bits parsers
|
||||
- bool parser for bits input
|
||||
|
||||
## 7.1.1 - 2022-03-14
|
||||
|
||||
### Thanks
|
||||
|
||||
- @ThomasdenH
|
||||
- @@SphinxKnight
|
||||
- @irevoire
|
||||
- @doehyunbaek
|
||||
- @pxeger
|
||||
- @punkeel
|
||||
- @max-sixty
|
||||
- @Xiretza
|
||||
- @5c077m4n
|
||||
- @erihsu
|
||||
- @TheNeikos
|
||||
- @LoganDark
|
||||
- @nickelc
|
||||
- @chotchki
|
||||
- @ctrlcctrlv
|
||||
|
||||
|
||||
### Changed
|
||||
|
||||
- documentation fixes
|
||||
- more examples
|
||||
|
||||
## 7.1.0 - 2021-11-04
|
||||
|
||||
### Thanks
|
||||
|
@ -1420,7 +1485,11 @@ Considering the number of changes since the last release, this version can conta
|
|||
|
||||
## Compare code
|
||||
|
||||
* [unreleased](https://github.com/Geal/nom/compare/7.0.0...HEAD)
|
||||
* [unreleased](https://github.com/Geal/nom/compare/7.1.3...HEAD)
|
||||
* [7.1.2](https://github.com/Geal/nom/compare/7.1.2...7.1.3)
|
||||
* [7.1.2](https://github.com/Geal/nom/compare/7.1.1...7.1.2)
|
||||
* [7.1.1](https://github.com/Geal/nom/compare/7.1.0...7.1.1)
|
||||
* [7.1.0](https://github.com/Geal/nom/compare/7.0.0...7.1.0)
|
||||
* [7.0.0](https://github.com/Geal/nom/compare/6.2.1...7.0.0)
|
||||
* [6.2.1](https://github.com/Geal/nom/compare/6.2.0...6.2.1)
|
||||
* [6.2.0](https://github.com/Geal/nom/compare/6.1.2...6.2.0)
|
||||
|
|
|
@ -90,7 +90,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
|||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.1"
|
||||
version = "7.1.3"
|
||||
dependencies = [
|
||||
"doc-comment",
|
||||
"memchr",
|
||||
|
|
|
@ -13,30 +13,62 @@
|
|||
edition = "2018"
|
||||
rust-version = "1.48"
|
||||
name = "nom"
|
||||
version = "7.1.1"
|
||||
version = "7.1.3"
|
||||
authors = ["contact@geoffroycouprie.com"]
|
||||
include = ["CHANGELOG.md", "LICENSE", "README.md", ".gitignore", "Cargo.toml", "src/*.rs", "src/*/*.rs", "tests/*.rs", "doc/nom_recipes.md"]
|
||||
include = [
|
||||
"CHANGELOG.md",
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
".gitignore",
|
||||
"Cargo.toml",
|
||||
"src/*.rs",
|
||||
"src/*/*.rs",
|
||||
"tests/*.rs",
|
||||
"doc/nom_recipes.md",
|
||||
]
|
||||
autoexamples = false
|
||||
description = "A byte-oriented, zero-copy, parser combinators library"
|
||||
documentation = "https://docs.rs/nom"
|
||||
readme = "README.md"
|
||||
keywords = ["parser", "parser-combinators", "parsing", "streaming", "bit"]
|
||||
keywords = [
|
||||
"parser",
|
||||
"parser-combinators",
|
||||
"parsing",
|
||||
"streaming",
|
||||
"bit",
|
||||
]
|
||||
categories = ["parsing"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/Geal/nom"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = [
|
||||
"alloc",
|
||||
"std",
|
||||
"docsrs",
|
||||
]
|
||||
all-features = true
|
||||
features = ["alloc", "std", "docsrs"]
|
||||
|
||||
[profile.bench]
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
debug = true
|
||||
|
||||
[[example]]
|
||||
name = "custom_error"
|
||||
path = "examples/custom_error.rs"
|
||||
required-features = ["alloc"]
|
||||
|
||||
[[example]]
|
||||
name = "json"
|
||||
path = "examples/json.rs"
|
||||
required-features = ["alloc"]
|
||||
|
||||
[[example]]
|
||||
name = "json_iterator"
|
||||
path = "examples/json_iterator.rs"
|
||||
required-features = ["alloc"]
|
||||
|
||||
[[example]]
|
||||
name = "iterator"
|
||||
path = "examples/iterator.rs"
|
||||
|
@ -99,6 +131,7 @@ name = "reborrow_fold"
|
|||
[[test]]
|
||||
name = "fnmut"
|
||||
required-features = ["alloc"]
|
||||
|
||||
[dependencies.memchr]
|
||||
version = "2.3"
|
||||
default-features = false
|
||||
|
@ -106,6 +139,7 @@ default-features = false
|
|||
[dependencies.minimal-lexical]
|
||||
version = "0.2.0"
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.doc-comment]
|
||||
version = "0.3"
|
||||
|
||||
|
@ -116,7 +150,12 @@ version = "1.0.0"
|
|||
alloc = []
|
||||
default = ["std"]
|
||||
docsrs = []
|
||||
std = ["alloc", "memchr/std", "minimal-lexical/std"]
|
||||
std = [
|
||||
"alloc",
|
||||
"memchr/std",
|
||||
"minimal-lexical/std",
|
||||
]
|
||||
|
||||
[badges.coveralls]
|
||||
branch = "main"
|
||||
repository = "Geal/nom"
|
||||
|
|
|
@ -17,6 +17,25 @@ error prone plumbing.
|
|||
|
||||
*nom will happily take a byte out of your files :)*
|
||||
|
||||
<!-- toc -->
|
||||
|
||||
- [Example](#example)
|
||||
- [Documentation](#documentation)
|
||||
- [Why use nom?](#why-use-nom)
|
||||
- [Binary format parsers](#binary-format-parsers)
|
||||
- [Text format parsers](#text-format-parsers)
|
||||
- [Programming language parsers](#programming-language-parsers)
|
||||
- [Streaming formats](#streaming-formats)
|
||||
- [Parser combinators](#parser-combinators)
|
||||
- [Technical features](#technical-features)
|
||||
- [Rust version requirements](#rust-version-requirements-msrv)
|
||||
- [Installation](#installation)
|
||||
- [Related projects](#related-projects)
|
||||
- [Parsers written with nom](#parsers-written-with-nom)
|
||||
- [Contributors](#contributors)
|
||||
|
||||
<!-- tocstop -->
|
||||
|
||||
## Example
|
||||
|
||||
[Hexadecimal color](https://developer.mozilla.org/en-US/docs/Web/CSS/color) parser:
|
||||
|
@ -296,7 +315,8 @@ Here is a (non exhaustive) list of known projects using nom:
|
|||
[Telcordia/Bellcore SR-4731 SOR OTDR files](https://github.com/JamesHarrison/otdrs),
|
||||
[MySQL binary log](https://github.com/PrivateRookie/boxercrab),
|
||||
[URI](https://github.com/Skasselbard/nom-uri),
|
||||
[Furigana](https://github.com/sachaarbonel/furigana.rs)
|
||||
[Furigana](https://github.com/sachaarbonel/furigana.rs),
|
||||
[Wordle Result](https://github.com/Fyko/wordle-stats/tree/main/parser)
|
||||
|
||||
Want to create a new parser using `nom`? A list of not yet implemented formats is available [here](https://github.com/Geal/nom/issues/14).
|
||||
|
||||
|
|
|
@ -105,6 +105,29 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Parses one specific bit as a bool.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// # use nom::bits::complete::bool;
|
||||
/// # use nom::IResult;
|
||||
/// # use nom::error::{Error, ErrorKind};
|
||||
///
|
||||
/// fn parse(input: (&[u8], usize)) -> IResult<(&[u8], usize), bool> {
|
||||
/// bool(input)
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(parse(([0b10000000].as_ref(), 0)), Ok((([0b10000000].as_ref(), 1), true)));
|
||||
/// assert_eq!(parse(([0b10000000].as_ref(), 1)), Ok((([0b10000000].as_ref(), 2), false)));
|
||||
/// ```
|
||||
pub fn bool<I, E: ParseError<(I, usize)>>(input: (I, usize)) -> IResult<(I, usize), bool, E>
|
||||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
let (res, bit): (_, u32) = take(1usize)(input)?;
|
||||
Ok((res, bit != 0))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
@ -147,4 +170,28 @@ mod test {
|
|||
Ok((([0b11111111].as_ref(), 4), 0b1000110100111111111111))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bool_0() {
|
||||
let input = [0b10000000].as_ref();
|
||||
|
||||
let result: crate::IResult<(&[u8], usize), bool> = bool((input, 0));
|
||||
|
||||
assert_eq!(result, Ok(((input, 1), true)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bool_eof() {
|
||||
let input = [0b10000000].as_ref();
|
||||
|
||||
let result: crate::IResult<(&[u8], usize), bool> = bool((input, 8));
|
||||
|
||||
assert_eq!(
|
||||
result,
|
||||
Err(crate::Err::Error(crate::error::Error {
|
||||
input: (input, 8),
|
||||
code: ErrorKind::Eof
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ pub mod complete;
|
|||
pub mod streaming;
|
||||
|
||||
use crate::error::{ErrorKind, ParseError};
|
||||
use crate::internal::{Err, IResult, Needed};
|
||||
use crate::internal::{Err, IResult, Needed, Parser};
|
||||
use crate::lib::std::ops::RangeFrom;
|
||||
use crate::traits::{ErrorConvert, Slice};
|
||||
|
||||
|
@ -42,9 +42,9 @@ where
|
|||
E1: ParseError<(I, usize)> + ErrorConvert<E2>,
|
||||
E2: ParseError<I>,
|
||||
I: Slice<RangeFrom<usize>>,
|
||||
P: FnMut((I, usize)) -> IResult<(I, usize), O, E1>,
|
||||
P: Parser<(I, usize), O, E1>,
|
||||
{
|
||||
move |input: I| match parser((input, 0)) {
|
||||
move |input: I| match parser.parse((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.
|
||||
|
@ -88,7 +88,7 @@ where
|
|||
E1: ParseError<I> + ErrorConvert<E2>,
|
||||
E2: ParseError<(I, usize)>,
|
||||
I: Slice<RangeFrom<usize>> + Clone,
|
||||
P: FnMut(I) -> IResult<I, O, E1>,
|
||||
P: Parser<I, O, E1>,
|
||||
{
|
||||
move |(input, offset): (I, usize)| {
|
||||
let inner = if offset % 8 != 0 {
|
||||
|
@ -97,7 +97,7 @@ where
|
|||
input.slice((offset / 8)..)
|
||||
};
|
||||
let i = (input, offset);
|
||||
match parser(inner) {
|
||||
match parser.parse(inner) {
|
||||
Ok((rest, res)) => Ok(((rest, 0), res)),
|
||||
Err(Err::Incomplete(Needed::Unknown)) => Err(Err::Incomplete(Needed::Unknown)),
|
||||
Err(Err::Incomplete(Needed::Size(sz))) => Err(match sz.get().checked_mul(8) {
|
||||
|
|
|
@ -79,6 +79,29 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Parses one specific bit as a bool.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// # use nom::bits::complete::bool;
|
||||
/// # use nom::IResult;
|
||||
/// # use nom::error::{Error, ErrorKind};
|
||||
///
|
||||
/// fn parse(input: (&[u8], usize)) -> IResult<(&[u8], usize), bool> {
|
||||
/// bool(input)
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(parse(([0b10000000].as_ref(), 0)), Ok((([0b10000000].as_ref(), 1), true)));
|
||||
/// assert_eq!(parse(([0b10000000].as_ref(), 1)), Ok((([0b10000000].as_ref(), 2), false)));
|
||||
/// ```
|
||||
pub fn bool<I, E: ParseError<(I, usize)>>(input: (I, usize)) -> IResult<(I, usize), bool, E>
|
||||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
let (res, bit): (_, u32) = take(1usize)(input)?;
|
||||
Ok((res, bit != 0))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
@ -126,4 +149,22 @@ mod test {
|
|||
}))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bool_0() {
|
||||
let input = [0b10000000].as_ref();
|
||||
|
||||
let result: crate::IResult<(&[u8], usize), bool> = bool((input, 0));
|
||||
|
||||
assert_eq!(result, Ok(((input, 1), true)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bool_eof() {
|
||||
let input = [0b10000000].as_ref();
|
||||
|
||||
let result: crate::IResult<(&[u8], usize), bool> = bool((input, 8));
|
||||
|
||||
assert_eq!(result, Err(crate::Err::Incomplete(Needed::new(1))));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +1,5 @@
|
|||
//! Choice combinators
|
||||
|
||||
macro_rules! succ (
|
||||
(0, $submac:ident ! ($($rest:tt)*)) => ($submac!(1, $($rest)*));
|
||||
(1, $submac:ident ! ($($rest:tt)*)) => ($submac!(2, $($rest)*));
|
||||
(2, $submac:ident ! ($($rest:tt)*)) => ($submac!(3, $($rest)*));
|
||||
(3, $submac:ident ! ($($rest:tt)*)) => ($submac!(4, $($rest)*));
|
||||
(4, $submac:ident ! ($($rest:tt)*)) => ($submac!(5, $($rest)*));
|
||||
(5, $submac:ident ! ($($rest:tt)*)) => ($submac!(6, $($rest)*));
|
||||
(6, $submac:ident ! ($($rest:tt)*)) => ($submac!(7, $($rest)*));
|
||||
(7, $submac:ident ! ($($rest:tt)*)) => ($submac!(8, $($rest)*));
|
||||
(8, $submac:ident ! ($($rest:tt)*)) => ($submac!(9, $($rest)*));
|
||||
(9, $submac:ident ! ($($rest:tt)*)) => ($submac!(10, $($rest)*));
|
||||
(10, $submac:ident ! ($($rest:tt)*)) => ($submac!(11, $($rest)*));
|
||||
(11, $submac:ident ! ($($rest:tt)*)) => ($submac!(12, $($rest)*));
|
||||
(12, $submac:ident ! ($($rest:tt)*)) => ($submac!(13, $($rest)*));
|
||||
(13, $submac:ident ! ($($rest:tt)*)) => ($submac!(14, $($rest)*));
|
||||
(14, $submac:ident ! ($($rest:tt)*)) => ($submac!(15, $($rest)*));
|
||||
(15, $submac:ident ! ($($rest:tt)*)) => ($submac!(16, $($rest)*));
|
||||
(16, $submac:ident ! ($($rest:tt)*)) => ($submac!(17, $($rest)*));
|
||||
(17, $submac:ident ! ($($rest:tt)*)) => ($submac!(18, $($rest)*));
|
||||
(18, $submac:ident ! ($($rest:tt)*)) => ($submac!(19, $($rest)*));
|
||||
(19, $submac:ident ! ($($rest:tt)*)) => ($submac!(20, $($rest)*));
|
||||
(20, $submac:ident ! ($($rest:tt)*)) => ($submac!(21, $($rest)*));
|
||||
);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
|
|
|
@ -218,7 +218,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Optional parser: Will return `None` if not successful.
|
||||
/// Optional parser, will return `None` on [`Err::Error`].
|
||||
///
|
||||
/// To chain an error up, see [`cut`].
|
||||
///
|
||||
/// ```rust
|
||||
/// # use nom::{Err,error::ErrorKind, IResult};
|
||||
|
@ -575,18 +577,55 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// transforms an error to failure
|
||||
/// Transforms an [`Err::Error`] (recoverable) to [`Err::Failure`] (unrecoverable)
|
||||
///
|
||||
/// This commits the parse result, preventing alternative branch paths like with
|
||||
/// [`nom::branch::alt`][crate::branch::alt].
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// Without `cut`:
|
||||
/// ```rust
|
||||
/// # use nom::{Err,error::ErrorKind, IResult};
|
||||
/// use nom::combinator::cut;
|
||||
/// use nom::character::complete::alpha1;
|
||||
/// # use nom::character::complete::{one_of, digit1};
|
||||
/// # use nom::combinator::rest;
|
||||
/// # use nom::branch::alt;
|
||||
/// # use nom::sequence::preceded;
|
||||
/// # fn main() {
|
||||
///
|
||||
/// let mut parser = cut(alpha1);
|
||||
/// fn parser(input: &str) -> IResult<&str, &str> {
|
||||
/// alt((
|
||||
/// preceded(one_of("+-"), digit1),
|
||||
/// rest
|
||||
/// ))(input)
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(parser("abcd;"), Ok((";", "abcd")));
|
||||
/// assert_eq!(parser("123;"), Err(Err::Failure(("123;", ErrorKind::Alpha))));
|
||||
/// assert_eq!(parser("+10 ab"), Ok((" ab", "10")));
|
||||
/// assert_eq!(parser("ab"), Ok(("", "ab")));
|
||||
/// assert_eq!(parser("+"), Ok(("", "+")));
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// With `cut`:
|
||||
/// ```rust
|
||||
/// # use nom::{Err,error::ErrorKind, IResult, error::Error};
|
||||
/// # use nom::character::complete::{one_of, digit1};
|
||||
/// # use nom::combinator::rest;
|
||||
/// # use nom::branch::alt;
|
||||
/// # use nom::sequence::preceded;
|
||||
/// use nom::combinator::cut;
|
||||
/// # fn main() {
|
||||
///
|
||||
/// fn parser(input: &str) -> IResult<&str, &str> {
|
||||
/// alt((
|
||||
/// preceded(one_of("+-"), cut(digit1)),
|
||||
/// rest
|
||||
/// ))(input)
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(parser("+10 ab"), Ok((" ab", "10")));
|
||||
/// assert_eq!(parser("ab"), Ok(("", "ab")));
|
||||
/// assert_eq!(parser("+"), Err(Err::Failure(Error { input: "", code: ErrorKind::Digit })));
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn cut<I, O, E: ParseError<I>, F>(mut parser: F) -> impl FnMut(I) -> IResult<I, O, E>
|
||||
|
@ -643,6 +682,8 @@ where
|
|||
/// Call the iterator's [ParserIterator::finish] method to get the remaining input if successful,
|
||||
/// or the error value if we encountered an error.
|
||||
///
|
||||
/// On [`Err::Error`], iteration will stop. To instead chain an error up, see [`cut`].
|
||||
///
|
||||
/// ```rust
|
||||
/// use nom::{combinator::iterator, IResult, bytes::complete::tag, character::complete::alpha1, sequence::terminated};
|
||||
/// use std::collections::HashMap;
|
||||
|
|
|
@ -473,7 +473,9 @@ mod tests {
|
|||
#[cfg(target_pointer_width = "64")]
|
||||
fn size_test() {
|
||||
assert_size!(IResult<&[u8], &[u8], (&[u8], u32)>, 40);
|
||||
assert_size!(IResult<&str, &str, u32>, 40);
|
||||
//FIXME: since rust 1.65, this is now 32 bytes, likely thanks to https://github.com/rust-lang/rust/pull/94075
|
||||
// deactivating that test for now because it'll have different values depending on the rust version
|
||||
// assert_size!(IResult<&str, &str, u32>, 40);
|
||||
assert_size!(Needed, 8);
|
||||
assert_size!(Err<u32>, 16);
|
||||
assert_size!(ErrorKind, 1);
|
||||
|
|
|
@ -438,16 +438,17 @@ pub use self::traits::*;
|
|||
|
||||
pub use self::str::*;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
#[macro_use]
|
||||
pub mod error;
|
||||
|
||||
pub mod branch;
|
||||
pub mod combinator;
|
||||
mod internal;
|
||||
mod traits;
|
||||
#[macro_use]
|
||||
pub mod branch;
|
||||
pub mod multi;
|
||||
pub mod sequence;
|
||||
mod traits;
|
||||
|
||||
pub mod bits;
|
||||
pub mod bytes;
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
macro_rules! succ (
|
||||
(0, $submac:ident ! ($($rest:tt)*)) => ($submac!(1, $($rest)*));
|
||||
(1, $submac:ident ! ($($rest:tt)*)) => ($submac!(2, $($rest)*));
|
||||
(2, $submac:ident ! ($($rest:tt)*)) => ($submac!(3, $($rest)*));
|
||||
(3, $submac:ident ! ($($rest:tt)*)) => ($submac!(4, $($rest)*));
|
||||
(4, $submac:ident ! ($($rest:tt)*)) => ($submac!(5, $($rest)*));
|
||||
(5, $submac:ident ! ($($rest:tt)*)) => ($submac!(6, $($rest)*));
|
||||
(6, $submac:ident ! ($($rest:tt)*)) => ($submac!(7, $($rest)*));
|
||||
(7, $submac:ident ! ($($rest:tt)*)) => ($submac!(8, $($rest)*));
|
||||
(8, $submac:ident ! ($($rest:tt)*)) => ($submac!(9, $($rest)*));
|
||||
(9, $submac:ident ! ($($rest:tt)*)) => ($submac!(10, $($rest)*));
|
||||
(10, $submac:ident ! ($($rest:tt)*)) => ($submac!(11, $($rest)*));
|
||||
(11, $submac:ident ! ($($rest:tt)*)) => ($submac!(12, $($rest)*));
|
||||
(12, $submac:ident ! ($($rest:tt)*)) => ($submac!(13, $($rest)*));
|
||||
(13, $submac:ident ! ($($rest:tt)*)) => ($submac!(14, $($rest)*));
|
||||
(14, $submac:ident ! ($($rest:tt)*)) => ($submac!(15, $($rest)*));
|
||||
(15, $submac:ident ! ($($rest:tt)*)) => ($submac!(16, $($rest)*));
|
||||
(16, $submac:ident ! ($($rest:tt)*)) => ($submac!(17, $($rest)*));
|
||||
(17, $submac:ident ! ($($rest:tt)*)) => ($submac!(18, $($rest)*));
|
||||
(18, $submac:ident ! ($($rest:tt)*)) => ($submac!(19, $($rest)*));
|
||||
(19, $submac:ident ! ($($rest:tt)*)) => ($submac!(20, $($rest)*));
|
||||
(20, $submac:ident ! ($($rest:tt)*)) => ($submac!(21, $($rest)*));
|
||||
);
|
|
@ -11,15 +11,28 @@ use crate::lib::std::vec::Vec;
|
|||
use crate::traits::{InputLength, InputTake, ToUsize};
|
||||
use core::num::NonZeroUsize;
|
||||
|
||||
/// Repeats the embedded parser until it fails
|
||||
/// and returns the results in a `Vec`.
|
||||
/// Don't pre-allocate more than 64KiB when calling `Vec::with_capacity`.
|
||||
///
|
||||
/// Pre-allocating memory is a nice optimization but count fields can't
|
||||
/// always be trusted. We should clamp initial capacities to some reasonable
|
||||
/// amount. This reduces the risk of a bogus count value triggering a panic
|
||||
/// due to an OOM error.
|
||||
///
|
||||
/// This does not affect correctness. Nom will always read the full number
|
||||
/// of elements regardless of the capacity cap.
|
||||
#[cfg(feature = "alloc")]
|
||||
const MAX_INITIAL_CAPACITY_BYTES: usize = 65536;
|
||||
|
||||
/// Repeats the embedded parser, gathering the results in a `Vec`.
|
||||
///
|
||||
/// This stops on [`Err::Error`] and returns the results that were accumulated. To instead chain an error up, see
|
||||
/// [`cut`][crate::combinator::cut].
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `f` The parser to apply.
|
||||
///
|
||||
/// *Note*: if the parser passed to `many0` accepts empty inputs
|
||||
/// (like `alpha0` or `digit0`), `many0` will return an error,
|
||||
/// to prevent going into an infinite loop
|
||||
/// *Note*: if the parser passed in accepts empty inputs (like `alpha0` or `digit0`), `many0` will
|
||||
/// return an error, to prevent going into an infinite loop
|
||||
///
|
||||
/// ```rust
|
||||
/// # use nom::{Err, error::ErrorKind, Needed, IResult};
|
||||
|
@ -64,10 +77,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Runs the embedded parser until it fails and
|
||||
/// returns the results in a `Vec`. Fails if
|
||||
/// the embedded parser does not produce at least
|
||||
/// one result.
|
||||
/// Runs the embedded parser, gathering the results in a `Vec`.
|
||||
///
|
||||
/// This stops on [`Err::Error`] if there is at least one result, and returns the results that were accumulated. To instead chain an error up,
|
||||
/// see [`cut`][crate::combinator::cut].
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `f` The parser to apply.
|
||||
|
@ -126,9 +139,12 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Applies the parser `f` until the parser `g` produces
|
||||
/// a result. Returns a pair consisting of the results of
|
||||
/// `f` in a `Vec` and the result of `g`.
|
||||
/// Applies the parser `f` until the parser `g` produces a result.
|
||||
///
|
||||
/// Returns a tuple of the results of `f` in a `Vec` and the result of `g`.
|
||||
///
|
||||
/// `f` keeps going so long as `g` produces [`Err::Error`]. To instead chain an error up, see [`cut`][crate::combinator::cut].
|
||||
///
|
||||
/// ```rust
|
||||
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
|
||||
/// use nom::multi::many_till;
|
||||
|
@ -183,8 +199,11 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Alternates between two parsers to produce
|
||||
/// a list of elements.
|
||||
/// Alternates between two parsers to produce a list of elements.
|
||||
///
|
||||
/// This stops when either parser returns [`Err::Error`] and returns the results that were accumulated. To instead chain an error up, see
|
||||
/// [`cut`][crate::combinator::cut].
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `sep` Parses the separator between list elements.
|
||||
/// * `f` Parses the elements of the list.
|
||||
|
@ -253,9 +272,13 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Alternates between two parsers to produce
|
||||
/// a list of elements. Fails if the element
|
||||
/// parser does not produce at least one element.
|
||||
/// Alternates between two parsers to produce a list of elements until [`Err::Error`].
|
||||
///
|
||||
/// Fails if the element parser does not produce at least one element.$
|
||||
///
|
||||
/// This stops when either parser returns [`Err::Error`] and returns the results that were accumulated. To instead chain an error up, see
|
||||
/// [`cut`][crate::combinator::cut].
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `sep` Parses the separator between list elements.
|
||||
/// * `f` Parses the elements of the list.
|
||||
|
@ -323,13 +346,20 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Repeats the embedded parser `n` times or until it fails
|
||||
/// and returns the results in a `Vec`. Fails if the
|
||||
/// embedded parser does not succeed at least `m` times.
|
||||
/// Repeats the embedded parser `m..=n` times
|
||||
///
|
||||
/// This stops before `n` when the parser returns [`Err::Error`] and returns the results that were accumulated. To instead chain an error up, see
|
||||
/// [`cut`][crate::combinator::cut].
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `m` The minimum number of iterations.
|
||||
/// * `n` The maximum number of iterations.
|
||||
/// * `f` The parser to apply.
|
||||
///
|
||||
/// *Note*: If the parser passed to `many1` accepts empty inputs
|
||||
/// (like `alpha0` or `digit0`), `many1` will return an error,
|
||||
/// to prevent going into an infinite loop.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use nom::{Err, error::ErrorKind, Needed, IResult};
|
||||
/// use nom::multi::many_m_n;
|
||||
|
@ -362,7 +392,9 @@ where
|
|||
return Err(Err::Failure(E::from_error_kind(input, ErrorKind::ManyMN)));
|
||||
}
|
||||
|
||||
let mut res = crate::lib::std::vec::Vec::with_capacity(min);
|
||||
let max_initial_capacity =
|
||||
MAX_INITIAL_CAPACITY_BYTES / crate::lib::std::mem::size_of::<O>().max(1);
|
||||
let mut res = crate::lib::std::vec::Vec::with_capacity(min.min(max_initial_capacity));
|
||||
for count in 0..max {
|
||||
let len = input.input_len();
|
||||
match parse.parse(input.clone()) {
|
||||
|
@ -392,10 +424,17 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Repeats the embedded parser until it fails
|
||||
/// and returns the number of successful iterations.
|
||||
/// Repeats the embedded parser, counting the results
|
||||
///
|
||||
/// This stops on [`Err::Error`]. To instead chain an error up, see
|
||||
/// [`cut`][crate::combinator::cut].
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `f` The parser to apply.
|
||||
///
|
||||
/// *Note*: if the parser passed in accepts empty inputs (like `alpha0` or `digit0`), `many0` will
|
||||
/// return an error, to prevent going into an infinite loop
|
||||
///
|
||||
/// ```rust
|
||||
/// # use nom::{Err, error::ErrorKind, Needed, IResult};
|
||||
/// use nom::multi::many0_count;
|
||||
|
@ -442,12 +481,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Repeats the embedded parser until it fails
|
||||
/// and returns the number of successful iterations.
|
||||
/// Fails if the embedded parser does not succeed
|
||||
/// at least once.
|
||||
/// Runs the embedded parser, counting the results.
|
||||
///
|
||||
/// This stops on [`Err::Error`] if there is at least one result. To instead chain an error up,
|
||||
/// see [`cut`][crate::combinator::cut].
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `f` The parser to apply.
|
||||
///
|
||||
/// *Note*: If the parser passed to `many1` accepts empty inputs
|
||||
/// (like `alpha0` or `digit0`), `many1` will return an error,
|
||||
/// to prevent going into an infinite loop.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
|
||||
/// use nom::multi::many1_count;
|
||||
|
@ -499,8 +544,8 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Runs the embedded parser a specified number
|
||||
/// of times. Returns the results in a `Vec`.
|
||||
/// Runs the embedded parser `count` times, gathering the results in a `Vec`
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `f` The parser to apply.
|
||||
/// * `count` How often to apply the parser.
|
||||
|
@ -529,7 +574,9 @@ where
|
|||
{
|
||||
move |i: I| {
|
||||
let mut input = i.clone();
|
||||
let mut res = crate::lib::std::vec::Vec::with_capacity(count);
|
||||
let max_initial_capacity =
|
||||
MAX_INITIAL_CAPACITY_BYTES / crate::lib::std::mem::size_of::<O>().max(1);
|
||||
let mut res = crate::lib::std::vec::Vec::with_capacity(count.min(max_initial_capacity));
|
||||
|
||||
for _ in 0..count {
|
||||
let input_ = input.clone();
|
||||
|
@ -551,8 +598,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Runs the embedded parser repeatedly, filling the given slice with results. This parser fails if
|
||||
/// the input runs out before the given slice is full.
|
||||
/// Runs the embedded parser repeatedly, filling the given slice with results.
|
||||
///
|
||||
/// This parser fails if the input runs out before the given slice is full.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `f` The parser to apply.
|
||||
/// * `buf` The slice to fill
|
||||
|
@ -602,13 +651,20 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Applies a parser until it fails and accumulates
|
||||
/// the results using a given function and initial value.
|
||||
/// Repeats the embedded parser, calling `g` to gather the results.
|
||||
///
|
||||
/// This stops on [`Err::Error`]. To instead chain an error up, see
|
||||
/// [`cut`][crate::combinator::cut].
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `f` The parser to apply.
|
||||
/// * `init` A function returning the initial value.
|
||||
/// * `g` The function that combines a result of `f` with
|
||||
/// the current accumulator.
|
||||
///
|
||||
/// *Note*: if the parser passed in accepts empty inputs (like `alpha0` or `digit0`), `many0` will
|
||||
/// return an error, to prevent going into an infinite loop
|
||||
///
|
||||
/// ```rust
|
||||
/// # use nom::{Err, error::ErrorKind, Needed, IResult};
|
||||
/// use nom::multi::fold_many0;
|
||||
|
@ -670,15 +726,21 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Applies a parser until it fails and accumulates
|
||||
/// the results using a given function and initial value.
|
||||
/// Fails if the embedded parser does not succeed at least
|
||||
/// once.
|
||||
/// Repeats the embedded parser, calling `g` to gather the results.
|
||||
///
|
||||
/// This stops on [`Err::Error`] if there is at least one result. To instead chain an error up,
|
||||
/// see [`cut`][crate::combinator::cut].
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `f` The parser to apply.
|
||||
/// * `init` A function returning the initial value.
|
||||
/// * `g` The function that combines a result of `f` with
|
||||
/// the current accumulator.
|
||||
///
|
||||
/// *Note*: If the parser passed to `many1` accepts empty inputs
|
||||
/// (like `alpha0` or `digit0`), `many1` will return an error,
|
||||
/// to prevent going into an infinite loop.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
|
||||
/// use nom::multi::fold_many1;
|
||||
|
@ -748,10 +810,11 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Applies a parser `n` times or until it fails and accumulates
|
||||
/// the results using a given function and initial value.
|
||||
/// Fails if the embedded parser does not succeed at least `m`
|
||||
/// times.
|
||||
/// Repeats the embedded parser `m..=n` times, calling `g` to gather the results
|
||||
///
|
||||
/// This stops before `n` when the parser returns [`Err::Error`]. To instead chain an error up, see
|
||||
/// [`cut`][crate::combinator::cut].
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `m` The minimum number of iterations.
|
||||
/// * `n` The maximum number of iterations.
|
||||
|
@ -759,6 +822,11 @@ where
|
|||
/// * `init` A function returning the initial value.
|
||||
/// * `g` The function that combines a result of `f` with
|
||||
/// the current accumulator.
|
||||
///
|
||||
/// *Note*: If the parser passed to `many1` accepts empty inputs
|
||||
/// (like `alpha0` or `digit0`), `many1` will return an error,
|
||||
/// to prevent going into an infinite loop.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use nom::{Err, error::ErrorKind, Needed, IResult};
|
||||
/// use nom::multi::fold_many_m_n;
|
||||
|
|
|
@ -13,26 +13,6 @@ use crate::traits::{
|
|||
AsBytes, AsChar, Compare, InputIter, InputLength, InputTake, InputTakeAtPosition, Offset, Slice,
|
||||
};
|
||||
|
||||
#[doc(hidden)]
|
||||
macro_rules! map(
|
||||
// Internal parser, do not use directly
|
||||
(__impl $i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
|
||||
$crate::combinator::map(move |i| {$submac!(i, $($args)*)}, $g).parse($i)
|
||||
);
|
||||
($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
|
||||
map!(__impl $i, $submac!($($args)*), $g)
|
||||
);
|
||||
($i:expr, $f:expr, $g:expr) => (
|
||||
map!(__impl $i, call!($f), $g)
|
||||
);
|
||||
);
|
||||
|
||||
#[doc(hidden)]
|
||||
macro_rules! call (
|
||||
($i:expr, $fun:expr) => ( $fun( $i ) );
|
||||
($i:expr, $fun:expr, $($args:expr),* ) => ( $fun( $i, $($args),* ) );
|
||||
);
|
||||
|
||||
/// Recognizes an unsigned 1 byte integer.
|
||||
///
|
||||
/// *Complete version*: Returns an error if there is not enough input data.
|
||||
|
@ -248,7 +228,7 @@ pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, be_u8, |x| x as i8)
|
||||
be_u8.map(|x| x as i8).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a big endian signed 2 bytes integer.
|
||||
|
@ -271,7 +251,7 @@ pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, be_u16, |x| x as i16)
|
||||
be_u16.map(|x| x as i16).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a big endian signed 3 bytes integer.
|
||||
|
@ -295,16 +275,20 @@ where
|
|||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
// Same as the unsigned version but we need to sign-extend manually here
|
||||
map!(input, be_u24, |x| if x & 0x80_00_00 != 0 {
|
||||
be_u24
|
||||
.map(|x| {
|
||||
if x & 0x80_00_00 != 0 {
|
||||
(x | 0xff_00_00_00) as i32
|
||||
} else {
|
||||
x as i32
|
||||
}
|
||||
})
|
||||
.parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a big endian signed 4 bytes integer.
|
||||
///
|
||||
/// *Complete version*: Teturns an error if there is not enough input data.
|
||||
/// *Complete version*: Returns an error if there is not enough input data.
|
||||
/// ```rust
|
||||
/// # use nom::{Err, error::ErrorKind, Needed};
|
||||
/// # use nom::Needed::Size;
|
||||
|
@ -322,7 +306,7 @@ pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, be_u32, |x| x as i32)
|
||||
be_u32.map(|x| x as i32).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a big endian signed 8 bytes integer.
|
||||
|
@ -345,7 +329,7 @@ pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, be_u64, |x| x as i64)
|
||||
be_u64.map(|x| x as i64).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a big endian signed 16 bytes integer.
|
||||
|
@ -368,7 +352,7 @@ pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, be_u128, |x| x as i128)
|
||||
be_u128.map(|x| x as i128).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes an unsigned 1 byte integer.
|
||||
|
@ -586,7 +570,7 @@ pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, be_u8, |x| x as i8)
|
||||
be_u8.map(|x| x as i8).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a little endian signed 2 bytes integer.
|
||||
|
@ -609,7 +593,7 @@ pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, le_u16, |x| x as i16)
|
||||
le_u16.map(|x| x as i16).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a little endian signed 3 bytes integer.
|
||||
|
@ -633,11 +617,15 @@ where
|
|||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
// Same as the unsigned version but we need to sign-extend manually here
|
||||
map!(input, le_u24, |x| if x & 0x80_00_00 != 0 {
|
||||
le_u24
|
||||
.map(|x| {
|
||||
if x & 0x80_00_00 != 0 {
|
||||
(x | 0xff_00_00_00) as i32
|
||||
} else {
|
||||
x as i32
|
||||
}
|
||||
})
|
||||
.parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a little endian signed 4 bytes integer.
|
||||
|
@ -660,7 +648,7 @@ pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, le_u32, |x| x as i32)
|
||||
le_u32.map(|x| x as i32).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a little endian signed 8 bytes integer.
|
||||
|
@ -683,7 +671,7 @@ pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, le_u64, |x| x as i64)
|
||||
le_u64.map(|x| x as i64).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a little endian signed 16 bytes integer.
|
||||
|
@ -706,7 +694,7 @@ pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, le_u128, |x| x as i128)
|
||||
le_u128.map(|x| x as i128).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes an unsigned 1 byte integer
|
||||
|
@ -957,7 +945,7 @@ pub fn i8<I, E: ParseError<I>>(i: I) -> IResult<I, i8, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(i, u8, |x| x as i8)
|
||||
u8.map(|x| x as i8).parse(i)
|
||||
}
|
||||
|
||||
/// Recognizes a signed 2 byte integer
|
||||
|
@ -1595,7 +1583,7 @@ where
|
|||
*/
|
||||
let (i, s) = recognize_float_or_exceptions(input)?;
|
||||
match s.parse_to() {
|
||||
Some(f) => (Ok((i, f))),
|
||||
Some(f) => Ok((i, f)),
|
||||
None => Err(crate::Err::Error(E::from_error_kind(
|
||||
i,
|
||||
crate::error::ErrorKind::Float,
|
||||
|
@ -1648,7 +1636,7 @@ where
|
|||
*/
|
||||
let (i, s) = recognize_float_or_exceptions(input)?;
|
||||
match s.parse_to() {
|
||||
Some(f) => (Ok((i, f))),
|
||||
Some(f) => Ok((i, f)),
|
||||
None => Err(crate::Err::Error(E::from_error_kind(
|
||||
i,
|
||||
crate::error::ErrorKind::Float,
|
||||
|
@ -2111,7 +2099,7 @@ mod tests {
|
|||
|
||||
#[cfg(feature = "std")]
|
||||
fn parse_f64(i: &str) -> IResult<&str, f64, ()> {
|
||||
match recognize_float(i) {
|
||||
match recognize_float_or_exceptions(i) {
|
||||
Err(e) => Err(e),
|
||||
Ok((i, s)) => {
|
||||
if s.is_empty() {
|
||||
|
|
|
@ -12,26 +12,6 @@ use crate::traits::{
|
|||
AsBytes, AsChar, Compare, InputIter, InputLength, InputTake, InputTakeAtPosition, Offset, Slice,
|
||||
};
|
||||
|
||||
#[doc(hidden)]
|
||||
macro_rules! map(
|
||||
// Internal parser, do not use directly
|
||||
(__impl $i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
|
||||
$crate::combinator::map(move |i| {$submac!(i, $($args)*)}, $g).parse($i)
|
||||
);
|
||||
($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
|
||||
map!(__impl $i, $submac!($($args)*), $g)
|
||||
);
|
||||
($i:expr, $f:expr, $g:expr) => (
|
||||
map!(__impl $i, call!($f), $g)
|
||||
);
|
||||
);
|
||||
|
||||
#[doc(hidden)]
|
||||
macro_rules! call (
|
||||
($i:expr, $fun:expr) => ( $fun( $i ) );
|
||||
($i:expr, $fun:expr, $($args:expr),* ) => ( $fun( $i, $($args),* ) );
|
||||
);
|
||||
|
||||
/// Recognizes an unsigned 1 byte integer.
|
||||
///
|
||||
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
|
||||
|
@ -242,7 +222,7 @@ pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, be_u8, |x| x as i8)
|
||||
be_u8.map(|x| x as i8).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a big endian signed 2 bytes integer.
|
||||
|
@ -262,7 +242,7 @@ pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, be_u16, |x| x as i16)
|
||||
be_u16.map(|x| x as i16).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a big endian signed 3 bytes integer.
|
||||
|
@ -283,11 +263,15 @@ where
|
|||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
// Same as the unsigned version but we need to sign-extend manually here
|
||||
map!(input, be_u24, |x| if x & 0x80_00_00 != 0 {
|
||||
be_u24
|
||||
.map(|x| {
|
||||
if x & 0x80_00_00 != 0 {
|
||||
(x | 0xff_00_00_00) as i32
|
||||
} else {
|
||||
x as i32
|
||||
}
|
||||
})
|
||||
.parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a big endian signed 4 bytes integer.
|
||||
|
@ -307,7 +291,7 @@ pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, be_u32, |x| x as i32)
|
||||
be_u32.map(|x| x as i32).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a big endian signed 8 bytes integer.
|
||||
|
@ -328,7 +312,7 @@ pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, be_u64, |x| x as i64)
|
||||
be_u64.map(|x| x as i64).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a big endian signed 16 bytes integer.
|
||||
|
@ -348,7 +332,7 @@ pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, be_u128, |x| x as i128)
|
||||
be_u128.map(|x| x as i128).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes an unsigned 1 byte integer.
|
||||
|
@ -560,7 +544,7 @@ pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, le_u8, |x| x as i8)
|
||||
le_u8.map(|x| x as i8).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a little endian signed 2 bytes integer.
|
||||
|
@ -583,7 +567,7 @@ pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, le_u16, |x| x as i16)
|
||||
le_u16.map(|x| x as i16).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a little endian signed 3 bytes integer.
|
||||
|
@ -607,11 +591,15 @@ where
|
|||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
// Same as the unsigned version but we need to sign-extend manually here
|
||||
map!(input, le_u24, |x| if x & 0x80_00_00 != 0 {
|
||||
le_u24
|
||||
.map(|x| {
|
||||
if x & 0x80_00_00 != 0 {
|
||||
(x | 0xff_00_00_00) as i32
|
||||
} else {
|
||||
x as i32
|
||||
}
|
||||
})
|
||||
.parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a little endian signed 4 bytes integer.
|
||||
|
@ -634,7 +622,7 @@ pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, le_u32, |x| x as i32)
|
||||
le_u32.map(|x| x as i32).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a little endian signed 8 bytes integer.
|
||||
|
@ -657,7 +645,7 @@ pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, le_u64, |x| x as i64)
|
||||
le_u64.map(|x| x as i64).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes a little endian signed 16 bytes integer.
|
||||
|
@ -680,7 +668,7 @@ pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(input, le_u128, |x| x as i128)
|
||||
le_u128.map(|x| x as i128).parse(input)
|
||||
}
|
||||
|
||||
/// Recognizes an unsigned 1 byte integer
|
||||
|
@ -931,7 +919,7 @@ pub fn i8<I, E: ParseError<I>>(i: I) -> IResult<I, i8, E>
|
|||
where
|
||||
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
|
||||
{
|
||||
map!(i, u8, |x| x as i8)
|
||||
u8.map(|x| x as i8).parse(i)
|
||||
}
|
||||
|
||||
/// Recognizes a signed 2 byte integer
|
||||
|
@ -1567,7 +1555,7 @@ where
|
|||
*/
|
||||
let (i, s) = recognize_float_or_exceptions(input)?;
|
||||
match s.parse_to() {
|
||||
Some(f) => (Ok((i, f))),
|
||||
Some(f) => Ok((i, f)),
|
||||
None => Err(crate::Err::Error(E::from_error_kind(
|
||||
i,
|
||||
crate::error::ErrorKind::Float,
|
||||
|
@ -1621,7 +1609,7 @@ where
|
|||
*/
|
||||
let (i, s) = recognize_float_or_exceptions(input)?;
|
||||
match s.parse_to() {
|
||||
Some(f) => (Ok((i, f))),
|
||||
Some(f) => Ok((i, f)),
|
||||
None => Err(crate::Err::Error(E::from_error_kind(
|
||||
i,
|
||||
crate::error::ErrorKind::Float,
|
||||
|
@ -2191,7 +2179,7 @@ mod tests {
|
|||
#[cfg(feature = "std")]
|
||||
fn parse_f64(i: &str) -> IResult<&str, f64, ()> {
|
||||
use crate::traits::ParseTo;
|
||||
match recognize_float(i) {
|
||||
match recognize_float_or_exceptions(i) {
|
||||
Err(e) => Err(e),
|
||||
Ok((i, s)) => {
|
||||
if s.is_empty() {
|
||||
|
|
|
@ -252,6 +252,15 @@ macro_rules! tuple_trait_inner(
|
|||
tuple_trait!(FnA A, FnB B, FnC C, FnD D, FnE E, FnF F, FnG G, FnH H, FnI I, FnJ J, FnK K, FnL L,
|
||||
FnM M, FnN N, FnO O, FnP P, FnQ Q, FnR R, FnS S, FnT T, FnU U);
|
||||
|
||||
// Special case: implement `Tuple` for `()`, the unit type.
|
||||
// This can come up in macros which accept a variable number of arguments.
|
||||
// Literally, `()` is an empty tuple, so it should simply parse nothing.
|
||||
impl<I, E: ParseError<I>> Tuple<I, (), E> for () {
|
||||
fn parse(&mut self, input: I) -> IResult<I, (), E> {
|
||||
Ok((input, ()))
|
||||
}
|
||||
}
|
||||
|
||||
///Applies a tuple of parsers one by one and returns their results as a tuple.
|
||||
///There is a maximum of 21 parsers
|
||||
/// ```rust
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use super::*;
|
||||
use crate::bytes::streaming::{tag, take};
|
||||
use crate::error::ErrorKind;
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::internal::{Err, IResult, Needed};
|
||||
use crate::number::streaming::be_u16;
|
||||
|
||||
|
@ -272,3 +272,19 @@ fn tuple_test() {
|
|||
Err(Err::Error(error_position!(&b"jk"[..], ErrorKind::Tag)))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unit_type() {
|
||||
assert_eq!(
|
||||
tuple::<&'static str, (), Error<&'static str>, ()>(())("abxsbsh"),
|
||||
Ok(("abxsbsh", ()))
|
||||
);
|
||||
assert_eq!(
|
||||
tuple::<&'static str, (), Error<&'static str>, ()>(())("sdfjakdsas"),
|
||||
Ok(("sdfjakdsas", ()))
|
||||
);
|
||||
assert_eq!(
|
||||
tuple::<&'static str, (), Error<&'static str>, ()>(())(""),
|
||||
Ok(("", ()))
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1330,6 +1330,10 @@ impl<I> ErrorConvert<error::VerboseError<(I, usize)>> for error::VerboseError<I>
|
|||
}
|
||||
}
|
||||
|
||||
impl ErrorConvert<()> for () {
|
||||
fn convert(self) {}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "std")))]
|
||||
/// Helper trait to show a byte slice as a hex dump
|
||||
|
|
|
@ -214,3 +214,29 @@ fn issue_1282_findtoken_char() {
|
|||
let parser = one_of::<_, _, Error<_>>(&['a', 'b', 'c'][..]);
|
||||
assert_eq!(parser("aaa"), Ok(("aa", 'a')));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_1459_clamp_capacity() {
|
||||
use nom::character::complete::char;
|
||||
|
||||
// shouldn't panic
|
||||
use nom::multi::many_m_n;
|
||||
let mut parser = many_m_n::<_, _, (), _>(usize::MAX, usize::MAX, char('a'));
|
||||
assert_eq!(parser("a"), Err(nom::Err::Error(())));
|
||||
|
||||
// shouldn't panic
|
||||
use nom::multi::count;
|
||||
let mut parser = count::<_, _, (), _>(char('a'), usize::MAX);
|
||||
assert_eq!(parser("a"), Err(nom::Err::Error(())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_1617_count_parser_returning_zero_size() {
|
||||
use nom::{bytes::complete::tag, combinator::map, error::Error, multi::count};
|
||||
|
||||
// previously, `count()` panicked if the parser had type `O = ()`
|
||||
let parser = map(tag::<_, _, Error<&str>>("abc"), |_| ());
|
||||
// shouldn't panic
|
||||
let result = count(parser, 3)("abcabcabcdef").expect("parsing should succeed");
|
||||
assert_eq!(result, ("def", vec![(), (), ()]));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче