下面的程序尝试解析 C++ 标头包含字符串,例如"my/file.hpp"
和<my/file.hpp>
。由于我不明白的原因,我的代码无法解析"
标题。这是 Spirit 中的错误,还是我遗漏了一些明显的东西?
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/home/x3.hpp>
#include <iostream>
#include <string>
#include <cassert>
using namespace boost::spirit::x3;
int main() {
auto header_name_brackets = '<' >> *(~char_('>')) >> '>';
auto header_name_quotes = '"' >> *(~char_('>')) >> '"';
{
auto s = std::string{"<my/file.hpp>"};
std::string parsed;
assert(phrase_parse(s.begin(), s.end(), header_name_brackets, space, parsed));
}
{
auto s = std::string{"\"my/file.hpp\""};
std::string parsed;
// this assert fails, but I don't know why.
assert(phrase_parse(s.begin(), s.end(), header_name_quotes, space, parsed));
}
}