I'm trying to parse this simply and consise xml-minded structure with Boost::Spirit,
One{
Two{
Three{
}
}
}
And the code is organized as follows:
Struct definition to keep the spirit-stuff:
struct config;
typedef boost::variant< boost::recursive_wrapper<config> , std::string > config_node;
struct config
{
std::string name;
std::vector<config_node> children;
};
BOOST_FUSION_ADAPT_STRUCT(
config,
(std::string, name)
(std::vector<config_node>, children)
)
( shameless stealed from the xml intro )
Declaration of the rules ( on the parser class )
qi::rule<Iterator, config(), qi::locals<std::string>, ascii::space_type> cfg;
qi::rule<Iterator, config_node(), ascii::space_type> node;
qi::rule<Iterator, std::string(), ascii::space_type> start_tag;
qi::rule<Iterator, void(std::string), ascii::space_type> end_tag;
Definition of the rules, in the parser 'parse' method.
node = cfg;
start_tag = +(char_ -'{') >> '{';
end_tag = char_('}');
cfg %= start_tag[_a = _1]
>> *node
>> end_tag(_a);
_a and _1 are boost::phoenix variables.
This rules works for the small snipped pasted above, but if I change it to:
One{
Two{
}
Three{
}
}
( two groups in the same scope, instead of group inside of other group ) the parser fails. and I have no idea why.