我的情况:我是Spirit的新手,我必须使用VC6,因此我使用Spirit 1.6.4。我如何正确解析这个精神?
我有一条线,看起来像这样:
//The Description;DESCRIPTION;;
我想把文本DESCRIPTION
一个字符串,如果符合//The Description;
开始。
我有一些作品,但看起来不是那么优雅对我说:
vector<char> vDescription; // std::string doesn't work due to missing ::clear() in VC6's STL implementation
if(parse(chars,
// Begin grammar
(
as_lower_d["//the description;"]
>> (+~ch_p(';'))[assign(vDescription)]
),
// End grammar
space_p).hit)
{
const string desc(vDescription.begin(), vDescription.end());
}
我会更喜欢所有可打印字符分配到下一个3210但下面不会起作用,因为parse(...).hit == false
parse(chars,
// Begin grammar
(
as_lower_d["//the description;"]
>> (+print_p)[assign(vDescription)]
>> ';'
),
// End grammar
space_p).hit)
我该如何击中它?
谢谢,明天我会试试这个。 看来我的一方存在根本的误解。我认为解析器会尝试匹配的东西,如果可能的话,不要这么懒惰...... 你知道这个行为的术语是什么吗? – foraidt 2009-01-21 22:52:58
我认为这个词是“贪婪”。见http://www.boost.org/doc/libs/1_35_0/libs/spirit/doc/faq.html#greedy_rd – 2009-01-21 22:57:40