4

当我尝试编译以下代码时,当 token_list > 10 个标记时,我得到一个编译失败(错误 C2903:'apply':符号既不是类模板也不是函数模板......)。

当标记 <= 10 时,代码可以正确编译和解析。标记的数量是否有限制?

#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");
}
4

1 回答 1

4

该规则call_setup在您的情况下存储一个序列,这是一个提升融合向量。默认情况下,该事物的最大长度为 10。

您可以通过将其放在#define FUSION_MAX_VECTOR_SIZE 20代码的开头来增加它。然后它编译没有问题。

于 2013-08-08T12:32:39.020 回答