我如何神交提振精神编译器错误 [英] How do I grok boost spirit compiler errors

查看:120
本文介绍了我如何神交提振精神编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 no_skip 指令解析形式输入:

 状态PASS
<标签>状态FAIL

我使用 ASCII ::空白我的队长。我得到的,当我换 no_skip [trans_assign_expr]一个编译错误来解析的标签。

我如何解决这个错误,而在一般情况下,我怎么知道这些错误,这样我可以解决未来的呢?升压精神永不文档使用包括精神这方面:(

这是错误


从/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:在成员函数'布尔提振精神:: ::气::规则::解析(迭代器和,常量迭代器和,语境,常量和船长,属性和)常量[结合语境=的boost ::精神::背景下,提振::融合:: vector0>,船长=的boost ::精神::齐::详细:: unused_skipper>>属性=常数的boost ::精神:: unused_type ,迭代器= __gnu_cxx :: __ normal_iterator>,T1 =提振::原:: exprns _ :: EXPR>,0L>,T2 =的boost ::精神:: unused_type,T3 =的boost ::精神:: unused_type,T4 =提升: :精神:: unused_type]:
/usr/include/boost/spirit/home/qi/reference.hpp:43:71:从'布尔的boost ::精神::齐::参考::解析实例化(迭代器和,常量迭代器和,语境,常量和船长,属性& )const的[与迭代器= __gnu_cxx :: __ normal_iterator>,上下文=的boost ::精神::背景下,提振::融合:: vector0>,船长=的boost ::精神::齐::详细:: unused_skipper>>属性=常数的boost ::精神:: unused_type,主题=常数的boost ::精神::齐::规则>,促进::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,升压: :精神:: unused_type,提振精神:: :: unused_type>]
/usr/include/boost/spirit/home/qi/directive/no_skip.hpp:64:63:从'布尔的boost ::精神::齐:: no_skip_directive ::解析实例化(迭代器和,常量迭代器和,语境,常量和船长,属性和)常量[与迭代器= __gnu_cxx :: __ normal_iterator>,上下文=的boost ::精神::背景下,提振::融合:: vector0>,船长=的boost ::精神::齐:: char_class>属性=常数提振精神:: :: unused_type,主题=的boost ::精神::齐::参考>,提振::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神::: :unused_type,提振精神:: :: unused_type>>]'
/usr/include/boost/spirit/home/qi/detail/fail_function.hpp:45:74:从'布尔的boost ::精神::齐::详细:: fail_function ::运算符()实例化(const的元件与)常量[使用组件=的boost ::精神::齐:: no_skip_directive>,提振::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type,提振::精神:: unused_type>>>,迭代器= __gnu_cxx :: __ normal_iterator>,上下文=的boost ::精神::背景下,提振::融合:: vector0>,船长=的boost ::精神::齐:: char_class>]
/usr/include/boost/fusion/algorithm/query/detail/any.hpp:42:83:[跳过8实例化上下文]
/usr/include/boost/function/function_template.hpp:132:42:从静态ř的boost ::具体实例::功能:: function_obj_invoker4 ::调用(::提高::详细::功能与function_buffer,T0,T1 ,T2,T3)与FunctionObj =的boost ::精神::齐::详细:: parser_binder>,提振::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振::精神:: unused_type,提振精神:: :: unused_type>>,提振::融合::利弊>,提振::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振::精神:: unused_type,提振精神:: :: unused_type>>>,提振::融合::零>>>>,MPL _ :: bool_>,R =布尔,T0 = __gnu_cxx :: __ normal_iterator>&,T1 =常数__gnu_cxx :: __ normal_iterator>&,T2 =的boost ::精神::背景下,提振::融合:: vector0>&T3 =常数的boost ::精神::齐:: char_class>&]'
/usr/include/boost/function/function_template.hpp:913:60:从'无效的boost :: function4 :: assign_to(仿函数)实例化[用函子=的boost ::精神::齐::详细:: parser_binder>提高::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type,提振精神:: :: unused_type>>,提振::融合::利弊>提高::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type,提振精神:: :: unused_type>>>,提振::融合::零> >>>,MPL _ :: bool_>,R =布尔,T0 = __gnu_cxx :: __ normal_iterator>&,T1 =常数__gnu_cxx :: __ normal_iterator>&,T2 =的boost ::精神::背景下,提振::融合:: vector0 >&T3 =常数的boost ::精神::齐:: char_class>&]'
/usr/include/boost/function/function_template.hpp:722:7:从'助推:: function4 :: function4实例化(仿函数类型名的boost :: enable_if_c ::值> ::价值,诠释> ::类型)与函子=的boost ::精神::齐::详细:: parser_binder>,提振::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type,升压::精神:: unused_type>>,提振::融合::利弊>,提振::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type,升压::精神:: unused_type>>>,提振::融合::零>>>>,MPL _ :: bool_>,R =布尔,T0 = __gnu_cxx :: __ normal_iterator>&,T1 =常数__gnu_cxx :: __ normal_iterator>& ,T2 =的boost ::精神::背景下,提振::融合:: vector0>&T3 =常数的boost ::精神::齐:: char_class>&类型名称的boost :: enable_if_c ::值> ::值, INT> ::类型= INT]'
/usr/include/boost/function/function_template.hpp:1064:16:从'的boost ::功能::功能(仿函数类型名的boost :: enable_if_c ::值> ::价值,诠释> ::型)[实例与函子=的boost ::精神::齐::详细:: parser_binder>,提振::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type,升压::精神:: unused_type>>,提振::融合::利弊>,提振::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type,升压::精神:: unused_type>>>,提振::融合::零>>>>,MPL _ :: bool_>,R =布尔,T0 = __gnu_cxx :: __ normal_iterator>&,T1 =常数__gnu_cxx :: __ normal_iterator>& ,T2 =的boost ::精神::背景下,提振::融合:: vector0>&T3 =常数的boost ::精神::齐:: char_class>&类型名称的boost :: enable_if_c ::值> ::值, INT> ::类型= INT]'
/usr/include/boost/function/function_template.hpp:1105:5:从'类型名称的boost :: enable_if_c ::值> ::值实例化,提振::函数&> ::类型boost ::功能::运算符=(仿函数)具有函子=的boost ::精神::齐::详细:: parser_binder>,提振::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type,提振精神:: :: unused_type>>,提振::融合::利弊>,提振::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type,提振精神:: :: unused_type>>>,提振::融合::零>>>>,MPL _ :: bool_>,R =布尔,T0 = __gnu_cxx :: __ normal_iterator>&,T1 =常数__gnu_cxx :: __normal_iterator>&,T2 =的boost ::精神::背景下,提振::融合:: vector0>&T3 =常数的boost ::精神::齐:: char_class>&类型名称的boost :: enable_if_c ::值>: :值,提振::函数&> :: =类型的boost ::功能>&,常量__gnu_cxx :: __ normal_iterator>&,提振精神:: ::背景下,提振::融合:: vector0>&,常量的boost ::精神::齐:: char_class>&)>&]'
/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp:198:13:从'的boost ::精神::齐::规则及升压::精神::齐::规则::操作符创建= (常量Expr的&)与Expr的=的boost ::原:: exprns _ :: EXPR>,提振::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type ,提振精神:: :: unused_type>&,常量的boost ::原:: exprns _ :: EXPR,0L>&>,2L>&,常量的boost ::原:: exprns _ :: EXPR,0L>&,升压: :精神::补气::规则>,促进::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type,提振精神:: :: unused_type>& >,2L>&>,2L>,迭代器= __gnu_cxx :: __ normal_iterator>,T1 =提振::原:: exprns _ :: EXPR>,0L>,T2 =的boost ::精神:: unused_type,T3 =的boost ::精神:: unused_type,T4 =的boost ::精神:: unused_type,提振精神:: ::气:: =规则的boost ::精神::齐::规则>,促进::原:: exprns _ :: EXPR> 0升>,提振精神:: :: unused_type,提振精神:: :: unused_type,提振精神:: :: unused_type>]
../src/RJstate.cpp:49:7:从实例化'fsm_grammar :: fsm_grammar()[与迭代器= __gnu_cxx :: __ normal_iterator>,船长=的boost ::原:: exprns _ :: EXPR>,0L>]
../src/RJstate.cpp:112:50:从这里实例化
/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp:277:17:错误:不对应的呼叫'(常量函式{又名常量的boost ::功能>&,常量__gnu_cxx :: __ normal_iterator> &,提振精神:: ::背景下,提振::融合:: vector0>&,常量的boost ::精神::齐:: char_class>&)>})(__gnu_cxx :: __ normal_iterator>&,常量__gnu_cxx :: __ normal_iterator >&,提振精神:: ::气::规则>,促进::原:: exprns _ :: EXPR>,0L>,提振精神:: :: unused_type,提振精神:: :: unused_type,提振精神:: :: unused_type> :: context_type&,常量的boost ::精神::齐::详细:: unused_skipper>>&)'
/usr/include/boost/function/function_template.hpp:1043:7:注:候选人是:
/usr/include/boost/function/function_template.hpp:1006:1:注:提振:: function4 :: result_type的升压:: function4 ::运算符()(T0,T1,T2,T3)常量[与R =布尔,T0 = __gnu_cxx :: __ normal_iterator>&,T1 =常数__gnu_cxx :: __ normal_iterator>&,T2 =的boost ::精神::背景下,提振::融合:: vector0>&T3 =常数的boost ::精神::气:: char_class>&,提振:: function4 :: result_type的布尔=]
/usr/include/boost/function/function_template.hpp:1006:1:注:为了论证4从'常量的boost ::精神::齐::详细:: unused_skipper>>到常量的boost ::没有已知的转换精神::齐:: char_class>&'

