我正在使用Boost Spirit解析一个非常复杂的语法,我遇到的问题是一个变种有20多种类型(21这里):
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无法识别使用push_back添加的最后一个类型(eddic :: ast :: New)。当我解析具有此元素的内容时,它会因此错误而失败:
eddic:/usr/include/boost/variant/detail/visitation_impl.hpp:264: typename Visitor :: result_type boost :: detail :: variant :: visitation_impl(int,int,Visitor&amp;,VoidPtrCV, mpl _ :: false_,NoBackupFlag,其中*,step0 *)[with which = MPL _ :: int_℃,取代; step0 = 提高::详细::变种:: visitation_impl_step, 提高:: 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, 提高:: MPL :: v_item, 提高:: MPL :: v_item, 提高:: MPL :: v_item, 提高:: MPL :: v_item, 0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>。 , 0&gt;,0&gt;,0&gt;,0&gt;,0l&gt;, 提高:: MPL :: v_iter, 提高:: 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, 提高:: MPL :: v_item, 提高:: MPL :: v_item, 提高:: MPL :: v_item, 提高:: MPL :: v_item, 0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>。 , 0&gt;,0&gt;,0&gt;,0&gt;,21l&gt;取代;访客= boost :: variant,boost :: mpl :: vector, eddic :: AST ::递延, eddic :: ast :: Deferred,eddic :: ast :: Null, eddic :: ast :: True,eddic :: ast :: False, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: ast :: Deferred&gt;,0&gt; &gt;中 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_, 升压::详细::变体:: void_&GT; ::分配器; VoidPtrCV = const void *; NoBackupFlag = boost :: variant,boost :: mpl :: vector, eddic :: AST ::递延, eddic :: ast :: Deferred,eddic :: ast :: Null, eddic :: ast :: True,eddic :: ast :: False, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: AST ::递延, eddic :: ast :: Deferred&gt;,0&gt; &gt;中 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_, 升压::详细::变体:: void_&GT; :: has_fallback_type_;类型名 Visitor :: result_type = void; mpl _ :: false_ = mpl _ :: bool_]: 断言`!“Boost.Variant内部错误:'哪个'超出范围。” 失败。
如果我交换两个元素(例如Ternary和New),则可以正确识别New,但不能识别Ternary。它只是失败的最后一个元素。
我已经尝试过使用push_front或vector21,但它不会改变任何东西,它总是最后一个有问题的元素。在我看来,它来自于Spirit在将其复制到我的variant_over类型之前在内部使用变量的事实。
这个问题有解决方法吗?
我可能会把数字减少到20,但问题是我将来肯定会有更多。
非常感谢任何想法
答案 0 :(得分:4)
将BOOST_MPL_LIMIT_VECTOR_SIZE
定义为您想要的任何新限制,但是这么高,通常会暗示设计问题,因此可能值得考虑一下。