#undef qword #include "boost/spirit/home/qi.hpp" #include "boost/spirit/home/phoenix.hpp" #include "boost/type_traits.hpp" namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; namespace phoenix = boost::phoenix; template< typename Iterator > struct foo : public qi::grammar< Iterator, void(), ascii::space_type > { typedef qi::symbols< char, qi::rule< Iterator, void( const int& ), ascii::space_type >* > SymbolsType; foo() : foo::base_type( "FooGrammar" ) { m_Symbols.add( "bar", new typename boost::remove_pointer< typename SymbolsType::value_type >::type( qi::int_( qi::_r1 ) ) ); m_NabialekTrick %= m_Symbols[ qi::_a = qi::_1 ] >> boost::spirit::lazy( *qi::_a )( qi::_r1 ); // Can't pass qi::_r1 to the rule due to lazy( *SymbolsType::value_type ) != *SymbolsType::value_type m_Root %= m_NabialekTrick( 1 ); } SymbolsType m_Symbols; typename foo::start_type m_Root; qi::rule< Iterator, void( const int& ), qi::locals< typename SymbolsType::value_type >, ascii::space_type > m_NabialekTrick; }; int main() { foo< std::string::iterator > inst; std::string src("humbug"); qi::phrase_parse( src.begin(), src.end(), inst, ascii::space ); }