这是我的code

 的#define BOOST_SPIRIT_DEBUG#包括LT&;&iostream的GT;
#包括LT&;矢量>
#包括LT&;&迭代器GT;
#包括LT&;&的fstream GT;//转发到<升压/精神的/ home /气/非终结/ grammar.hpp>
#包括LT&;升压/精神/有/ qi_grammar.hpp>
//转发到<升压/精神的/ home /气/非终结/ rule.hpp>
#包括LT&;升压/精神/有/ qi_rule.hpp>#包括LT&;升压/精神/有/ qi.hpp>#包括LT&;升压/精神/有/ qi_char_class.hpp>
#包括LT&;升压/精神/有/ qi_no_skip.hpp>#包括LT&;升压/精神/有/ phoenix.hpp>#包括TestParser.hpp////////////////////////////////////////////////// /////////////////////////////命名空间补气=的boost ::精神::补气;
命名空间ASCII =的boost ::精神:: ASCII;模板< typename的迭代器,类型名船长=补气::空间类型>
结构fsm_grammar:补气::语法<迭代器,船长>
{
   fsm_grammar():fsm_grammar :: base_type(脚本)
   {
      使用boost ::精神:: double_;
      使用boost ::精神:: ASCII :: char_;
      使用boost ::精神:: ASCII :: alnum;
      使用boost ::精神:: ASCII ::阿尔法;
      使用boost ::精神::点燃;
      使用boost ::精神::补气:: EOL;
      使用boost ::精神::补气::意向书;
      使用boost ::精神::词位;
      使用boost ::精神::补气:: no_skip;
      使用boost ::精神::齐:: _ 1;
      使用boost ::精神::齐:: _ VAL;      // ID =字符_(A-ZA-Z)[_ VAL + = _1] GT;> *字符_(A-ZA-Z_0-9),[_ VAL + = _1]。
      ID =语义的α[_val + = _1] GT;> * alnum [_val + = _1] GT;> !alnum];
      STATE_ID =状态>> ID;
      start_expr =开始>> ID;
      trans_assign_expr =亮(\\ t的)GT;> STATE_ID>> +(炭_('一个','Z'));
      trans_expr = STATE_ID>> EOL>> no_skip [trans_assign_expr]
      assign_expr =字符_(A-ZA-Z);
      states_list =状态>> +(ID);
      EXPR =(trans_expr | start_expr | states_list)GT;> + EOL;
      脚本= * expr的>>意向书;      BOOST_SPIRIT_DEBUG_NODE(脚本);
      BOOST_SPIRIT_DEBUG_NODE(states_list);
      BOOST_SPIRIT_DEBUG_NODE(表达式);
      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);      标准::字符串VAL =PASS;
      // test_parser(+字符_(A-ZA-Z));
   }   齐::规则<迭代器,船长>脚本;
   齐::规则<迭代器,船长> states_list;
   齐::规则<迭代器,船长> EXPR;
   齐::规则<迭代器,船长> trans_expr;
   齐::规则<迭代器,船长> trans_assign_expr;
   齐::规则<迭代器,船长> assign_expr;
   齐::规则<迭代器,船长> start_expr;
   齐::规则<迭代器,船长> STATE_ID;
   齐::规则<迭代器,标准::字符串()> ID;
};


