如何将Boost Spirit与超过20种类型的变体一起使用? [英] How to use Boost Spirit with variant with more than 20 types?

查看:100
本文介绍了如何将Boost Spirit与超过20种类型的变体一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Boost Spirit解析一个非常复杂的语法,而我遇到的是一个具有20多种类型(此处为21种)的变体的问题:

I'm parsing a quite complex grammar with Boost Spirit and I'm facing a problem with a variant that have more than 20 types (21 here):

namespace eddic { namespace ast {

typedef boost::mpl::vector<
            Integer,
            IntegerSuffix,
            Float,
            Litteral,
            VariableValue,
            DereferenceValue,
            Expression,
            Unary,
            Null,
            True,
            False,
            ArrayValue,
            FunctionCall,
            MemberFunctionCall,
            Cast,
            BuiltinOperator,
            Assignment,
            SuffixOperation,
            PrefixOperation,
            Ternary
        > types_initial;

typedef boost::mpl::push_back<types_initial, New>::type types;
typedef boost::make_variant_over<types>::type Value;

}}

Boost Spirit无法识别最后一种类型(eddic: :ast :: New)添加了push_back。当我解析具有此元素的内容时,它将失败并显示以下错误:

Boost Spirit does not recognize the last type (eddic::ast::New) added with push_back. When I parse something that have this element, it fails with this error:


eddic:/ usr / include / boost / variant / detail / visitation_impl.hpp:264:
类型名Visitor :: result_type
boost :: detail :: variant :: visitation_impl(int,int,Visitor& ;, VoidPtrCV,
mpl _ :: false_,NoBackupFlag,其中*,step0 *)[其中哪个=
mpl _ :: int_< 0>; step0 =
boost :: detail :: variant :: visitation_impl_step,
boost :: mpl :: v_item,
boost :: mpl :: v_item,
boost :: mpl: :v_item,
boost :: mpl :: v_item,
boost :: mpl :: v_item,
boost :: mpl :: v_item,
boost :: mpl :: v_item ,
boost :: mpl :: v_item,
boost :: mpl :: v_item,
boost :: mpl :: v_item,
boost :: mpl :: v_item,
boost :: mpl :: v_item,
boost :: mpl :: v_item,
0>,0>,0>,0>,0>,0>,0>,0> ,0>,0>,0>,0>,0>,0>,0>,0>,0>,
0>,0>,0>,0>,0l>,
boost :: mpl :: v_iter,
boost :: mpl :: v_item,
boost :: mpl :: v_item,
boost :: mpl :: v_item,
boost :: mpl :: v_item,
提升:: mpl :: v_item,
提升:: mpl :: v_item,
提升:: mpl :: v_item,
提升:: mpl :: v_item,
提升:: mpl :: v_item,
提升:: mpl :: v_item,
提升:: mpl :: v_item,
提升:: mpl: :v_item,
boost :: mpl :: v_item,
0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0 >,0>,0>,0>,0>,0>,0>,
0>,0>,0>,0>,21l>>;访客=
boost :: variant,boost :: mpl :: vector,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,eddic :: ast :: Null ,
eddic :: ast :: True,eddic :: ast :: False,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred>,0>>,
boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void_ ,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,
boost :: detail :: variant: :void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,
boost :: detail ::变种::: void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void _> :: assigner; VoidPtrCV = const void *;
NoBackupFlag =
boost :: variant,boost :: mpl :: vector,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,eddic :: ast :: Null,
eddic :: ast :: True,eddic :: ast :: False,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred,
eddic :: ast :: Deferred>,0>>,
boost :: detail :: variant: :void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,
boost :: detail ::变种::: void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,
boost: :detail :: variant :: void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void_,boost :: detail :: variant :: v oid_,
boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,
boost :: detail :: variant :: void _> :: has_fallback_type_; typename
Visitor :: result_type = void; mpl _ :: false_ = mpl _ :: bool_]:
断言`! Boost.Variant内部错误:超出范围。'
失败。

eddic: /usr/include/boost/variant/detail/visitation_impl.hpp:264: typename Visitor::result_type boost::detail::variant::visitation_impl(int, int, Visitor&, VoidPtrCV, mpl_::false_, NoBackupFlag, Which*, step0*) [with Which = mpl_::int_<0>; step0 = boost::detail::variant::visitation_impl_step, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0l>, boost::mpl::v_iter, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, boost::mpl::v_item, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 0>, 21l> >; Visitor = boost::variant, boost::mpl::vector, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Null, eddic::ast::True, eddic::ast::False, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred >, 0> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>::assigner; VoidPtrCV = const void*; NoBackupFlag = boost::variant, boost::mpl::vector, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Null, eddic::ast::True, eddic::ast::False, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred, eddic::ast::Deferred >, 0> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>::has_fallback_type_; typename Visitor::result_type = void; mpl_::false_ = mpl_::bool_]: Assertion `!"Boost.Variant internal error: 'which' out of range."' failed.

如果我交换两个元素(例如Ternary和New),则New会被正确识别,但Ternary不会被识别。它只是最后一个失败的元素。

If I swap two elements (Ternary and New for example), New is correctly recognized, but not Ternary. It is only the last element that fails.

我已经尝试过使用push_front或vector21,但是它并没有改变任何东西,它始终是有问题的最后一个元素。我认为这是因为Spirit在将变量复制到我的variant_over类型之前在内部使用了一个变量。

I already tried using push_front or vector21, but it doesn't change anything, it's always the last element that have problem. In my opinion it comes from the fact that Spirit uses a variant internally before copying it to my variant_over type.

是否有解决此问题的方法?

Is there a workaround to this problem ?

我可以将数字减少到20,但是问题是,将来我肯定会拥有更多。

I could probably reduce the number to 20, but the problem is that I will certainly have more than that in the future.

非常感谢任何想法

推荐答案

定义 BOOST_MPL_LIMIT_VECTOR_SIZE 达到您想要的任何新限制,但过高通常表示存在设计问题,因此可能值得考虑。

Define BOOST_MPL_LIMIT_VECTOR_SIZE to whatever new limit you want, but going this high is usually a hint at design problems so it might be worth to give it some consideration.

这篇关于如何将Boost Spirit与超过20种类型的变体一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