Not able to use x3::skip(skipper)[some recursive rule] in its rule definition
Han Wang <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CAPDNnCY1WmqzPtMGoQr6ty9MSLXPyo_FUOJPBnuW0UmyT7uqZQ@mail.gmail.com> |
I've posted the same question in stackoverflow.
https://stackoverflow.com/questions/45282293/spirit-not-able-to-use-x3skipskippersome-recursive-rule-in-its-rule-defin
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
<http://coliru.stacked-crooked.com/a/31fb17064091fae3>.
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:
1. Is there always a better way to write parsers for this kind of
questions to avoid such compile error and how?
2. Or is the x3::make_context implementation considered to be flawed for
this kind of questions?
BTW: TU seperation doesn't solve this.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general