2011-05-05 5 views
0

Boost.Spirit V2.x (특히 Boost.Spirit.Qi)에서 사용하려면 구조체/클래스를 Boost.Fusion으로 래핑하는 것이 정말로 필요합니까? 오히려 의미 론적 액션을 사용하여 멤버에게 할당하는 것이 좋습니다. 내 기억이 잘 복무한다면, V1.x에서 그랬던 것처럼 ...Boost.Spirit V2.x를 Boost.Fusion없이 사용할 수 있습니까?

calculator example은 여전히 ​​가능해야한다고 제안합니다. 지금까지, 나는 그것을 할 수있는 좋은 방법을 찾지 못했습니다.

나는 당신이 employee example에서 어떻게 할 것인지보고 싶습니다. 다음은 컴파일되지 않지만 어쩌면 작동시킬 수있는 방법이있을 수 있습니다.

template <typename Iterator> 
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_; 

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

     start = 
      lit("employee") 
      >> '{' 
      >> int_[px::bind(&employee::age, qi::_val) = qi::_1] >> ',' 
      >> quoted_string[px::bind(&employee::surname, qi::_val) = qi::_1] >> ',' 
      >> quoted_string[px::bind(&employee::forename, qi::_val) = qi::_1] >> ',' 
      >> double_[px::bind(&employee::salary, qi::_val) = qi::_1] 
      >> '}' 
      ; 
    } 

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

답변

1

내게 아직도 오래된 퓨전 인쇄 물건이 있습니다. 질문을 게시 한 후에 실수를 찾는 것이 훨씬 더 쉬워졌습니다. :)

(작동하므로 생산 코드에 다른 오류가 있음)

관련 문제