Parse succeeds, but doesn't propagate to first attribute with extra actions.

Dan Bloomquist <[email protected]> Mon, 18 Nov 2019 11:19:22 -0800
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
I started here.
<https://stackoverflow.com/questions/45673378/boost-spirit-x3-parse-into-structs>
There is yet another example in the comments of the question using an 
MPL map I like. But I decided that this is simple enough, just use 
semantic action. The confusion for me as that the commented parser will 
populate the 'face_name'. But with additional paring actions, they work 
but the 'face_name' is left blank. The below should paste and run.

Thanks for any clues, best, Dan.

#define BOOST_SPIRIT_X3_DEBUG
#include <iostream>
#include <boost/fusion/adapted/struct.hpp>
#include <boost/spirit/home/x3.hpp>
using namespace boost::spirit::x3; //for now...

struct font {
     std::string face_name;
     size_t point;
     bool bold;
     bool italic;
     bool strike;
     size_t id;
};
BOOST_FUSION_ADAPT_STRUCT(font, face_name)

namespace parsers {
     void dummy() { std::cout << "dummy\n"; }
     rule<class info, font> const info = "layer info";
     template <typename T>
     const auto as = [](const auto& parser) { return rule<struct _, T>{} 
= parser; };

     auto const point = [](auto& attr) { dummy(); _val(attr).point = 
_attr(attr); };

     auto word = lexeme[+char_("a-zA-Z")];
     auto words = lexeme[+char_("a-zA-Z ")];

//    auto font_parser = rule<struct _, font>() = lit("font(") >> words 
 >> ';';
     auto font_parser = rule<struct _, font>() = lit("font(") >> words 
 >> ';'
         >> *(
             lit("size") >> '=' >> int_[point]
             | lit("bold") >> -('=' >> int_[point])
             ) % ';';
}

int main() {
     using namespace parsers;
     //
     font afont;
     std::string target;
     std::string test_str("font(Times New Roman;size=12;bold=true);circle");
     auto begin = test_str.begin();
     bool r = phrase_parse(begin, test_str.end(), font_parser, space, 
afont);
     std::cout << std::boolalpha << r << std::endl;
     //
     return 0;
}


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