Re: Spirit X3 employee.cpp compile error
Larry Evans <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On 08/20/2016 05:20 AM, Larry Evans wrote: > On 08/12/2016 08:29 AM, Larry Evans wrote: >> On 08/12/2016 07:53 AM, Vincent Virgilio wrote: >>> >>> >>> On Aug 12, 2016, at 08:27 AM, Larry Evans <[email protected]> wrote: >>> >>>> On 08/12/2016 06:40 AM, Larry Evans wrote: >>>> [snip] >>>>> >>>>>> GitHub: [email protected] <mailto:[email protected]>:boostorg/spirit.git >>>>>> >>>>>> Use the develop branch. >>>>>> --}--cut here-- >>>>>> >>>>> The 2 template arg rule code is actually in the x3-devel branch instead >>>>> of the develop branch: >>>>> >>>>> https://github.com/boostorg/spirit/blob/x3-devel/include/boost/spirit/home/x3/nonterminal/rule.hpp#L80 >>>>> >>>> [snip] >>>> However, if you decide to use x3-devel, then the employee.cpp code >>>> referenced in your OP needs to be modified so that the arguments >>>> to BOOST_SPIRIT_DEFINE contain assignments instead of just >>>> rule names. For example, see: >>>> >>>> https://github.com/boostorg/spirit/blob/x3-devel/example/x3/calc4.cpp#L218 >>>> >>>> HTH. >>>> >>>> -regards, >>>> Larry >>> >>> Hi Larry, >>> >>> Thanks for all the help so far. >>> >>> Why is BOOST_SPIRIT_DEFINE required if the rule declarations and >>> definitions are already associated via assignment? In another small >>> project, I was able to parse with an X3 grammar without that macro. In >>> that case, very schematically, I had "auto const rule_name = rule<...>() >>> = rule_def;" >>> >> [snip] >> Hi Vincent, >> >> I can only guess that the grammar in this small project had no >> recursive rules like the calc4.cpp grammar I mentioned above. >> >> That's only a guess; however, I *think* the whole purpose of >> BOOST_SPIRIT_DEFINE is to allow mutually recursive rules, > > Apparently that conclusion is wrong because here: > > https://github.com/boostorg/spirit/blob/master/test/x3/rule1.cpp#L48 > > there's a single recursive rule and there's no BOOST_SPIRIT_DEFINE. > > Sorry for misleading you. I'm still trying to learn how the code > works :( > OOPS. I should have re-looked at: https://github.com/boostorg/spirit/blob/develop/workbench/x3/toy/toy.cpp#L134 which shows the rule_definition<>::parse function stores the rule definition in the context dictionary. Then, even when BOOST_SPIRIT_DEFINE is not used, the rule rhs is looked up by the rule<...>::parse function: https://github.com/boostorg/spirit/blob/develop/workbench/x3/toy/toy.cpp#L154 The process is a little more complicated in the actual code. There, rule_defintion<...>::parse: https://github.com/boostorg/spirit/blob/master/include/boost/spirit/home/x3/nonterminal/rule.hpp#L64 *maybe* does something similar by putting the definition in the context dictionary where the key is the rule ID. Then, in subsequent calls to rule<...>::parse: https://github.com/boostorg/spirit/blob/master/include/boost/spirit/home/x3/nonterminal/rule.hpp#L113 the rule_parse<...> function looks up the definition in the context, if it can: https://github.com/boostorg/spirit/blob/master/include/boost/spirit/home/x3/nonterminal/rule.hpp#L37 Of course, I maybe missing something. It's happened before :( -regards, Larry ------------------------------------------------------------------------------