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

Dan Bloomquist <[email protected]> Mon, 18 Nov 2019 17:40:50 -0800
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Dan Bloomquist wrote:
> I started here. ...

I'm gathering, even if I could not find it, that any semantic action 
will kill attribute propagation globally for the given target. At least, 
that is what I'm seeing. So, I just did it all with SA. The part where I 
make '= true/false' is verbose, I'm working on that. But this works.
Best, Dan.

#include <iostream>
#include <boost/fusion/adapted/struct.hpp>
#include <boost/spirit/home/x3.hpp>
struct font {
     std::string face_name;
     size_t point=0;
     bool bold=false;
     bool italic = false;
     bool strike = false;
     size_t id=0;
};
namespace parsers {
     using namespace boost::spirit::x3;
     auto const face = [](auto& attr) { _val(attr).face_name = 
_attr(attr); };
     auto const point = [](auto& attr) { _val(attr).point = _attr(attr); };
     auto const bold = [](auto& attr) { _val(attr).bold = _attr(attr); };
     auto const italic = [](auto& attr) { _val(attr).italic = 
_attr(attr); };
     auto const strike = [](auto& attr) { _val(attr).strike = 
_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[face] >>
         *(
             lit("size") >> '=' >> int_[point]
             | lit("bold") >> (('=' >> bool_[bold]) | attr(true)[bold])
             | lit("italic") >> (('=' >> bool_[italic]) | 
attr(true)[italic])
             | lit("strike") >> (('=' >> bool_[strike]) | 
attr(true)[strike])
             ) % ';';
}
int main() {
     font afont;
     std::string target;
     std::string test_str("font(Times New 
Roman;size=12;bold=true;italic);circle");
     auto begin = test_str.begin();
    phrase_parse(begin, test_str.end(), parsers::font_parser, 
boost::spirit::x3::space, afont);
     return 0;
}


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