[英]boost::spirit::qi::parse --> No result
請考慮以下代碼:
namespace qi = boost::spirit::qi;
typedef qi::rule<
std::string::const_iterator
> rule_type;
rule_type value_rule = +qi::char_ - ( '[' | qi::eoi );
std::string input( "Hello World" );
std::string value0, value1;
bool b0 = qi::parse( input.begin( ),
input.end( ),
value_rule,
value0 );
bool b1 = qi::parse( input.begin( ),
input.end( ),
+qi::char_ - ( '[' | qi::eoi ),
value1 );
結果:
b0 = true
b1 = true
value0 = ""
value1 = "Hello World"
我很困惑為什么結果不同。 為獲得相同的結果,qi :: rule類型的正確定義是什么?
您忘記使規則聲明其公開的屬性類型:
typedef qi::rule<std::string::const_iterator, std::string()> rule_type;
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
int main()
{
std::string const input( "Hello World" );
{
typedef qi::rule<std::string::const_iterator, std::string()> rule_type;
rule_type value_rule = +qi::char_ - ( '[' | qi::eoi );
std::string value;
bool ok = qi::parse( input.begin( ),
input.end( ),
value_rule,
value );
std::cout << std::boolalpha << ok << "\t" << value << "\n";
}
{
std::string value;
bool ok = qi::parse( input.begin( ),
input.end( ),
+qi::char_ - ( '[' | qi::eoi ),
value );
std::cout << std::boolalpha << ok << "\t" << value << "\n";
}
}
產量
true Hello World
true Hello World
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.