c++ - boost::spirit compile error when lexer tokens > 10 -
when try , compile following code compile fail (error c2903: 'apply' : symbol neither class template nor function template ...) when token_list > 10 tokens.
the code compiles , parses correctly when tokens <= 10. there limit number of tokens ?
#define boost_variant_minimize_size #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/lex_lexertl.hpp> #include <iostream> #include <string> namespace qi = boost::spirit::qi; namespace lex = boost::spirit::lex; template <typename lexer> struct token_list : lex::lexer<lexer> { token_list() { cs1 = "tok1"; cs2 = "tok2"; cs3 = "tok3"; cs4 = "tok4"; cs5 = "tok5"; cs6 = "tok6"; cs7 = "tok7"; cs8 = "tok8"; cs9 = "tok9"; cs10 = "tok10"; cs11 = "tok11"; this->self.add (cs1) (cs2) (cs3) (cs4) (cs5) (cs6) (cs7) (cs8) (cs9) (cs10) (cs11); } lex::token_def<std::string> cs1, cs2, cs3, cs4, cs5, cs6, cs7, cs8, cs9, cs10, cs11; }; template <typename iterator> struct grammar : qi::grammar<iterator> { template <typename tokendef> grammar(tokendef const& tok) : grammar::base_type(call_setup) { call_setup = tok.cs1>>tok.cs2>>tok.cs3>>tok.cs4>>tok.cs5>> tok.cs6>>tok.cs7>>tok.cs8>>-tok.cs9>>tok.cs10>> tok.cs11; } qi::rule<iterator> call_setup; }; int main() { typedef std::string::const_iterator it; typedef lex::lexertl::token<it, boost::mpl::vector<std::string>> token_type; typedef lex::lexertl::lexer<token_type> lexer_type; typedef token_list<lexer_type>::iterator_type iterator_type; token_list<lexer_type> call_setup; grammar<iterator_type> g(call_setup); std::cout<<"enter string parse\n"; std::cout<<"type [q or q] quit\n\n"; std::string str; while (getline(std::cin, str)){ if (str.empty() || str[0] == 'q' || str[0] == 'q') break; first = str.begin(); last = str.end(); bool r = lex::tokenize_and_parse(first, last, call_setup, g); if (r) { std::cout << "parsing passed"<< "\n"; } else { std::string rest(first, last); std::cerr << "parsing failed\n" << "stopped at: \"" << rest << "\"\n"; } } system("pause"); }
the rule call_setup
stores sequence in case , boost fusion vector. default max length of thing 10.
you increase putting #define fusion_max_vector_size 20
@ beginning of code. compiles without problems.
Comments
Post a Comment