0

eps accepts a lazy argument that evaluates bool.

I've been using eps with pheonix objects like eps(_r1 == 0) >> something, and it has worked.

However, when I use a lambda function for more complex expression that can't be expressed in a pheonix form, static assertion is raised and fails to compile.

auto test_lazy_arg_f = [](const auto&, const auto& context) {
  return true;
}

boost::spirit::qi::eps(test_lazy_arg_f) >> whatever_i_need;

This fails to compile with the following error:

/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp:177:13: error: static assertion failed: error_invalid_expression
         BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);

https://wandbox.org/permlink/eiM6zDfyzuapcQtB (Thanks Nikita Kniazev)

I don't see any restriction on lazy arguments in spirit documentations.

How can I use non-pheonix function object?

Inbae Jeong
  • 4,053
  • 25
  • 38
  • 1
    It is very interesting that [Lazy Argument](https://www.boost.org/doc/libs/1_69_0/libs/spirit/doc/html/spirit/qi/reference/basics.html#spirit.qi.reference.basics.lazy_argument) documentation mentions pure functions, but in a reality it never supported that. – Nikita Kniazev Jan 28 '19 at 21:17
  • @NikitaKniazev Ah. That matches my experience too. I think it's just copied a little bit too _verbatim_ from the section describing _semantic actions_, which _does_ in many ways evaluate the expressions in a very similar context mostly. – sehe Jan 28 '19 at 22:36

1 Answers1

1

The code shown can't reproduce your issue (https://wandbox.org/permlink/uE5ONUXCjuX7j4Mt). I assume you meant in more context.

I think the "raw function signature" only works for exact matches (which are inconvenient to get right and hard to maintain, see boost spirit semantic action parameters).

So to make any callable object (your polymorphic lambda is such a thing) into a Phoenix actor, use phoenix::bind. I personally like to use phoenix:function<> to wrap my callable objects.

I have many examples of that, but see e.g. boost spirit semantic action using non-void function objects

sehe
  • 374,641
  • 47
  • 450
  • 633
  • 1
    to hit this assertation you need `parse` call or assign the parser to a rule https://wandbox.org/permlink/eiM6zDfyzuapcQtB – Nikita Kniazev Jan 28 '19 at 19:52
  • @NikitaKniazev Thanks. Actual assertation is raised when `parse` is called. I've edited the post. – Inbae Jeong Jan 28 '19 at 21:31
  • @NikitaKniazev I'm aware of that, thanks anyways. In the future, you could add it to the question, I think – sehe Jan 28 '19 at 22:34