我在大約一個升壓深深折服之間是::精神和永恆的挫折並不理解它;)升壓精神過於貪婪
我有一個字符串過於貪婪的問題,因此它不匹配。下面是一個最小的例子,它不會隨着txt規則的結束而解析。
有關我想要做什麼的更多信息:目標是解析一些僞SQL,並跳過空格。在像
select foo.id, bar.id from foo, baz
聲明我需要把from
作爲一個特殊的關鍵字。規則是類似於
"select" >> txt % ',' >> "from" >> txt % ','
但它顯然不工作,它看到bar.id from foo
作爲一個項目。
#include <boost/spirit/include/qi.hpp>
#include <iostream>
namespace qi = boost::spirit::qi;
int main(int, char**) {
auto txt = +(qi::char_("a-zA-Z_"));
auto rule = qi::lit("Hello") >> txt % ',' >> "end";
std::string str = "HelloFoo,Moo,Bazend";
std::string::iterator begin = str.begin();
if (qi::parse(begin, str.end(), rule))
std::cout << "Match !" << std::endl;
else
std::cout << "No match :'(" << std::endl;
}
謝謝!這個詞語是我錯過的東西。你完全正確地添加空格(我在示例中將它們留在了最小的東西上,但我想它比任何東西都更令人困惑) – 2011-03-20 09:20:23
幸運的猜測;)謝謝。 – phooji 2011-03-21 01:42:34