boostspirit:内置终端应该使用什么类型名称?
我正在重构一个使用 Spirit 进行字符串序列化的打字系统(类型模型)。我正在使用类型特征的编译时建模构造。
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 全局定义。
我的问题:如何输入规则、语法、原始解析器?
注意:我已经开始致力于为我的所有“类型”提供一个封装规则的函子,然后将其设为类型特征。
I am refactoring a typing system (type model) I have in place that uses spirit for string-serialization. I am using the compile-time modeling construct of type-traits.
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 put in rules as well.
The int4 type works, but that 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> >
{};
}
the string typedef doesn't work, and neither does eps. I couldn't figure out the why's of refering to the string 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; } \
/***/
Which means I can't typedef it, it is a proto terminal construct, or put opaquely, a const global definition.
My question : How do I typedef a rule, grammar, primitive parser ?
Note : I have already started working on giving all my "types" a functor encapsulating a rule and then making that a type trait.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定它在所有情况下都有效,但我对我的 Skipper 所做的 typedef 是使用 BOOST_TYPEOF :
所以你的例子是 可能
有更好/更优雅的方法,但它目前可以满足我的需要。
I'm not sure it will work in all case but what I did to typedef my Skipper was to use BOOST_TYPEOF :
so your example would be
There is probably a better / more elegant way but it currently work for what I needed it.