解析为 x3::variant 时出现编译器错误
Compiler errors when parsing into x3::variant
我或多或少正在做 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': none of the 4 overloads could convert all the argument types ZeusCore d:\boost_1_67_0\boost\spirit\home\x3\support\traits\move_to.hpp 224
我希望,我没有把代码简化太多...
我正在使用 boost 1.67 和 Visual Studio 2017 的最新版本。
从您发布的内容看来,问题出在引用 *_def
上。 cRule_def
和 ccRule_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
是多余的。
我或多或少正在做 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': none of the 4 overloads could convert all the argument types ZeusCore d:\boost_1_67_0\boost\spirit\home\x3\support\traits\move_to.hpp 224
我希望,我没有把代码简化太多...
我正在使用 boost 1.67 和 Visual Studio 2017 的最新版本。
从您发布的内容看来,问题出在引用 *_def
上。 cRule_def
和 ccRule_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
是多余的。