I'm in way over my head with spirit::qi and need some help. I'm trying to parse a phrase that is of the form:
( wheels=4 & chassis=metal & engine=( cylinders=8 & volume=6209 ) )
... into a nested structure:
class dict : public std::map<std::string, boost::variant<dict, std::string>>
... where car_dict["wheels"] returns "4", and car_dict["engine"] returns another dict, where engine_dict["cylinders"] returns "8".
Here is my grammar, I'm hoping someone that has plenty of experience in this stuff can just point out where I'm going wrong.
struct qi_car_grammar : qi::grammar<std::string::const_iterator, dict()>
{
qi::rule<std::string::const_iterator, dict()> car_dict;
qi::rule<std::string::const_iterator, std::string()> car_key;
qi::rule<std::string::const_iterator, boost::variant<dict, std::string>()> car_variant_value;
qi_car_grammar()
: qi_car_grammar::base_type(car_dict)
{
// RULES
car_key %= *(qi::lit(' ')) >> *(~qi::lit('='));
car_variant_value %= car_dict | *(~qi::char_("&)"));
car_dict = qi::lit('(')
>> car_key >> qi::lit('=') >> car_variant_value
>> *(qi::lit('&') >> car_key >> qi::lit('=') >> car_variant_value)
>> qi::lit(')');
}
}
Any help appreciated. Before anyone suggests it, no, I don't have much control over the structure that I am parsing into.