X3: How should a custom parser be implemented?
"Ilya Shchukin" <[email protected]> Thu, 23 Jul 2020 06:39:18 +0500
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
What interface should a custom parser expose? As of now, I implement my parsers like this:
struct custom_parser_type : x3::parser<custom_parser_type>
{
static bool const handles_container = false;
static bool const is_pass_through_unary = false;
static bool const has_action = false;
template<typename It, typename Ctx, typename RCtx, typename Attribute>
bool parse(It& f, It l, Ctx&, RCtx&, Attribute& attr) const
{
// custom parsing here
If (/*succeeded*/)
{
if constexpr (!std::is_same_v<Attribute, x3::unused_type>)
{
// set attribute value
attr = {};
}
return true;
}
return false;
}
};
inline const custom_parser_type custom_parser;
Is my implementation correct? Is it the full interface X3 parser has to provide? What's the purpose of three static bools? A sequence of custom parsers doesn't compile without has_action. Should I derive from x3::parser_base or x3::parser<Derived>?