精神语法不会编译:函数模板参数错误?
Spirit grammar won't compile: function template argument error?
编译这种简单的精神语法会导致似乎是一个错误(尽管有巨大的错误消息),这可能与我的船长或我错误使用过的其他模板参数有关。
我对语法和开始规则进行了多种属性定义,但对错误没有影响。
#include <string>
#include "/usr/local/boost/include/boost/spirit/include/qi.hpp"
#include "/usr/local/boost/include/boost/spirit/include/qi_symbols.hpp"
using std::string;
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
boost::spirit::qi::rule<string::const_iterator>
skipper_rule = qi::space | '#' >> *(qi::char_ - qi::eol) >> qi::eol;
typedef BOOST_TYPEOF(skipper_rule) skipper_T;
template <typename Iterator, typename Skipper>
class Grammar1 : boost::spirit::qi::grammar<Iterator, Skipper>
{
public:
typedef boost::spirit::qi::rule<Iterator, Skipper> rule_nil_T;
typedef boost::spirit::qi::rule<Iterator, string()> rule_str_T;
rule_nil_T under = qi::char_('_');
rule_nil_T dot = qi::char_('.');
rule_nil_T star = qi::char_('*');
rule_str_T file_name_star = qi::lexeme [ (qi::alpha | under) >> *(qi::alnum | under) >> dot >> star ];
rule_nil_T start = +file_name_star;
Grammar1(void) : Grammar1::base_type(start) { };
~Grammar1(void) { };
void parseInputFile(Iterator itr, Iterator itr_end)
{
bool b;
bool r = phrase_parse(itr, itr_end, start, skipper_rule);
if (r && itr == itr_end)
{
std::cout << "Parsing succeededn";
} else
{
string rest(itr, itr_end);
std::cout << "stopped at: ": " << rest << ""n";
}
}
};
int main(int argc, char **argv)
{
Grammar1<string::const_iterator, skipper_T> g;
string input("input1.* input2.*");
g.parseInputFile(input.cbegin(), input.cend());
}
错误消息的重要部分似乎是:
/usr/local/boost/include/boost/spirit/home/qi/nonterminal/rule.hpp:304:17:
error: no match for call to ‘(const function_type *REMOVED*)’
if (f(first, last, context, skipper))
^
上述精神文件中的第304行的评论指出我可能正在使用不兼容的船长,但是我尝试了更简单的ASCII :: SPACE_TYPE船长,无济于事。
错误消息的其余部分:
usr/local/boost/include/boost/function/function_template.hpp:1048:7: note:
candidate is:
class function<BOOST_FUNCTION_PARTIAL_SPEC>
^
/usr/local/boost/include/boost/function/function_template.hpp:758:17: note:
boost::function4<R, T1, T2, T3, T4>:: *REMOVED*
result_type operator()(BOOST_FUNCTION_PARMS) const
^
/usr/local/boost/include/boost/function/function_template.hpp:758:17: note:
no known conversion for argument 4 from ‘const
boost::spirit::unused_type’ to ‘const boost::spirit::qi::reference<const
boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*,
std::basic_string<char> > > >&’
知道我在做什么错吗?我的编译器是GCC 4.8.5。
您正在尝试使用 rule_nil_T
规则,该规则在 rule_str_T
规则中没有船长。出于内部原因,精神只能在呼叫规则时失去船长。可以通过在使用站点中内置under
,dot
和star
来轻松解决该问题。
注意: QI中的规则调用开销。为这样简单的解析器创建规则,然后在重复解析器中使用它不是一个好主意。
提示:您可以使用raw
指令,并在其中使用文字解析器,以使更多的性能和清洁器看起来更加清洁以看起来像解析器。考虑一下: qi::lexeme[qi::raw[(qi::alpha | '_') >> qi::alnum % '.'] >> ".*"]
。
相关文章:
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 是否可以获取成员函数模板参数的拥有对象?
- 如何防止用户指定函数模板参数,迫使其进行推导
- 使用用户定义的转换运算符推导函数模板参数
- 构造函数模板参数推导,其中 std::function 作为参数
- 在简单地移动参数时使用函数模板参数的优点
- 使用函数模板参数作为类模板参数?
- 函数模板参数推断使用 std::Optional 失败
- 函数模板参数包问题
- 尝试将 C++11 代码转换为 C++03 时默认函数模板参数出错
- 是否可以从指向成员函数模板参数的指针推断类类型
- 精神语法不会编译:函数模板参数错误?
- 从函数模板参数中自动推论对容器的元素类型
- 函数模板参数推导和继承
- 有人能解释一下特殊的std::函数模板参数列表语法(这个奇怪的类型(Types..))吗
- 成员函数模板参数的部分专业化
- std::函数模板参数解析
- 'Incomplete type' 为标准::函数声明指向成员的指针函数模板参数时出错
- 具有指针数据类型的非类型函数模板参数
- 从模板参数类型中推导函数模板参数