1

代替演算子 ('|') を含むルールの区切りをオフにしようとしていますが、互換性のない区切り文字に関するコンパイル エラーが発生します。例として、boost の calc2_ast_dump.cpp の例を取り上げ、構造体 dump_ast の ast_node ルールを次のように変更しました。

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

また、boost/spirit/home/karma/nonterminal/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 区切り記号を使用)。

代替案について私が見逃しているものはありますか?no_delimit が「<<」では機能するのに、「|」では機能しないのはなぜですか?

ブースト 1.48 を使用していますが、バグ修正が必要でしたか?

4

1 に答える 1

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で実際にご覧ください

于 2013-03-05T23:05:41.580 に答える