3

我正在尝试将错误处理添加到我的一个基本解析器中。解析器如下:

struct string_literal_id : error_handler_base, annotation_base{};
struct regex_literal_id : error_handler_base, annotation_base{};
struct bool_literal_id : error_handler_base, annotation_base{};

typedef x3::rule<string_literal_id, string_literal> string_literal_type;
typedef x3::rule<regex_literal_id, regex_literal> regex_literal_type;
typedef x3::rule<bool_literal_id, bool_literal> bool_literal_type;



const string_literal_type string_literal_p = "string_literal";
const regex_literal_type regex_literal = "regex_literal";
const bool_literal_type bool_literal = "bool_literal";

auto const string_literal_p_def = x3::lexeme['"' >> +(x3::char_ - '"') >> '"'];
auto const regex_literal_def = x3::lexeme["'" >> +(x3::char_ - "'") >> "'"];
auto const bool_literal_def = x3::bool_;


BOOST_SPIRIT_DEFINE(string_literal_p, regex_literal, bool_literal)

他们解析成这些结构:

struct string_literal : x3::position_tagged {
    std::string compile_out() const;
    std::string value;
};

struct regex_literal : x3::position_tagged {
    std::string compile_out() const;
    std::string value;
};

struct bool_literal : x3::position_tagged {
    std::string compile_out() const;
    bool value;
};

BOOST_FUSION_ADAPT_STRUCT(
        string_literal,
        (std::string, value)
)
BOOST_FUSION_ADAPT_STRUCT(
        regex_literal,
        (std::string, value)
)
BOOST_FUSION_ADAPT_STRUCT(
        bool_literal,
        (bool, value)
)

我将这个基础用于 error_handling 和 annotation:annotationerror_handling

当我尝试测试解析器并编译它们时,我收到了这些错误:

/home/lukas/ClionProjects/tests/main.cpp:33:71: Fehler: keine passende Funktion für Aufruf von »boost::spirit::x3::unused_type::get()«
         auto &error_handler = x3::get<error_handler_tag>(context).get();

这是德语

Error: no matching function for calling »boost::spirit::x3::unused_type::get()«
             auto &error_handler = x3::get<error_handler_tag>(context).get();

我试图自己学习如何在精神 x3 中使用错误实现错误处理,但我找不到一种方法来完成这项工作。任何人都可以帮助我了解 error_handling 在 x3 中的工作原理吗?我被困在这一点上。

4

0 回答 0