增强精神 X3:错误:在"..."中没有名为"大小"的类型

Boost Spirit X3: error: no type named 'size' in '...'

本文关键字:大小 类型 X3 错误 增强      更新时间:2023-10-16

我试图解析成包含 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:也许是因为他想解析namearguments到一个容器中。

我忘了将ast_adapted.h导入我的decfile_parser.h。错误是因为结构当然不适合融合序列。