如何在VS2017中的Boost Spirit x3中制定递归规则 [英] How to make a recursive rule in boost spirit x3 in VS2017
问题描述
我在boost :: spirit :: x3中编写了以下递归规则,但它似乎只能在g ++ / clang中编译,而不是在VS2017(15.5.3)中编译:
I've written the following recursive rule in boost::spirit::x3 but it only seems to compile in g++/clang, not VS2017 (15.5.3):
#include <iostream>
#include <boost/spirit/home/x3.hpp>
namespace lex3
{
namespace x3 = boost::spirit::x3;
x3::rule<struct foo_class> const foo = "foo";
x3::rule<struct bar_class> const bar = "bar";
auto bar_def = *((x3::char_ - "/*") - "*/") >> *(foo > *((x3::char_ - "/*") - "*/"));
auto foo_def = "/*" > bar > "*/";
BOOST_SPIRIT_DEFINE(foo)
BOOST_SPIRIT_DEFINE(bar)
}
int main(int argc, char** argv)
{
std::string input = "/* a /* nested */ comment */";
auto f = input.begin();
auto l = input.end();
if (parse(f, l, lex3::foo) && (f == l))
std::cout << "Parse success.\n";
else
std::cout << "Parse failure (remainder: " << std::string(f, l) << ").\n";
return 0;
}
如何在VS2017中做到这一点(如果可能)?
How do I make this work in VS2017 (if possible)?
PS:平台工具集设置为v141,ISO标准设置为C ++ 17,增强版为1.66.0
P.S: Platform Toolset is set to v141, ISO standard is set to C++17, boost version is 1.66.0
PPS:编译错误如下
P.P.S: The compilation errors are as follows
error C2039: 'insert': is not a member of 'boost::spirit::x3::unused_type'
note: see declaration of 'boost::spirit::x3::unused_type'
error C2039: 'end': is not a member of 'boost::spirit::x3::unused_type'
note: see declaration of 'boost::spirit::x3::unused_type'
error C2039: 'begin': is not a member of 'boost::spirit::x3::unused_type'
note: see declaration of 'boost::spirit::x3::unused_type'
推荐答案
我签出了GitHub上的Boost.Spirit存储库,因为我的本地版本太旧了,并注意到您的示例可以使用最新的 develop
分支很好地编译但不适用于1.66.0版本(也适用于Clang和GCC)。将提交历史分成两部分,发现此错误已修复
I checked out the Boost.Spirit repository on GitHub because my local version was too old and noticed that your example compiles fine with the latest develop
branch but not with the 1.66.0 release (also on Clang and GCC). Bisecting the commit history revealed that this bug was fixed in
>您可以将此次提交中的补丁应用到您的安装中,或者等待下一个版本。
You could either apply the patch from this commit to your installation or wait for the next release.
这篇关于如何在VS2017中的Boost Spirit x3中制定递归规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!