-
Notifications
You must be signed in to change notification settings - Fork 32
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
Allow chaining parsers similar to p + q + r
but without getting nested tuple result
#25
Comments
I think it's OK to define and use |
While this approach looks good. |
From my perspective, the reason I like using pom over the alternatives is the simplicity. The operator style for the combinators ( That said, I do agree the code in your second post is nice. But that example is from combine, and it's not clear to me how an API like that could be developed within pom. |
Yes, it would be fine to rename |
Hi guys, not sure whether this is helpful but I solved this problem in my code using a new 'vector' combinator and an enum. I copied and adapted your code for the 'list' combinator to use an ordered Vec of parsers. I have this in parsers.rs:
Then a minimal working example:
You can see the limitation is that all the members of the vector have to return the same type, but I think it's quite neat when you combine the vector combinator with an enum :) |
Following up on the discussion in #24, I created one possible implementation which allows chaining parsers without getting a nested tuple result. You can see the result of this at the link below. Note that in this example, I could have removed the call to
map
entirely, but I wanted to leave it to demonstrate that the(hours, minutes, seconds)
tuple is not longer nested.master...JoshMcguigan:experimental-combinator
Unfortunately, at the moment I'm not sure how this could be extended to tuples of any size without creating
all4
,all5
..allN
for some reasonable value of N. Another downside of this approach is when the user adds a parser to the chain they'd have to switch which version of theall
function they are using, fromallN
toallN+1
.The upside to this is the result is a (not nested) tuple of the results of each of the parsers, which means this could nicely replace the use of the
+
,-
, and*
combinators, allowing users to write these types of combinations in what I'd consider to be more idiomatic Rust.Thanks again for your work on this crate, and feel free to let me know if this isn't something you are interested in.
The text was updated successfully, but these errors were encountered: