文字列のシリアル化に精神を使用する型付けシステム (型モデル) をリファクタリングしています。型特性のコンパイル時モデリング構造を使用しています。
template<>
type_traits<int4_type>
{
typedef boost::spirit::qi::int_parser<boost::int32_t> string_parser;
}
template<>
type_traits<string_type>
{
typedef boost::spirit::ascii::string string_parser;
}
この例では基本的なパーサーを示していますが、ルールも含めることを期待しています。
int4 型は機能しますが、これは (home/qi/numeric/int.hpp +27) が原因です。
namespace tag
{
template <typename T, unsigned Radix, unsigned MinDigits
, int MaxDigits>
struct int_parser {};
}
namespace qi
{
///////////////////////////////////////////////////////////////////////
// This one is the class that the user can instantiate directly in
// order to create a customized int parser
template <typename T = int, unsigned Radix = 10, unsigned MinDigits = 1
, int MaxDigits = -1>
struct int_parser
: spirit::terminal<tag::int_parser<T, Radix, MinDigits, MaxDigits> >
{};
}
文字列 typedef は機能せず、eps も機能しません。文字列パーサーを参照する理由がわかりませんでした。ただし、eps の場合は次のようになります。
#define BOOST_SPIRIT_TERMINAL(name) \
namespace tag { struct name {}; } \
typedef boost::proto::terminal<tag::name>::type name##_type; \
name##_type const name = {{}}; \
inline void silence_unused_warnings__##name() { (void) name; } \
/***/
これは、typedef できないことを意味します。これは、プロト ターミナル コンストラクトであるか、不透明に言えば、const グローバル定義です。
私の質問:ルール、文法、プリミティブパーサーをどのように型定義しますか?
注:私はすでに、すべての「型」にルールをカプセル化するファンクターを与え、それを型特性にする作業を開始しています。