我使用Boost :: Spirit这个非常简单的解析器:
rule<std::string::iterator, std::string()> zeroTo255 = (string("25") >> char_('0', '5'))
| (char_('2') >> char_('0', '4') >> digit)
| (char_('1') >> repeat[2](digit))
| (char_('1', '9') >> digit) | digit;
Run Code Online (Sandbox Code Playgroud)
当我尝试解析时
std::string o{"1"};
std::string s;
parse(o.begin(), o.end(), zeroTo255, s);
std::cout << o << ": " << s << std::endl;
Run Code Online (Sandbox Code Playgroud)
我有输出
1: 111
Run Code Online (Sandbox Code Playgroud)
我显然做错了什么,但是什么?