2013-03-05 4 views
1

대체 연산자 ('|')가 포함 된 규칙 주위에서 구분을 해제하려고하는데 호환되지 않는 구분 기호에 대한 컴파일 오류가 발생합니다. 예를 들어, 내가 부스트에서 calc2_ast_dump.cpp 예를 갔고, 수 구조체 dump_ast에서 ast_node 규칙을 수정 :boost :: spirit :: karma : 대체와 함께 no_delimit 사용

ast_node %= no_delimit[int_ | binary_node | unary_node]; 

그러나 이것은 컴파일 오류 제공 :

/usr/include/boost/function/function_template.hpp:754:17: note: candidate function not viable: no known conversion 
    from 'const 
boost::spirit::karma::detail::unused_delimiter<boost::spirit::karma::any_space<boost::spirit::char_encoding::ascii> 
    >' to 'const boost::spirit::karma::any_space<boost::spirit::char_encoding::ascii>' for 3rd argument 
result_type operator()(BOOST_FUNCTION_PARMS) const 

와 관련 의견을 부스트에서/정신/홈/업/비단/rule.hpp : (사용하여 내 자신의 프로젝트에

// If you are seeing a compilation error here stating that the 
// third parameter can't be converted to a karma::reference 
// then you are probably trying to use a rule or a grammar with 
// an incompatible delimiter type. 

, 나는 문제없이 "no_delimit [A < < B]를"할 수 있어요 karma :: space delimiter).

대체 방법에 대해 누락 된 것이 있습니까? no_delimit은 '< <'과 함께 작동하지만 '|'가 아닌 이유는 무엇입니까?

부스트 1.48을 사용하고 있으므로 픽업해야하는 버그 픽스가 있습니까?

답변

2

구분 기호를 사용하지 않는다는 사실을 반영하기 위해 규칙 선언을 수정해야합니다. 당신이 무엇이든지, 어떤 단락 문자를 싶지 않다고 가정

:

template <typename OuputIterator> 
struct dump_ast 
    : karma::grammar<OuputIterator, expression_ast()> 
{ 
    dump_ast() : dump_ast::base_type(ast_node) 
    { 
     ast_node %= int_ | binary_node | unary_node; 
     binary_node %= '(' << ast_node << char_ << ast_node << ')'; 
     unary_node %= '(' << char_ << ast_node << ')'; 
    } 

    karma::rule<OuputIterator, expression_ast()> ast_node; 
    karma::rule<OuputIterator, binary_op()> binary_node; 
    karma::rule<OuputIterator, unary_op()> unary_node; 
}; 

은 실제로 그것을했다, http://liveworkspace.org/code/4edZlj$0

+0

아에서 라이브를 참조하십시오. 하지만 내 프로젝트가 아닌 내 프로젝트를 명확히하기 위해 no_delimit에 사용 된 모든 하위 규칙 만 구분 기호를 사용하지 않도록 작성해야합니다. 이 이해가 맞습니까? – EHuhtala

+0

네, 기본적으로 맞습니다. skipper 유형을 템플릿 인수로'dump_ast' 생성기에 추가 할 수 있으며, 기본값을'spirit :: unused_type'으로 지정하면 규칙 정의를 변경하지 않고도 변경할 수 있습니다. – sehe