I'm using spirit parser for a quite long time but now I have an issue I don't really understand. I want to parse something like a,b->c,d or a,b->d into a struct. The following code does this right if the input is a,b->c,d (the left part of the rule). But if input is a,b->d (the alternativ part), then the produces aa,bb,,d. So it seems that the alternative parser does not clear the already parsed parts.
struct Test
{
std::string a;
std::string b;
std::string c;
std::string d;
};
BOOST_FUSION_ADAPT_STRUCT(Test,
(std::string, a)
(std::string, b)
(std::string, c)
(std::string, d))
using namespace boost::spirit::qi;
using std::string;
using std::pair;
rule<const char *, Test()> r = (+alnum >> ',' >> +alnum >> "->" >> +alnum >> ',' >> +alnum) | (+alnum >> ',' >> +alnum >> "->" >> attr(string()) >> +alnum);
Test result;
//const char* s = "a,b->c,d"; //produces a Result with a,b,c,d
const char* s = "a,b->d"; // procudes a Result with aa,bb,,d
parse(s, s + strlen(s), r, result);