1

given a phoenix code [a(),b()], I think the correct behavior is called a() then b() respectively, but obviously in boost 1.47 only second function is called, this is what it is supposed to be? see the below code:

struct employee_parser : qi::grammar<Iterator, employee(), ascii::space_type>
{
    employee_parser() : employee_parser::base_type(start)
    {
        using qi::int_;
        using qi::lit;
        using qi::double_;
        using qi::lexeme;
        using ascii::char_;

        using ascii::string;
        using namespace qi::labels;            
        using boost::phoenix::ref;
        using boost::phoenix::val;

        quoted_string %= (lexeme['"' >> +(char_ - '"') >> '"' ]) ;

        start %= (
            lit("employee")
            >> '{'
            >>  int_ >> ','
            >>  quoted_string [std::cout<<ref(text1)<<" \n",ref(text1) = _1]  >> ',' 
            >>  quoted_string >> ','
            >>  double_
            >>  '}'  )                
            ;
    }

    qi::rule<Iterator, std::string(), ascii::space_type> quoted_string;
    qi::rule<Iterator, employee(), ascii::space_type> start;
    std::string text1;
};

why the first part isn't called? is it bug and fixed in latest boost library?

std::cout<<ref(text1)<<" \n"
Rui Zhou
  • 209
  • 1
  • 3
  • 9

1 Answers1

3

You probably need to explicitly include

#include <boost/spirit/include/phoenix_operator.hpp>

There used to be a version of boost where including the main Phoenix header failed to bring in this required header.

In more recent versions this is longer needed. And I'd generally recommend switching to Phoenix V3 in later versions:

#define BOOST_SPIRIT_USE_PHOENIX_V3

Phoenix V3 has more features, better (c++11) interop and is just generally more-evolved than Phoenix V2

sehe
  • 374,641
  • 47
  • 450
  • 633
  • 1
    hi sehe, seems the root cause is the below stuff: #include #include #include after I change to: `#include ` the problem is solved – Rui Zhou Oct 28 '13 at 10:02
  • Interesting. I may have remembered the actual missing header name wrong (I suppose you didn't narrow it down?). I usually just include the high-level headers, unless I really have a need to tweak compilation times (i.e. almost never; we're using Boost Spirit, right :)) – sehe Oct 28 '13 at 10:09
  • @RuiZhou I believe the header needed is "phoenix_statement.hpp". – llonesmiz Oct 28 '13 at 14:56