3

I am trying to add error handling to one of my basic parsers. The parsers are the following:

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)

they parse into these structs:

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)
)

I am using this bases for error_handling and annotation: annotation, error_handling.

when I try to test the parsers and compile them I am getting these errors:

/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();

which is german for

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

I tried to learn how to use error implement error handling in spirit x3 by myself, but I can't find a way to make this work. Could anybody help me understanding how error_handling works in x3? I am stuck at this point.

Exagon
  • 4,798
  • 6
  • 25
  • 53
  • Having a complete example would make helping a lot easier. – llonesmiz Aug 18 '16 at 16:54
  • Did you notice [this](https://github.com/djowel/spirit_x3/blob/master/example/x3/calc9/main.cpp#L68) in the example? – llonesmiz Aug 18 '16 at 16:56
  • hell no i didnt, stupid me ... i will try if this helps – Exagon Aug 18 '16 at 17:17
  • do i need to wrap every parser with an error_handler_base in this with directive? – Exagon Aug 18 '16 at 18:29
  • 1
    I'm far from sure, but I think it's just the "entry level" parser, the one you pass to `parse`/`phrase_parse `. It should then be passed along, via the context, to the rest of the rules / parsers. – llonesmiz Aug 18 '16 at 18:33
  • doesn't seem like the error-handling and annotation thing is realy easy ... does anybody know where I can read how all this works together with the context etc? – Exagon Aug 18 '16 at 21:36
  • 2
    No time to expound it, but here's a livecoding session I did: [Spirit X3 Error Handling/Annotating parts #1 and #2](https://www.livecoding.tv/sehe/playlists/RJvnR-spirit-x3-tinkering/) – sehe Aug 18 '16 at 22:21
  • thank you very much i will have a look :) – Exagon Aug 18 '16 at 23:13
  • You might change this: +(x3::char_ - '"') to this +(~x3::char_('"')) – matiu Sep 17 '16 at 13:55
  • 3
    @sehe Your livecoding session appears to be behind a paywall (at least for me LiveEdu is telling me to "go pro" to see it). Some of your other videos seem to be working (without ability to navigate in the video). Would you consider moving some of these videos to a freely available service? I can find no good resouce for how to use Boost Spirit X3 error handling on the Internet, and am left wondering if your video might indeed be it. – sigbjornlo Apr 27 '17 at 07:21

0 Answers0