I am refactoring the input system (model type) that I use, uses the spirit for string serialization. I use the type-time compile-time simulation construct.
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; }
In this example, I show primitive parsers, but I expect to introduce rules as well.
The int4 type works, but this is because of (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 string does not work and does not eps. I could not understand why referring to the line parser. However, in the case of eps, it boils down to:
#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; } \ /***/
This means that I cannot typedef it, it is a proto-terminal constructor or an opaque global definition of const.
My question is: how do I type a rule, grammar, primitive parser?
Note. I have already begun work on providing all of my βtypesβ with a functor that encapsulates a rule and then creates a type trait.