Iʼm playing with creating Boost.Spirit.Qi-based parsing. Having an example like calc_utree, I'm trying to extend what to use as semantic action.
It's trivial to reuse the same approach with an alone assignment as semantic action, for example
term =
factor [_val = _1]
as literally in the example. But, when I try to pass both into a function (method) external to the rule definition, or even write it as lambda, for example
term =
factor [([&] {_val = _1; })]
it causes silent misassignment in that place: _val
remains unchanged (without any error or warning from compiler). The same if I change it to something like
term =
factor [do_term_factor(_val, _1)]
<...>
template <typename D, typename S>
D& do_term_factor(D& d, S& s) {
d = s;
}
Seems Iʼve fallen into principal misconception with Qi
and Phoenix
. The questions are (principally they are different forms of the same one):
- What is specific with
Phoenix
variables that they donʼt work in C++ lambdas? - How to make it working with such external action call?
Alternatively, how _val
can be achieved without Phoenix
? Spirit
documentation seems quite obscure in this.
Environment details: Boost 1.58.0, gcc 5.4.0 or clang 4.0 (all of Ubuntu 16.04).