Skip to content

How to create a all_of parser? #217

Answered by zesterer
soywod asked this question in Q&A
Discussion options

You must be logged in to vote

This is, unfortunately, not context-sensitive and isn't something that chumsky currently supports as a built-in thing (and I'm unconvinced I could come up with a sufficiently general API that covers most cases of this that I've seen). However, you can do it using try_map without too much difficulty in a way that gives you quite a lot of control over the error message:

// 'Remember' what kind of part this is by appending it to the output
let part_prop = |kind| part_prop(kind).map(|o| (o, kind));

choice((
    part_prop("type"),
    part_prop("filename"),
))
    .repeated()
    .try_map(|xs, span| {
        // Search through the outputs for each kind of part, ensuring we have at least one

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@soywod
Comment options

Answer selected by soywod
# for free to join this conversation on GitHub. Already have an account? # to comment
Category
Q&A
Labels
None yet
2 participants