Question

Good time of day!

I wrote this piece of code and expect it being able to be compiled.

#include <string>

#include <boost/spirit/include/qi.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <boost/fusion/include/adapted.hpp>

struct ParsedThunk
{
    typedef boost::variant<std::string, boost::tuple<boost::recursive_wrapper<ParsedThunk>, boost::recursive_wrapper<ParsedThunk> > > ParsedThunkEntity;
    ParsedThunkEntity _entity;
};

BOOST_FUSION_ADAPT_STRUCT(
    ParsedThunk,
    (ParsedThunk::ParsedThunkEntity, _entity)
)

class ThunkParser
{
protected:
    boost::spirit::qi::rule<std::string::iterator, ParsedThunk(), boost::spirit::ascii::space_type> _thunkRule;

public:
    ThunkParser()
    {
        _thunkRule %= (
            (boost::spirit::qi::lexeme[+(boost::spirit::qi::char_ - boost::spirit::qi::char_(" =()"))]) | 
            (boost::spirit::qi::lit("(") >> _thunkRule >> _thunkRule >> boost::spirit::qi::lit(")")) | 
            (_thunkRule >> _thunkRule)
            ) >> boost::spirit::qi::eps;
    }
};

int main(void)
{
    return 0;
}

But when I compile it with clang or with GCC I get an error. The most interesting part of it is:

/usr/include/boost/variant/detail/initializer.hpp:89:24: note: candidate function not viable: no known conversion from 'const boost::fusion::vector2<ParsedThunk, ParsedThunk>' to 'const
      boost::tuples::tuple<boost::recursive_wrapper<ParsedThunk>, boost::recursive_wrapper<ParsedThunk>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type,
      boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>' for 2nd argument;
            static int initialize(void* dest, param_T operand)

I use clang 3.1 or gcc 4.7 and boost 1.52, but I think it doesn't matter. :)

How should I edit this piece of code to make it be compiled?

UPDATE

Well, I just noticed that the grammar I specified is left-recursive and therefore recursive descend parser may not stop while processing input. May this be a cause of the compilation problem?

Was it helpful?

Solution

Fix your variant type:

typedef boost::variant<
            std::string,
            boost::recursive_wrapper<boost::tuple<ParsedThunk, ParsedThunk> >
        > ParsedThunkEntity;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top