[Question] How do I combine these parsers?
See original GitHub issueLet’s assume I have a Group 1 of parser a,b,c and d and Group 2 of parser w,x,y and z. I would like to combine these parses so that the resulting parser would parse any combination of parsers from group 1 and exactly 1 parser from group 2 in any order.
Is this possible?
It is quite possible that I’m attacking the problem from a wrong angle (XY-problem), here is what I’m really trying to solve.
I’d like to parse a command line switch that starts with -
or /
and then a number of options follows for example -abwdc
among these options there could be as many as desired binary ones (that is a,b,c or d, that do not require a parameter to follow) but only one that requires a parameter (w,x,u or z). The options can be specified in any order.
Issue Analytics
- State:
- Created 6 years ago
- Comments:20 (18 by maintainers)
Top Results From Across the Web
parsing - How to combine many parsers?
For simplicity, I use constant "else " and "elif " strings in the results, but these can be built from the partial results...
Read more >Introduction to Parsers
We can combine these parsers together with some higher-order functions called combinators. Let's create a combinator called sequence that ...
Read more >parsing - When to use a Parser Combinator? ...
to combine them : e.g. many1 attempts to match another parser as many times as possible (but at least once, or it itself...
Read more >Unlocking the Power of Parser Combinators: A Beginner's ...
First, we will create a parser that only recognizes a single character, but by combining multiples of those, we'll be able to recognize...
Read more >A Guide To Parsing: Algorithms And Terminology
An in-depth coverage of parsing terminology an issues, together with an explanation for each one of the major algorithms and when to use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@AndrewSav I’m pretty thankful for your stream of conciousness. I was looking to see if anyone had implemented a command-line parser library using SuperPower, as the whole tokenization feature seems like it would allow for people to extend it with varying grammars. And the parser combinator feature would allow for nesting grammars.
@jzabroski
An example would be helpful, otherwise it’s a bit too abstract. I’m sure there are examples, I just did not come across any in anything I’ve done so far with Superpower.
Superpower is never ambiguous. It always prefers the first valid match.
Which parser combinators did you mention? I must have missed that.