Ticket #6402: minimallazy.cpp

File minimallazy.cpp, 1.2 KB (added by sairony@…, 11 years ago)

Minimal test case for short comings of passing arguments to rules evaluated with lazy()

Line 
1#undef qword
2#include "boost/spirit/home/qi.hpp"
3#include "boost/spirit/home/phoenix.hpp"
4#include "boost/type_traits.hpp"
5
6namespace qi = boost::spirit::qi;
7namespace ascii = boost::spirit::ascii;
8namespace phoenix = boost::phoenix;
9
10template< typename Iterator >
11struct foo : public qi::grammar< Iterator, void(), ascii::space_type >
12{
13 typedef qi::symbols< char, qi::rule< Iterator, void( const int& ), ascii::space_type >* > SymbolsType;
14 foo() : foo::base_type( "FooGrammar" )
15 {
16 m_Symbols.add( "bar", new typename boost::remove_pointer< typename SymbolsType::value_type >::type( qi::int_( qi::_r1 ) ) );
17 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
18 m_Root %= m_NabialekTrick( 1 );
19 }
20 SymbolsType m_Symbols;
21 typename foo::start_type m_Root;
22 qi::rule< Iterator, void( const int& ), qi::locals< typename SymbolsType::value_type >, ascii::space_type > m_NabialekTrick;
23};
24
25int main()
26{
27 foo< std::string::iterator > inst;
28 std::string src("humbug");
29 qi::phrase_parse( src.begin(), src.end(), inst, ascii::space );
30}