-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
Parsing a(ba)* in 1.0.0-alpha.4 #478
Comments
More generally, I think that the general approach to parser iterators in 1.0.0-alpha.4 can be improved:
Here's how I would love to do things: use chumsky::iter::once;
once(a).chain(once(b).chain(once(a)).repeated().flatten()).collect() Footnotes
|
Yet another thought: That would help parsing a.or_not().into_iter().chain(b.repeated()) |
Yet another idea: It might be a nice idea to be able to convert |
Hello!
In
I definitely agree! There's an open issue for this that you might find interesting. It would allow you to do something like Obviously, this represent a pretty substantial reworking of the crate internals, and this is something I've not yet had time to make progress on, sadly. If you have other ideas that you don't think are mentioned on the above issue, I'd definitely love to see suggestions added there! |
Going to close this since #425 pretty much covers the requested features in this issue. |
I am converting a parser from chumsky 0.9 to 1.0.0-alpha.4.
During this, I noticed a pattern that I found quite nontrivial to translate.
In particular, a parser for
a(ba)*
, wherea
andb
are parsers that have the same output typeT
, and we want to obtain all parsed elements asVec<T>
. (It's likeseparated_by
, but keeping the separators.)In chumsky 0.9, this looked something like:
In the new chumsky, however, there is no more
chain
.After some struggling, I came up with the following equivalent in chumsky 1.0.0-alpha.4:
This is significantly longer, and IMHO, much harder to understand. (My actual example even involves nested
foldl
Is there some more canonical way to do this?
The text was updated successfully, but these errors were encountered: