增强精神 X3:错误:在"..."中没有名为"大小"的类型
Boost Spirit X3: error: no type named 'size' in '...'
我试图解析成包含 std::string 和 std::vector 的结构,但在使用 Boost Spirit 的 %-运算符时总是出现错误。
我已经尝试将列表解析为单独的规则(源(和as<>
-指令与此问题隔离开来
如果没有predicate_arguments
规则,它可以完美运行。
错误非常大,一些片段:
[...] error: static assertion failed: The parser expects tuple-like attribute type
[...] error: no type named 'size' in 'struct dec::predicate_query'
[...] error: no type named 'type' in 'struct boost::fusion::extension::size_impl<boost::fusion::non_fusion_tag>::apply<dec::predicate_query>'
[...] error: non-constant condition for static assertion
decfile_parser.cpp
namespace x3 = boost::spirit::x3;
x3::rule<class predicate_name, std::string> predicate_name = "predicate_name";
x3::rule<class predicate_query, dec::predicate_query> predicate_query = "predicate_query";
x3::rule<class predicate_arguments, std::vector<dec::predicate_argument_type>> predicate_arguments = "predicate_arguments";
x3::rule<class predicate_argument, dec::predicate_argument_type> predicate_argument = "predicate_argument";
auto const predicate_query_def = predicate_name >> '(' >> predicate_arguments >> ')';
auto const predicate_arguments_def = predicate_argument % ',';
auto const predicate_name_def = *x3::char_("a-zA-Z");
// TODO: sortname
auto const predicate_argument_def = *x3::char_("a-zA-Z") | predicate_query;
decfile_parser::decfile_parser() {
}
void decfile_parser::parse_file(std::string filename) {
int value = 0;
std::string str("HoldsAt(Pos(), test)");
std::string::iterator strbegin = str.begin();
x3::phrase_parse(strbegin,
str.end(),
predicate_query,
x3::ascii::blank);
}
BOOST_SPIRIT_DEFINE(predicate_query, predicate_name, predicate_argument, predicate_arguments);
int main() {
decfile_parser par;
par.parse_file("test.e2");
}
decfile_parser.h
#include <boost/spirit/home/x3.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <string>
#include "ast.h"
class decfile_parser {
public:
decfile_parser();
~decfile_parser() = default;
void parse_file(std::string filename);
};
阿斯特·
namespace dec {
namespace x3 = boost::spirit::x3;
struct predicate_query;
typedef x3::variant<std::string, x3::forward_ast<predicate_query>> predicate_argument_type;
struct predicate_query {
std::string name;
std::vector<predicate_argument_type> arguments;
};
}
ast_adapted.h
#include <boost/fusion/include/adapt_struct.hpp>
#include "ast.h"
BOOST_FUSION_ADAPT_STRUCT(
dec::predicate_query,
(std::string, name),
(std::vector<dec::predicate_argument_type>, arguments)
)
编辑1:也许是因为他想解析name
并arguments
到一个容器中。
我忘了将ast_adapted.h
导入我的decfile_parser.h
。错误是因为结构当然不适合融合序列。
相关文章:
- 类型总是使用其大小存储在内存中吗
- 增强精神 X3:错误:在"..."中没有名为"大小"的类型
- 声明C++具有动态大小的数组类型在 Linux 中工作正常,但不能在 Windows 中工作
- 结构体和类的不同大小(),彼此具有相同的字段类型
- 是否可以根据其数据成员的类型确定类型的大小
- 类型的大小与无符号的等效项?
- 有没有办法通过插入新类型名称而不是 int 来使用 2 位大小类型而不是 int?
- 为什么 std::ssize 被强制为其有符号大小类型的最小大小
- 使用固定大小类型时强制对位字段(C++14 之前)进行签名
- 为什么特征矩阵库的固定大小类型与积分数据不是 PoD?
- C++变体:为什么转换构造函数需要大小.(类型)为非零
- 这个错误意味着什么:在任何函数之外声明的可变大小类型
- 大小(值)与大小(类型)
- 确定两个矢量类型或一个矢量类型与标量类型之间的二进制运算结果的正确大小类型
- 为什么reinterpret_cast不强制copy_n相同大小类型之间的转换?
- 对Cocos2d-x大小类型的引用不明确
- C++用于在指向相同大小类型的指针之间进行转换
- 继承构造函数-定义可移植的固定大小类型(C++)
- 使用通用矢量大小类型的最佳方式是什么
- C++矢量大小类型