我在 Classic Spirit 中有以下代码:
/// _BasicRules.h
template <typename scanT> class _BasicRules {
public:
_BasicRules() {
// ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
ALPHA = range_p(0x41, 0x5A) | range_p(0x61, 0x7A);
...
}
protected:
boost::spirit::rule<scanT> ALPHA;
...
};
// CommonRules.h
template <typename scanT> class _CommonRules : public _BasicRules<scanT> {...};
// _UriRules.h
template <typename scanT> class _UriRules : public _CommonRules<scanT> {...};
// _HeaderRules.h
template <class scanT> class _HeaderRules : public _UriRules<scanT> {...};
// _SipRules.h
template <typename scanT> class SipGrammar::definition : public _HeaderRules<scanT> {
public:
definition(SipGrammar const& self) {
SIP_message = Request | Response;
Request = Request_Line >> *(message_header) >> CRLF >> !message_body;
...
}
const rule<scanT> & start() const
{
return SIP_message;
}
private:
boost::spirit::rule<scanT> SIP_message;
using _BasicRules<scanT>::DIGIT;
using _CommonRules<scanT>::token;
...
};
我只是将基于 RFC3261 的 SIP 消息解析器从 Spirit Classic 转换为新的 Spirit 2.5.2。我将整个语法拆分为多个继承文件,因为语法非常庞大。
我正在写这段代码;
....
template <typename Iterator> struct _HeaderRules:grammar<Iterator>, _UriRules<Iterator> {...}
template <typename Iterator> struct SipGrammar:grammar<Iterator>, _HeaderRules<Iterator> {
SipGrammar():SipGrammar::base_type(SIP_Message){...}
...
};
这不起作用。您能否建议在 Spirit 2.5.2 中分层拆分语法的来源。