How to use spirit's qi attributes properly

"Roeber, Steffen" <[email protected]> Tue, 29 May 2018 07:44:50 +0000
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <VI1PR0201MB2047090401FED59B9E93C1FA936D0@VI1PR0201MB2047.eurprd02.prod.outlook.com>
Hi,

I want to parse something like "a=1;b=2;{c=3;d=4;}e=5;f=6;". My problem is how to handle the block within the '{}' chars. The values within the block shall be parsed (but not propagated to attribute of r1) if ignoreBlock is true.

using namespace boost::spirit;

using namespace std;

bool ignoreBlock = true;

qi::rule<std::string::iterator, vector<pair<string, int>>()> r1;

qi::rule<std::string::iterator, pair<string, int>()> r2;

qi::rule<std::string::iterator, vector<pair<string, int>>()> r3;

r1 = *(r2 | (qi::eps(phoenix::ref(ignoreBlock)==true) >> qi::omit[r3]) | r3);

r2 = qi::as<string>()[+qi::alnum] >> '=' >> qi::int_ >> ';';

r3 = '{' >> *r2 >> '}';

string s = { "a=1;b=2;{c=3;d=4;}e=5;f=6;"};

vector<pair<string, int>> v;

phrase_parse(s.begin(), s.end(), r1,  boost::spirit::ascii::space, v);

This code causes some error like: 'static_cast': cannot convert from const std::vector,std::allocator<_Ty>>' to 'std::pair'

How do I handle such conditional parts correctly?
Best regards
Steffen

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general