Question

when i try and compile the following code i get a compile fail (error C2903: 'apply' : symbol 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 to 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");
}
Was it helpful?

Solution

The rule call_setup stores a sequence in your case and this is a boost fusion vector. By default the max length of that thing is 10.

You increase it by putting #define FUSION_MAX_VECTOR_SIZE 20 at the beginning of your code. Then it compiles without problems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top