You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that this is a heavily simplified example (reference code). This parser matches multiple instances of tag1, followed by multiple instances of tag2. That is not the expected behavior. Instances of tag1 and tag2 can be intermixed with each other (eg tag1 tag2 tag2 tag1).
To fix this, it looks like we would have to use some combination of alt and many0, something like the following:
many0(alt((tag("tag1"), tag("tag2"))))
But I can't figure out how. I was also wondering if there is an easy way of doing this, because this looks like a fairly common use case (intermixed permutations of a bunch of subparsers, result being a bunch of lists). Thanks!
The text was updated successfully, but these errors were encountered:
The permutation only works by applying one of the parsers that you give fully and then it doesn't try that one again. So you are correct, the many0 inside the permutation doesn't work like you expected. But this is by design.
You basically want a permutation, but where parsers can be applied multiple times? I don't think that exists. The second parser you wrote there sounds like a good alternative, but mostly when you have an enum to capture all of those in. Because all the alternatives in the many0 block should have the same resulting type.
Do you have a bit more detailed information what you're trying to do? This is a bit too high-level to give a good answer I think.
Prerequisites
Here are a few things you should provide to help me understand the issue:
1.83.0
7.1
["alloc"]
Test case
Hi there! We are using a parsing library that has a permutation that looks like this:
Note that this is a heavily simplified example (reference code). This parser matches multiple instances of tag1, followed by multiple instances of tag2. That is not the expected behavior. Instances of tag1 and tag2 can be intermixed with each other (eg
tag1 tag2 tag2 tag1
).To fix this, it looks like we would have to use some combination of
alt
andmany0
, something like the following:But I can't figure out how. I was also wondering if there is an easy way of doing this, because this looks like a fairly common use case (intermixed permutations of a bunch of subparsers, result being a bunch of lists). Thanks!
The text was updated successfully, but these errors were encountered: