Im trying to parse a character string in an attribute of the user-defined type symbol , which contains the member std::string . I thought I could use BOOST_FUSION_ADAPT_STRUCT here, but this does not work.
If I declare a rule as rule<It, std::string(), space_type> , it works. If I define it as rule<It, symbol(), space_type> , it fails with the error "no type name value_type in symbol ". I think Spirit is trying to add a character-for-character value to an attribute that is not as expected. But is there no way to make this work without adding an additional intermediate rule that captures the std::string attribute?
Here is the full MWE:
#include <boost/fusion/include/adapt_struct.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> struct symbol { std::string repr; }; BOOST_FUSION_ADAPT_STRUCT(symbol, (std::string, repr)) namespace qi = boost::spirit::qi; template <typename Iterator> struct test_grammar : qi::grammar<Iterator, symbol(), qi::ascii::space_type> { test_grammar() : test_grammar::base_type{start} { start = qi::lexeme[+qi::char_("az")]; } qi::rule<Iterator, symbol(), qi::ascii::space_type> start; }; #include <iostream> auto main() -> int { test_grammar<std::string::iterator> grammar{}; auto input = std::string{"test"}; auto output = symbol{}; auto e = end(input); if (qi::phrase_parse(begin(input), e, grammar, qi::ascii::space, output)) std::cout << output.repr; }
c ++ boost-fusion boost-spirit
Konrad Rudolph
source share