【问题标题】:Compiler errors when parsing into x3::variant解析为 x3::variant 时出现编译器错误
【发布时间】:2018-09-08 17:47:00
【问题描述】:

我在 X3 上或多或少地做了我的第一步,并且已经成功地解析了一个包含 2 个成员的简单结构。但是我没能把这个结构变成一个变体。

(简化的)代码如下所示:

struct Command1
{
            CommandType type;
            std::string objName;
}
BOOST_FUSION_ADAPT_STRUCT(
    Command1,
    type, objName
);

struct Nil {};
using Command = x3::variant<Nil, Command1>;

const x3::rule<struct create_cmd_rule, Command1> ccRule = "ccRule";
const auto ccRule_def = typeRule > identifier;

const x3::rule<struct create_rule, Command> cRule = "cRule";
const auto cRule_def = x3::omit[x3::no_case["CREATE"]] > (ccRule_def);

如果我这样称呼它

Command1 cmd;
x3::phrase_parse(statement.cbegin(), statement.cend(), parser::cRule_def, x3::space, cmd);

一切都很好。但如果我通过我的变体:

Command cmd;
x3::phrase_parse(statement.cbegin(), statement.cend(), parser::cRule_def, x3::space, cmd);

它不编译: 严重性代码 描述 项目文件行抑制状态 错误 C2665 'boost::spirit::x3::traits::detail::move_to': 4 个重载都不能转换所有参数类型 ZeusCore d:\boost_1_67_0\boost\spirit\home\x3\support\traits\ move_to.hpp 224

希望,我没有将代码简化太多...

我正在使用 boost 1.67 和最新版本的 Visual Studio 2017。

【问题讨论】:

  • 请始终提供显示错误的MCVE
  • 谢谢!实际上,我过于简化了我的代码。大多数规则我都有 BOOST_SPIRIT_DEFINE,但我的“标识符”规则没有。

标签: c++ boost-spirit-x3


【解决方案1】:

从您发布的内容看来,引用 *_def 时出现的问题。 cRule_defccRule_def不是规则,它们只是链接存储在变量中的解析器。

尝试替换:

const auto cRule_def = x3::omit[x3::no_case["CREATE"]] > (ccRule_def);

与:

const auto cRule_def = x3::omit[x3::no_case["CREATE"]] > (ccRule);

BOOST_SPIRIT_DEFINE(cRule, ccRule);

然后这样称呼它:

Command1 cmd;
x3::phrase_parse(statement.cbegin(), statement.cend(), parser::cRule, x3::space, cmd);

这是一个玩具工作示例,我曾经尝试复制错误https://wandbox.org/permlink/BMP5zzHxPZo7LUDi

其他说明:x3::omit[x3::no_case["CREATE"]] 中的x3::omit 是多余的。

【讨论】:

    猜你喜欢
    • 2012-11-23
    • 1970-01-01
    • 2012-09-21
    • 2011-02-09
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多