How to make a recursive rule in boost spirit x3 in VS2017(如何在VS2017的boost Spirit x3中制定递归规则)
问题描述
我在 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.
";
else
std::cout << "Parse failure (remainder: " << std::string(f, l) << ").
";
return 0;
}
Coliru 链接,g++
Coliru 链接,clang++
如何在 VS2017 中完成这项工作(如果可能)?
How do I make this work in VS2017 (if possible)?
P.S:Platform Toolset 设置为 v141,ISO 标准设置为 C++17,boost 版本为 1.66.0
P.S: Platform Toolset is set to v141, ISO standard is set to C++17, boost version is 1.66.0
P.P.S:编译错误如下
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
ee4943d5891bdae0706fb616b908e3bf528e0dfa
您可以将此提交中的补丁应用到您的安装中,也可以等待下一个版本.
You could either apply the patch from this commit to your installation or wait for the next release.
这篇关于如何在VS2017的boost Spirit x3中制定递归规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在VS2017的boost Spirit x3中制定递归规则
基础教程推荐
- 使用从字符串中提取的参数调用函数 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01