5

我正在尝试使用该no_skip指令来解析表单的输入:

state PASS
<tab> state FAIL

我正在ascii::blank用作我的船长。当我换no_skip[ trans_assign_expr ]行以解析选项卡时出现编译错误。

我该如何修复这个错误,一般来说,我如何理解这些错误,以便我可以修复未来的错误?boost Spirit 文档从未涵盖使用 Spirit 的这一方面 :(

这是错误

在 /usr/include/boost/spirit/home/qi/nonterminal/grammar.hpp:18:0 包含的文件中,
                 来自 /usr/include/boost/spirit/include/qi_grammar.hpp:16,
                 来自../src/RJstate.cpp:9:
/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp: 在成员函数'bool boost::spirit::qi::rule::parse(Iterator&, const Iterator&, Context&, const Skipper&, Attribute&) const [with Context = boost::spirit::context, boost::fusion::vector0 >, Skipper = boost::spirit::qi::detail::unused_skipper >>, Attribute = const boost::spirit::unused_type , 迭代器 = __gnu_cxx::__normal_iterator >, T1 = boost::proto::exprns_::expr >, 0l>, T2 = boost::spirit::unused_type, T3 = boost::spirit::unused_type, T4 = boost: :spirit::unused_type]':
/usr/include/boost/spirit/home/qi/reference.hpp:43:71: 从 'bool boost::spirit::qi::reference::parse(Iterator&, const Iterator&, Context&, const Skipper&, Attribute& 实例化) const [with Iterator = __gnu_cxx::__normal_iterator >, Context = boost::spirit::context, boost::fusion::vector0 >, Skipper = boost::spirit::qi::detail::unused_skipper > >, 属性= const boost::spirit::unused_type, 主题 = const boost::spirit::qi::rule >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost: :spirit::unused_type, boost::spirit::unused_type>]'
/usr/include/boost/spirit/home/qi/directive/no_skip.hpp:64:63: 从 'bool boost::spirit::qi::no_skip_directive::parse(Iterator&, const Iterator&, Context&, const Skipper& , Attribute&) const [with Iterator = __gnu_cxx::__normal_iterator >, Context = boost::spirit::context, boost::fusion::vector0 >, Skipper = boost::spirit::qi::char_class >, Attribute = const boost::spirit::unused_type, Subject = boost::spirit::qi::reference >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit: :unused_type, boost::spirit::unused_type> >]'
/usr/include/boost/spirit/home/qi/detail/fail_function.hpp:45:74: 从 'bool boost::spirit::qi::detail::fail_function::operator()(const Component&) const 实例化[with Component = boost::spirit::qi::no_skip_directive >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::unused_type, boost:: Spirit::unused_type> > >, Iterator = __gnu_cxx::__normal_iterator >, Context = boost::spirit::context, boost::fusion::vector0 >, Skipper = boost::spirit::qi::char_class >]'
/usr/include/boost/fusion/algorithm/query/detail/any.hpp:42:83: [跳过 8 个实例化上下文]
/usr/include/boost/function/function_template.hpp:132:42: 从 'static R boost::detail::function::function_obj_invoker4::invoke(boost::detail::function::function_buffer&, T0, T1 , T2, T3) [with FunctionObj = boost::spirit::qi::detail::parser_binder >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost:: Spirit::unused_type, boost::spirit::unused_type> >, boost::fusion::cons >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost:: Spirit::unused_type, boost::spirit::unused_type> > >, boost::fusion::nil> > > >, mpl_::bool_ >, R = bool, T0 = __gnu_cxx::__normal_iterator >&, T1 = const __gnu_cxx::__normal_iterator >&, T2 = boost::spirit::context, boost::fusion::vector0 >&, T3 = const boost::spirit::qi::char_class >&]'
/usr/include/boost/function/function_template.hpp:913:60: 实例化自 'void boost::function4::assign_to(Functor) [with Functor = boost::spirit::qi::detail::parser_binder >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> >, boost::fusion::cons >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, boost::fusion::nil> > > >, mpl_::bool_ >, R = bool, T0 = __gnu_cxx::__normal_iterator >&, T1 = const __gnu_cxx::__normal_iterator >&, T2 = boost::spirit::context, boost::fusion::vector0 >&, T3 = const boost::spirit::qi::char_class >&]'
/usr/include/boost/function/function_template.hpp:722:7: 从 'boost::function4::function4(Functor, typename boost::enable_if_c::value>::value, int>::type) [ with Functor = boost::spirit::qi::detail::parser_binder >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::unused_type, boost ::spirit::unused_type> > boost::fusion::cons >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::unused_type, boost ::spirit::unused_type> > >, boost::fusion::nil> > > >, mpl_::bool_ >, R = bool, T0 = __gnu_cxx::__normal_iterator >&, T1 = const __gnu_cxx::__normal_iterator >& , T2 = boost::spirit::context, boost::fusion::vector0 >&, T3 = const boost::spirit::qi::char_class >&, typename boost::enable_if_c::value>::值,int>::type = int]'
/usr/include/boost/function/function_template.hpp:1064:16: 从 'boost::function::function(Functor, typename boost::enable_if_c::value>::value, int>::type) [ with Functor = boost::spirit::qi::detail::parser_binder >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::unused_type, boost ::spirit::unused_type> > boost::fusion::cons >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::unused_type, boost ::spirit::unused_type> > >, boost::fusion::nil> > > >, mpl_::bool_ >, R = bool, T0 = __gnu_cxx::__normal_iterator >&, T1 = const __gnu_cxx::__normal_iterator >& , T2 = boost::spirit::context, boost::fusion::vector0 >&, T3 = const boost::spirit::qi::char_class >&, typename boost::enable_if_c::value>::值,int>::type = int]'
/usr/include/boost/function/function_template.hpp:1105:5: 从 'typename boost::enable_if_c::value>::value, boost::function&>::type boost::function::operator=( Functor) [with Functor = boost::spirit::qi::detail::parser_binder >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::未使用类型,boost::spirit::unused_type> >, boost::fusion::cons >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::未使用类型,boost::spirit::unused_type> > >, boost::fusion::nil> > > >, mpl_::bool_ >, R = bool, T0 = __gnu_cxx::__normal_iterator >&, T1 = const __gnu_cxx:: __normal_iterator >&, T2 = boost::spirit::context, boost::fusion::vector0 >&, T3 = const boost::spirit::qi::char_class >&, 类型名 boost::enable_if_c::value>::value, boost::function&>::type = boost::function >&, const __gnu_cxx::__normal_iterator >&, boost::spirit::context, boost::fusion::vector0 >& , const boost::spirit::qi::char_class >&)>&]'
/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp:198:13: 从 'boost::spirit::qi::rule& boost::spirit::qi::rule::operator= 实例化(const Expr&) [with Expr = boost::proto::exprns_::expr >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::unused_type , boost::spirit::unused_type>&, const boost::proto::exprns_::expr, 0l>&>, 2l>&, const boost::proto::exprns_::expr, 0l>&, boost: :spirit::qi::rule >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type>& >, 2l>&>, 2l>, Iterator = __gnu_cxx::__normal_iterator >, T1 = boost::proto::exprns_::expr >, 0l>, T2 = boost::spirit::unused_type, T3 = boost:: Spirit::unused_type, T4 = boost::spirit::unused_type, boost::Spirit::qi::rule = boost::spirit::qi::rule >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::unused_type , boost::spirit::unused_type>]'
../src/RJstate.cpp:49:7: 实例化自 'fsm_grammar::fsm_grammar() [with Iterator = __gnu_cxx::__normal_iterator >, Skipper = boost::proto::exprns_::expr >, 0l>]'
../src/RJstate.cpp:112:50:从这里实例化
/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp:277:17: 错误:不匹配调用 '(const function_type {aka const boost::function >&, const __gnu_cxx::__normal_iterator > &, boost::spirit::context, boost::fusion::vector0 >&, const boost::spirit::qi::char_class >&)>}) (__gnu_cxx::__normal_iterator >&, const __gnu_cxx::__normal_iterator >&, boost::spirit::qi::rule >, boost::proto::exprns_::expr >, 0l>, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit ::unused_type>::context_type&, const boost::spirit::qi::detail::unused_skipper > >&)'
/usr/include/boost/function/function_template.hpp:1043:7:注意:候选人是:
/usr/include/boost/function/function_template.hpp:1006:1: 注意: boost::function4::result_type boost::function4::operator()(T0, T1, T2, T3) const [with R = bool , T0 = __gnu_cxx::__normal_iterator >&, T1 = const __gnu_cxx::__normal_iterator >&, T2 = boost::spirit::context, boost::fusion::vector0 >&, T3 = const boost::spirit::qi ::char_class >&, boost::function4::result_type = bool]
/usr/include/boost/function/function_template.hpp:1006:1:注意:参数 4 从 'const boost::spirit::qi::detail::unused_skipper >>' 到 'const boost:: 没有已知的转换精神::qi::char_class >&'

这是我的代码

#define BOOST_SPIRIT_DEBUG

#include <iostream>
#include <vector>
#include <iterator>
#include <fstream>

// forwards to <boost/spirit/home/qi/nonterminal/grammar.hpp>
#include <boost/spirit/include/qi_grammar.hpp>
// forwards to <boost/spirit/home/qi/nonterminal/rule.hpp>
#include <boost/spirit/include/qi_rule.hpp>

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

#include <boost/spirit/include/qi_char_class.hpp>
#include <boost/spirit/include/qi_no_skip.hpp>

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

#include "TestParser.hpp"

///////////////////////////////////////////////////////////////////////////////

namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;

template <typename Iterator, typename Skipper=qi::space_type>
struct fsm_grammar : qi::grammar<Iterator, Skipper>
{
   fsm_grammar() : fsm_grammar::base_type(script)
   {
      using boost::spirit::double_;
      using boost::spirit::ascii::char_;
      using boost::spirit::ascii::alnum;
      using boost::spirit::ascii::alpha;
      using boost::spirit::lit;
      using boost::spirit::qi::eol;
      using boost::spirit::qi::eoi;
      using boost::spirit::lexeme;
      using boost::spirit::qi::no_skip;
      using boost::spirit::qi::_1;
      using boost::spirit::qi::_val;

      //id = char_("a-zA-Z")[_val += _1] >> *char_("a-zA-Z_0-9")[_val += _1];
      id = lexeme[ alpha[_val += _1] >> *alnum[_val += _1] >> !alnum ];
      state_id = "state" >> id;
      start_expr = "start" >> id;
      trans_assign_expr = lit("\t") >> state_id >> +(char_('a','z'));
      trans_expr = state_id >> eol >> no_skip[ trans_assign_expr ];
      assign_expr = char_("a-zA-Z");
      states_list = "states" >> +(id);
      expr = (trans_expr | start_expr | states_list) >> +eol;
      script = *expr >> eoi;

      BOOST_SPIRIT_DEBUG_NODE(script);
      BOOST_SPIRIT_DEBUG_NODE(states_list);
      BOOST_SPIRIT_DEBUG_NODE(expr);
      BOOST_SPIRIT_DEBUG_NODE(start_expr);
      BOOST_SPIRIT_DEBUG_NODE(assign_expr);
      BOOST_SPIRIT_DEBUG_NODE(trans_expr);
      BOOST_SPIRIT_DEBUG_NODE(trans_assign_expr);
      BOOST_SPIRIT_DEBUG_NODE(state_id);
      BOOST_SPIRIT_DEBUG_NODE(id);

      std::string val = "PASS";
      //test_parser("  ",+char_("a-zA-Z"));
   }

   qi::rule<Iterator, Skipper> script;
   qi::rule<Iterator, Skipper> states_list;
   qi::rule<Iterator, Skipper> expr;
   qi::rule<Iterator, Skipper> trans_expr;
   qi::rule<Iterator, Skipper> trans_assign_expr;
   qi::rule<Iterator, Skipper> assign_expr;
   qi::rule<Iterator, Skipper> start_expr;
   qi::rule<Iterator, Skipper> state_id;
   qi::rule<Iterator, std::string()> id;
};
4

1 回答 1

5

正如 llonesmiz 非常恰当地指出的那样:

  • 寻找静态断言 ( ****** like this in the error 'novel' ******)
  • 在“失败”行上方直接(我的意思是,直接)查找评论。这包括触发模板实例化的点。

    如果您在此处看到编译错误,指出无法将第四个参数转换为所需的目标类型,那么您可能正在尝试使用不兼容的船长类型的规则或语法。

    在这种情况下,由于您想在trans_assign_expr没有船长的情况下使用,您必须在没有船长的情况下声明它:

    // no skippers
    qi::rule<Iterator, std::string()> id;
    qi::rule<Iterator> state_id;
    qi::rule<Iterator> trans_assign_expr;
    

这使它编译。但是,输出表明它不 /work/。

我不相信这是你想要做的。无论如何lexeme,这里似乎是一个更好的选择。我会简化id规则:

id = lexeme [ alpha >> *alnum ];

lexeme已经具有本地禁用正在使用的船长的属性。

这是语法http://liveworkspace.org/code/70f3319342c567854b9f785ac13508d6的轻微变化

trans_assign_expr = state_id >> +(char_('a','z'));
trans_expr        = state_id >> no_skip [ eol >> '\t' ] >> trans_assign_expr;

如您所见,我将 with 包含eol在 no_skip 中(以避免船长吃标签)。这样,船长仍然有效trans_assign_expr- 这使得它接受额外的空间。给定输入

const char input[]="state PASS\n\t state FAIL more";

现在的输出是

<script>
  <try>state PASS\n\t state F</try>
  <expr>
    <try>state PASS\n\t state F</try>
    <trans_expr>
      <try>state PASS\n\t state F</try>
      <state_id>
        <try>state PASS\n\t state F</try>
        <id>
          <try> PASS\n\t state FAIL m</try>
          <success>\n\t state FAIL more\n</success>
          <attributes>[[P, A, S, S]]</attributes>
        </id>
        <success>\n\t state FAIL more\n</success>
        <attributes>[]</attributes>
      </state_id>
      <trans_assign_expr>
        <try> state FAIL more\n</try>
        <state_id>
          <try> state FAIL more\n</try>
          <id>
            <try> FAIL more\n</try>
            <success> more\n</success>
            <attributes>[[F, A, I, L]]</attributes>
          </id>
          <success> more\n</success>
          <attributes>[]</attributes>
        </state_id>
        <success>\n</success>
        <attributes>[]</attributes>
      </trans_assign_expr>
      <success>\n</success>
      <attributes>[]</attributes>
    </trans_expr>
    <success></success>
    <attributes>[]</attributes>
  </expr>
  <expr>
    <try></try>
    <trans_expr>
      <try></try>
      <state_id>
        <try></try>
        <fail/>
      </state_id>
      <fail/>
    </trans_expr>
    <start_expr>
      <try></try>
      <fail/>
    </start_expr>
    <states_list>
      <try></try>
      <fail/>
    </states_list>
    <fail/>
  </expr>
  <success></success>
  <attributes>[]</attributes>
</script>
true
于 2012-10-22T09:46:25.630 回答