Let's say we want to parse a recursive block like this. When "skip_comments_tag
" is prefixed to the block, we skip all comments(/*...*/
) within this block recursively.
{
{}
{
skip_comments_tag{
{} /*comments*/
{ /*comments*/ }
}
}
}
It's easy to come up with a recursive parser as in Coliru.
namespace Parser {
auto const ruleComment = x3::lit("/*") >> *(x3::char_ - "*/") >> "*/" | x3::space;
x3::rule<struct SBlockId> const ruleBlock;
auto const ruleBlock_def = x3::lit('{') >> *(ruleBlock | "skip_comments_tag" >> x3::skip(ruleComment)[ruleBlock]) >> '}';
BOOST_SPIRIT_DEFINE(ruleBlock)
}
But it doesn't compile (when the parse
function is called) because it will generate an infinite context (by x3::make_context
in x3::skip_directive
). x3::no_case
and x3::with
also have this problem because they all use x3::make_context
in the implementation.
Questions:
- Is there always a better way to write parsers for this kind of questions to avoid such compile error and how?
- Or is the
x3::make_context
implementation considered to be flawed for this kind of questions?