I have an input encoded with ABNF grammar rules (it is MEGACO protocol):
!/3 [15.232.33.21]:2134
T=173619123
{
C=230234621
{
PR=9,
MF=ip/187/6/23045241
{
...
},
MF=ip/187/6/23045242
{
I want to parse it into a complex struct with boost::spirit, pseudo-code:
megaco
{
param1
param2
{
param1
param2
list of param3
param3-1
{
param4
...
}
param3-2
{
...
}
}
}
It should be noted that the grammar is complex and contains a lot of alternatives, levels and sequences. I am not sure how to create a boost::spirit parser to decode such a message level by level saving necessary values in the process.
Also I am not sure that boost::spirit is the right tool for it.
So how should I do it?
UPDATE: I want to thanks sehe for the great example, still the main task is to populate some structure with the values from the message. The only possible way I see now is to use BOOST_FUSION_ADAPT_STRUCT with a lot of structs using boost::variant for alternative and std::vector for lists of items. Am I right?
Ironically, heading over to Appendix B.2 of RFC 3525, and implementing the bulk of it superficially¹ it turns out your sample snippet is invalid.
It was missing
ammParameter, that's not optional as soon as you have the opening{:So, fixing the snippet, here's something to get you started. It's only 850 lines of code because the spec is lengthy:
Live On Coliru
Prints
¹ i.e. mostly dumb transformation of the productions, specifically barely no attribute handling and very heavy (e.g. no
symbols<>for the modemtypes etc.)