#include <iostream>
#include <boost/spirit/core.hpp>

using namespace boost::spirit;

namespace boost { namespace spirit
{
    template <typename RHS>
    struct sub_grammar : parser<sub_grammar<RHS> >
    {
        typedef sub_grammar     self_t;
        typedef self_t const&   embed_t;

        template <typename ScannerT>
        struct result
        {
            typedef typename parser_result<RHS, ScannerT>::type type;
        };

        sub_grammar(RHS const& rhs_)
        : rhs(rhs_) {}

        template <typename ScannerT>
        typename parser_result<self_t, ScannerT>::type
        parse(ScannerT const& scan) const
        { return rhs.parse(scan); }

        RHS rhs;
    };
}}

#define DEFINITION                                                              \
    space_p                                                                     \
    |   "//" >> *(anychar_p - '\n') >> '\n'     /* C++ comment */               \
    |   "/*" >> *(anychar_p - "*/") >> "*/"     /* C comment  */                \
    |   "#line" >> *(anychar_p - '\n') >> '\n'  /* added for correctly */       \
                                                /* handling preprocessed */     \
    |   "#pragma" >> *(anychar_p - '\n') >> '\n'/* files from Intel V5.0.1 */   \
                                                /* on W2K */                    \

#ifdef __MWERKS__
#define typeof __typeof__
#endif

typedef typeof(DEFINITION) rhs_t;

int
main()
{
    sub_grammar<rhs_t> g = DEFINITION;

    bool success = parse(
        "/*this is a comment*/\n//this is a c++ comment\n\n",
        *g).full;
    assert(success);
    std::cout << "SUCCESS!!!\n";
    return 0;
}
