i'm trying parse object order of attributes should not matter.
for example, parsing employee
employee { surname = "doe", firstname = "john", age = 30 }
should same
employee { age = 30, firstname = "john", surname = "doe"}
so ideally rule should (don't mind lack of formal definition)
unordered_rule %= lit("employee") >> "{" >> kwd("surname")["=" > quoted_string] / kwd("age")["=" > int_] / kwd("firstname")["=" > quoted_string] / kwd("age")["=" > int] >> "}";
but firstly, how incorporate separating commas parsing rule? , c++ struct struct employee { std::string firstname; ... int age; }
, order of attributes matter or how boost know keyword corresponds attribute after struct has been converted fusion vector?
this doesn't add me after reading documentation on keyword list operators.
fusion sequences ordered only. order in attributes synthesized must match order in fields have been adapted fusion sequence.
i know no elegant way incorporate delimiters (i think should extend keyword list parser directive that... feel free :)).
you use mix of skipping e.g. (qi::space | ',')
, qi::lexeme[]
around relevant items (see boost spirit skipper issues).
or can use lookahead-asserted repeating expression like
unordered_rule %= lit("employee") >> "{" >> (kwd("surname") >> (&lit('}') | ',')) [ "=" > quoted_string ] / kwd("age") >> (&lit('}') | ',')) [ "=" > int_ ] / kwd("firstname") >> (&lit('}') | ',')) [ "=" > quoted_string ] / kwd("age") >> (&lit('}') | ',')) [ "=" > int ] >> "}";
(not tested now).