We can't see the grammar because you didn't post it.
I can see that you donot check wheter the input has been completely consumed:
return boost::spirit::qi::phrase_parse(
begin, end,
grammar_parser ,
qi::space);
You can fix that by either requiring qi::eoi
:
return boost::spirit::qi::phrase_parse(
begin, end,
grammar_parser >> qi::eoi,
qi::space);
Or you can check the iterators:
bool ok = boost::spirit::qi::phrase_parse(
begin, end,
grammar_parser ,
qi::space);
if (begin != end)
std::cerr << "Remaining unparsed: '" << std::string(begin, end) << "'\n";
return ok && (begin == end);
Finally, note that side-effects of semantic actions can never be undone in the case of backtracking. See also: