Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ qi::规则<;It,std::string()>;不';t解析输入字符串_C++_Boost_Boost Spirit_Boost Spirit Qi - Fatal编程技术网

C++ qi::规则<;It,std::string()>;不';t解析输入字符串

C++ qi::规则<;It,std::string()>;不';t解析输入字符串,c++,boost,boost-spirit,boost-spirit-qi,C++,Boost,Boost Spirit,Boost Spirit Qi,我有一个奇怪的问题: qi::rule <Iterator, std::string ()> str = +alnum; // will not parse given input //param = "WELL" >> space >> str >> ((space >> no_case[control]) || (space >> no_case[limit])) >> space >> qi::

我有一个奇怪的问题:

qi::rule <Iterator, std::string ()> str = +alnum;
// will not parse given input
//param = "WELL" >> space >> str >> ((space >> no_case[control]) || (space >> no_case[limit])) >> space >> qi::eol; 

// will parse given input ok
param = "WELL" >> space >> +alnum >> ((space >> no_case[control]) || (space >> no_case[limit])) >> space >> qi::eol; 

expression = qi::no_skip[param];
qi::rule str=+alnum;
//不会解析给定的输入
//param=“WELL”>>space>>str>>((space>>无案例[控制])| |(space>>无案例[限制])>>space>>qi::eol;
//解析给定的输入是否正确
param=“WELL”>>space>>+alnum>>((space>>无案例[控制])| |(space>>无案例[限制])>>space>>qi::eol;
表达式=qi::无_跳过[param];
输入为“油井名称3生产油\n”。控件和限制是符号表

我做错了什么

upd

<param>
  <try>WELL name3 PROD OIL </try>

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff64db290 in boost::function4<bool, char*&, char* const&, boost::spirit::context<boost::fusion::cons<std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::fusion::nil>, boost::fusion::vector0<void> >&, boost::spirit::unused_type const&>::operator() (this=
    0x7fffffffd700, a0=@0x7fffffffd2d0, a1=@0x7fffffffda20, a2=..., a3=...)
    at /opt/libs/boost/boost/function/function_template.hpp:1013
1013                 (this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
定义了BOOST_SPIRIT_QI_DEBUG,并在表达式之前使用BOOST_SPIRIT_DEBUG_节点(param),如果使用str,我将获得以下输出:

<param>
  <try>WELL name3 PROD OIL </try>
Segmentation fault

3号井产品油
分段故障
在+alnum情况下,我得到:

<param>
  <try>WELL name3 PROD OIL </try>
  <success></success>
  <attributes>[]</attributes>
</param>

3号井产品油
[]
回溯

<param>
  <try>WELL name3 PROD OIL </try>

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff64db290 in boost::function4<bool, char*&, char* const&, boost::spirit::context<boost::fusion::cons<std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::fusion::nil>, boost::fusion::vector0<void> >&, boost::spirit::unused_type const&>::operator() (this=
    0x7fffffffd700, a0=@0x7fffffffd2d0, a1=@0x7fffffffda20, a2=..., a3=...)
    at /opt/libs/boost/boost/function/function_template.hpp:1013
1013                 (this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);

3号井产品油
程序接收信号SIGSEGV,分段故障。
boost::function4::operator()中的0x00007ffff64db290(此=
0x7FFFFFD700,a0=@0x7fffffffd2d0,a1=@0x7fffffffda20,a2=…,a3=…)
at/opt/libs/boost/boost/function/function_模板。hpp:1013
1013(此->函子BOOST\u函数\u逗号BOOST\u函数\u参数);

问题在于您在堆栈上定义了规则
str
(作为构造函数中的局部变量)。当语法的构造函数退出时,此变量超出范围,将
param
规则保留为对它的悬空引用。如果将
str
移动为语法的成员变量,则一切都会按预期工作


此外,您似乎希望跳过输入元素之间的空格。我建议看一下
短语\u parse
API以及如何使用Skipper。

这里有点难看——你能提供更多的代码吗——最好是一个小的可编译测试用例吗?是的,请提供我们可以尝试的最小但完整的代码片段。例如,param是如何定义的?很抱歉延迟回答。示例代码-.@hkaiser,param定义为qi::rule param;哦,我的错!很有效,谢谢!现在我尝试使用lex来标记输入:)hkaiser射门,他得分!:)