-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CompleteByteSlice/CompleteStr are invasive and make parsers not reusable #795
Comments
Even if the type is the right way to do it, I was left wondering if it could be made ergonomic. Having to start specifying the input type for all the |
@djc Personally I just ended up creating own macro which, in turns, calls |
@RReverser What do you do about combinators like |
I noticed this issue while researching #809. @RalfJung you could use my |
here's a gist that shows what I meant in my previous comment. It's based on your doubles_and_int parser example. |
@ian-p-cooke So I couldn't use I'm also a little surprised about these |
@RalfJung yes, that was my idea... I think ideally the trait that abstracts over all the input types would be defined in I agree, the Trait bounds are weird. I didn't see another way to satisfy the |
This issue was driving me so mad that I switched to combine even though it’s a bit slower for me. I will be very glad if nom’s mainteners find some way to make |
The It should also be possible to implement a generic parser over Though, it seems that you can write one using where clauses like: |
As a workaround to rust-bakery/nom#544, migrate to nom 4 to ensure that the verbose-errors feature becomes additive and therefore portus compiles when used as a dependency. There were two classes of changes to the parser structure: 1. Error handling, as predicted and outlined here: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#replacing-parser-result-matchers 2. Migration to "CompleteByteSlice". This was predicted in the migration notes: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#dealing-with-incomplete-usage but caused underlying errors as reported here: rust-bakery/nom#790 (comment) To address this, shadow nom's `named!` macro with our own, `named_complete!`, which replaces the types appropriately. This is the solution proposed here: rust-bakery/nom#795 (comment)
As a workaround to rust-bakery/nom#544, migrate to nom 4 to ensure that the verbose-errors feature becomes additive and therefore portus compiles when used as a dependency. There were two classes of changes to the parser structure: 1. Error handling, as predicted and outlined here: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#replacing-parser-result-matchers 2. Migration to "CompleteByteSlice". This was predicted in the migration notes: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#dealing-with-incomplete-usage but caused underlying errors as reported here: rust-bakery/nom#790 (comment) To address this, shadow nom's `named!` macro with our own, `named_complete!`, which replaces the types appropriately. This is the solution proposed here: rust-bakery/nom#795 (comment)
As a workaround to rust-bakery/nom#544, migrate to nom 4 to ensure that the verbose-errors feature becomes additive and therefore portus compiles when used as a dependency. There were two classes of changes to the parser structure: 1. Error handling, as predicted and outlined here: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#replacing-parser-result-matchers 2. Migration to "CompleteByteSlice". This was predicted in the migration notes: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#dealing-with-incomplete-usage but caused underlying errors as reported here: rust-bakery/nom#790 (comment) To address this, shadow nom's `named!` macro with our own, `named_complete!`, which replaces the types appropriately. This is the solution proposed here: rust-bakery/nom#795 (comment)
Maybe does it help to fix this problem? https://github.com/NamsooCho/nom3_test.git nom3 is working well with many_m_n!(). https://github.com/NamsooCho/nom4_test.git same code fails with nom4. Because I used trait, It is not easy to change to CompleteBytesSlice. |
|
nom 5's release is imminent, closing this now |
Prerequisites
Here are a few things you should provide to help me understand the issue:
Test case
Say you have a parser like this
And (for example because of #790) you want to change that parser to use
CompleteByteSlice
. It turns out that is quite hard, because (a) the code at the end ofdo_parse
also needs changing to (un)wrap theCompleteByteSlice
everywhere, and (b) much worse,double
works for&[u8]
only. Here's the solution I came up with eventually:This is clearly bad. It would help if there was a variant of
double
that works onCompleteByteSlice
shipped with nom, but the problem actually goes deeper: I may have both streaming and non-streaming parsing in my project, and I may want to re-use some of the parsers. E.g., imaginedoubles_and_int
was used both on a stream, and in another parser combinator that involvesmany0!
. Right now, the only way I found to make that work is to literally duplicatedoubles_and_int
, have one version that works onCompleteByteSlice
and one that works on&[u8]
. I tried wrapping the&[u8]
one similar to how I wrappeddouble
above, but that doesn't actually work: For combinators liketake_until_and_consume!
(and, I presume,tag!
though I did not test that), they have to be used directly on aCompleteByteSlice
or they will not behave correctly.I get the impression that using the type to encode the EOF behavior was the wrong choice (though there may be a trick I am missing here). Whether more data can come later is a property of the value (the byte stream) I am parsing; the parsers themselves should mostly be generic and usable on both prefixes and entire inputs.
The text was updated successfully, but these errors were encountered: