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
separated_list1 by multipspace0 sep failed #1691
Comments
While its not in the docs, in the code is this comment
Meaning, the separator parser. I assume this is protecting against writing code where both the separator and the core type are allowed to be empty, you'd get an infinite loop, so nom seems to say the core type may be empty but the separator must not be. |
Maybe related with #1573 |
The Perhaps the required
|
I ran into the same thing. Is there a more accepted pattern currently for a sequence of items that are optionally separated by whitespace? I've switched something like a |
If the separator is optional then what is to separate two consecutive elements when the separator is absent? without testing, this seems to be what you might want...
Rust saves us from ourselves ;) |
The return type on that isn't great, though. You'd have to |
that check for non consuming input in repeating parser dates from the very beginning of nom. People kept running into issues with parsers going into infinite loop, in particular due to optional whitespace. Even now in some user tests without the check people trip on it 😅 |
Sure, that makes sense, but I think it would be more robustly handled by returning an error in the case that both |
An optional Another situation is when the elements themselves are bracketed and the separator is purely cosmetic such as a sequence of quoted bracketed strings. However, this later case isn't a separated list but a sequence of elements with optional suffix (or prefix). I wonder if we cand define traits and auto implement them against parser results so as to use bounds to better document this functionality. ...pseudo
|
You present this as fact when it's really just your opinion. The difference between |
That depends on what's being parsed. In my case, I have a list of
That's not a problem, because if it's not optional, it's not optional. If somebody uses
In no situation should it be unclear whether the separator is optional or not, because you can always use a mandatory combinator if you want it to be mandatory. This is one of the major strengths of combinators, that you can build exactly the behavior you want from the building blocks. The suggestion is not making the separator optional, but allowing it to be a potentially non-consuming parser. |
Actually, the reason I am on this thread is because I had a similar presumption about this functionality for the optionality of Incidentally, my apologizes if I sound emphatic or definitive. I am an infinite novice in this and many things. :)
|
I have moved the loop check in
This will offer enough protection against infinite loops |
We should probably remove the comment that
|
Hello, and thank you for submitting an issue to nom!
First, please note that, for family reasons, I have limited time to work on
nom, so following the advice here will make sure I will quickly understand
your problem and answer as soon as possible.
Second, if I don't get to work on your issue quickly, that does not mean I
don't consider it important or useful. Major version releases happen once
a year, and a lot of fixes are done for the occasion, once I have had time
to think of the right solution. So I will get back to you :)
Prerequisites
Here are a few things you should provide to help me understand the issue:
Test case
Please provide a short, complete (with crate import, etc) test case for
the issue, showing clearly the expected and obtained results.
Example test case:
The text was updated successfully, but these errors were encountered: