So, I have the following spirit karma rule body:
base_rule =
eps(_r1 != 0) [ // _r1 is a pointer_typed placeholder
eps
]
;
which leads to a rather long error message from g++ which (helpfully) ends with :
/opt/dev_64_swat/Boost/include/boost/spirit/home/phoenix/operator/comparison.hpp
:37:5: error: ISO C++ forbids comparison between pointer and integer
[-fpermissive]
This is valid c++:
struct zebra{};
int main()
{
zebra * x;
if( x == 0);
}
I thought to try boost::phoenix::static_cast_<_r1_type *>(0)
as well as converting _r1_type
to a integer (yes that is WRONG, it was just an experiment).
The question:
How can I use a spirit eps construct to perform a pointer test on a placeholder to prevent rule body evaluation when the point is zero ?
As with all "C++ functional programming library usage" questions I expect the answer to leave me feeling like a dimwit.
The Answer
Ildjam's point directly answers my question. There were two issues with my problem; there is a indirect problem above. And that is to do with conditionals in PEG. What I am trying to express should be written as such:
rule = ( eps(_r) << ( /* grammar for when pointer is not null */ ) )
| eps // otherwise dont do anything.
;
I was using the semantic action body ( specified in a [] block), to express the conditional part of the grammar. Strangely though I have written conditional PEG grammars before, I just made a mistake, which led to the second class of problems.
So, eps(_r1) does the trick, The second type of compilation issue is irrelevant to the question.