Re: Not able to use x3::skip(skipper)[some recursive rule] in its rule definition
Larry Evans <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On 07/25/2017 03:40 AM, Han Wang wrote:
> 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>.
>
> |namespaceParser{autoconstruleComment =x3::lit("/*")>>*(x3::char_
> -"*/")>>"*/"|x3::space;x3::rule<structSBlockId>construleBlock;autoconstruleBlock_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.
>
Hi Han.
You might try the get_rhs branch of a spirit fork here:
https://github.com/cppljevans/spirit/tree/get_rhs
and then #define BOOST_SPIRIT_GET_RHS_CRTP. As you can see from here:
https://github.com/cppljevans/spirit/blob/get_rhs/include/boost/spirit/home/x3/nonterminal/detail/rule.hpp#L140
that will disable the x3::make_context calls.
Please let me know if that works. If so, I might be
encouraged enough to go to the trouble of creating a pull request
despite the need (as pointed out in a private email) that
I'll need to document the rationale for the pull request.
HTH.
-regards,
Larry
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot