when I try to compile the following code, I get a compilation failure (error C2903: "apply": the character is neither a class template nor a function template ...) when token_list> 10 tokens.
The code compiles and parses correctly when tokens <= 10. Is there a limit on the 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 to parse\n"; std::cout<<"Type [q or Q] to quit\n\n"; std::string str; while (getline(std::cin, str)){ if (str.empty() || str[0] == 'q' || str[0] == 'Q') break; It first = str.begin(); It 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"); }
source share