Re: compare of 2 existing methods to implement grammar recursion
Larry Evans <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On 07/29/2016 10:31 AM, Larry Evans wrote: > The repository: > https://github.com/boostorg/spirit/tree/develop > has toy.cpp here: > */workbench/x3/toy/toy.cpp > which connects the rule with it's rule_definition using > the context; however, it's not clear from the code how > to connect multiple rule's withe their rule_definition's. > > In contrast: > > */include/boost/spirit/home/x3/nonterminal/rule.hpp > > uses the BOOST_SPIRIT_DEFINE macro to do this, as illustrated by: > > */example/x3/calc/calc1.cpp > > The gist: > > https://gist.github.com/cppljevans/3634cc4e8ad4da81531608e6aa847de5 > > shows both methods except, in contrast to toy.cpp, it uses > make_defns to link multiple rule's with their definitions. > > Also, the gist uses a macro, USE_PARSE_RULE, to switch between the > 2 methods to ease comparison. OOPS. Apparently the 2 methods of linking a rule with it's rule_definition can be used together. The decision about which to use is done by the BOOST_SPIRIT_DEFINE; hence, the above rationale for USE_PARSE_RULE is not valid :( Hence, replaced the USE_PARSE_RULE macro with USE_SPIRIT_DEFINE macro. Comments under the macros should clarify their purpose. Also, added the USE_MIXED_DEF to decide whether to use both BOOST_SPIRIT_DEFINE *and* rule_defns to connect the rule's with their rule_definition's. The example output shows where BOOST_SPIRIT_DEFINE was used to link expr and fact with their rule_definition's, but where rule_defns was used to link term with it's rule_definition. [snip] ------------------------------------------------------------------------------