This is basically a follow up of a question i asked earlier and @sehe so graciously answered!
Question: How do i parse multiple command parsers using boost spirit x3 and here is the code given by @sehe - https://coliru.stacked-crooked.com/a/5879831b11c51f84
The follow up question is how to parse the command arguments in any order:
i.e. parse the following successfully
cmd1 param1=<value> param2=value OR
cmd1 param2=<value> param1=value
and so on
I feel I have to mention we're not ChatGPT. You're in luck though, I like doing X3 finger exercises.
First, let's observe that Spirit Qi has a parser operator that comes close out of the box: Permutation Parser
Live On Coliru
Printing
You might consider staying with Qi for this.
Other Approaches
To get similar things done in X3 you some heroics will be required. Let me try by
cmd1 param1 = 3 param1 = 4
is fine)Here are the quick-and-dirty heroics:
I would probably clean it up to use static type info instead of requiring default-constructability, but in the interest of speed let's keep it as that. Now, use it:
Or indeed, with some more factory help:
Integrating in the example test cases:
Live On Coliru
Printing
Summarizing
I would probably make a general grammar and AST like
And create a validator function that validates the correctness of the commands after parsing. This way you get a very simple grammar that's easy to maintain, and way more flexibility regarding validation logic.