解决方案

由于llonesmiz非常恰当地指出:


  • 查找静态断言( ******像这样的错误'小说'******

  • 看征求意见的直接的(我的意思是,直接)上空的'失败'行。这包括在该模板实例被触发点。


      

    如果你看到一个编译错误,在这里指出,第四参数不能转换为所需的目标类型,那么你很可能试图用一个规则或语法不兼容的队长类型。


    在此情况下,由于要使用 trans_assign_expr 无船长,您必须声明它没有之一:

      //没有船长
    齐::规则<迭代器,标准::字符串()> ID;
    齐::规则<&迭代器GT; STATE_ID;
    齐::规则<&迭代器GT; trans_assign_expr;


这使得它编译。输出表明,它并不/工作/,虽然。

我不相信这是你想做的事的东西。由于语义似乎是一个更好的选择在这里,反正。我想简化 ID 规则:

  ID =语义的α>> * alnum];

语义已经在本地使用禁用船长属性。

下面是语法略有变化 http://liveworkspace.org/$c $ C / 70f3319342c567854b9f785ac13508d6

  trans_assign_expr = STATE_ID>> +(炭_('一个','Z'));
trans_expr = STATE_ID>> no_skip [EOL>> '\\ t']>> trans_assign_expr;

正如你所看到的,我包括与 EOL 在no_skip(避免船长吃了标签)。通过这种方式,船长是的仍然在 trans_assign_expr 作用的 - 这使得它接受额外的空间。给定了输入

 为const char输入[] =状态PASS \\ n \\ T状态FAIL多;

输出现在

 <脚本>
  <尽量>状态PASS \\ n \\ T状态F< /&尝试GT;
  <&expr的GT;
    <尽量>状态PASS \\ n \\ T状态F< /&尝试GT;
    < trans_expr>
      <尽量>状态PASS \\ n \\ T状态F< /&尝试GT;
      <&STATE_ID GT;
        <尽量>状态PASS \\ n \\ T状态F< /&尝试GT;
        <&ID GT;
          <尽量> PASS \\ n \\ T状态FAIL M< /&尝试GT;
          <成功与GT; \\ n \\ T状态FAIL等等\\ n< /成功>
          <&属性GT; [P,A,S,S]]< /属性>
        < / ID>
        <成功与GT; \\ n \\ T状态FAIL等等\\ n< /成功>
        <&属性GT;< /属性>
      < / STATE_ID>
      < trans_assign_expr>
        <尽量> FAIL状态等等\\ n< /&尝试GT;
        <&STATE_ID GT;
          <尽量> FAIL状态等等\\ n< /&尝试GT;
          <&ID GT;
            <尽量> FAIL等等\\ n< /&尝试GT;
            <成功与GT;等等\\ n< /成功>
            <&属性GT; [F,A,I,L]]< /属性>
          < / ID>
          <成功与GT;等等\\ n< /成功>
          <&属性GT;< /属性>
        < / STATE_ID>
        <成功与GT; \\ n< /成功>
        <&属性GT;< /属性>
      < / trans_assign_expr>
      <成功与GT; \\ n< /成功>
      <&属性GT;< /属性>
    < / trans_expr>
    <成功与GT;< /成功>
    <&属性GT;< /属性>
  < / EXPR>
  <&expr的GT;
    <尽量>< /&尝试GT;
    < trans_expr>
      <尽量>< /&尝试GT;
      <&STATE_ID GT;
        <尽量>< /&尝试GT;
        <失败/>
      < / STATE_ID>
      <失败/>
    < / trans_expr>
    < start_expr>
      <尽量>< /&尝试GT;
      <失败/>
    < / start_expr>
    < states_list>
      <尽量>< /&尝试GT;
      <失败/>
    < / states_list>
    <失败/>
  < / EXPR>
  <成功与GT;< /成功>
  <&属性GT;< /属性>
< / SCRIPT>
真正

I am trying to use the no_skip directive to parse input of the form:

state PASS
<tab> state FAIL

I am using ascii::blank as my skipper. I get an compile error when I wrap no_skip[ trans_assign_expr ] to parse for the tab.

How do I fix this error, and in general, how do I understand these errors so that I can fix future ones? The boost spirit documentation never covers this aspect of using spirit :(

This is the error

In file included from /usr/include/boost/spirit/home/qi/nonterminal/grammar.hpp:18:0,
                 from /usr/include/boost/spirit/include/qi_grammar.hpp:16,
                 from ../src/RJstate.cpp:9:
/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp: In member function ‘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, 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]’:
/usr/include/boost/spirit/home/qi/reference.hpp:43:71:   instantiated from ‘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 > >, Attribute = const boost::spirit::unused_type, Subject = 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:   instantiated from ‘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:   instantiated from ‘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:   [ skipping 8 instantiation contexts ]
/usr/include/boost/function/function_template.hpp:132:42:   instantiated from ‘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:   instantiated from ‘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:   instantiated from ‘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>::value, int>::type = int]’
/usr/include/boost/function/function_template.hpp:1064:16:   instantiated from ‘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>::value, int>::type = int]’
/usr/include/boost/function/function_template.hpp:1105:5:   instantiated from ‘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::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>::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:   instantiated from ‘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:   instantiated from ‘fsm_grammar::fsm_grammar() [with Iterator = __gnu_cxx::__normal_iterator >, Skipper = boost::proto::exprns_::expr >, 0l>]’
../src/RJstate.cpp:112:50:   instantiated from here
/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp:277:17: error: no match for call to ‘(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: note: candidate is:
/usr/include/boost/function/function_template.hpp:1006:1: note: 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: note:   no known conversion for argument 4 from ‘const boost::spirit::qi::detail::unused_skipper > >’ to ‘const boost::spirit::qi::char_class >&’

This is my code

#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;
};

解决方案

As llonesmiz very aptly pointed out:

  • look for static asserts (****** like this in the error 'novel' ******)
  • look for comments directly (I mean, directly) above a 'failing' line. This includes the points at which template instantiations were triggered.

    If you are seeing a compilation error here stating that the forth parameter can't be converted to a required target type then you are probably trying to use a rule or a grammar with an incompatible skipper type.

    In this case, since you want to use trans_assign_expr without a skipper, you must declare it without one:

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

This makes it compile. The output suggests it doesn't /work/, though.

I'm not convinced this is what you want to do. Since lexeme seems to be a better option here, anyway. I'd simplify the id rule:

id = lexeme [ alpha >> *alnum ];

lexeme already has the property of locally disabling the Skipper in use.

Here is a slight change of the grammar http://liveworkspace.org/code/70f3319342c567854b9f785ac13508d6

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

As you can see, I include the with eol in a no_skip (to avoid the skipper eating the tab). This way, the skipper is still in effect in trans_assign_expr - which makes it accept the extra space. Given the input

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

The output is now

<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

这篇关于我如何神交提振精神编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