分解精神规则的共同部分 [英] Factoring out common parts of Spirit rules
本文介绍了分解精神规则的共同部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有很多有共同前缀和后缀的规则:
rule = begin_stuff>一些>其他>> stuff>> end_stuff。
(其中 begin_stuff
和 end_stuff
由文字组成)
我想能够说
rule = wrapped(some>> other>> stuff);
我试着沿着
的行 template< typename Rule>规则包装(规则里面)
{
规则结果;
result = begin_stuff>>内部>> end_stuff;
return result;
}
但是我得到的很多来自Qi的编译时断言。 p>
如何以这种方式重构Spirit规则?
解决方案
您需要使用 Qi Confix Parser Derective 来自精神库。这正是你需要的。
I have a lot of rules that have common prefix and suffix:
rule = begin_stuff >> some >> other >> stuff >> end_stuff.
(where begin_stuff
and end_stuff
are composed from literals)
I wanted to be able to say
rule = wrapped(some >> other >> stuff);
I tried something along the lines of
template<typename Rule> Rule wrapped(Rule inside)
{
Rule result;
result = begin_stuff >> inside >> end_stuff;
return result;
}
but all I get is lots of compile-time assertions from Qi.
How can I refactor Spirit rules in this fashion?
解决方案
I think you need to use the Qi Confix Parser Derective from Spirit Repository. It is exactly what you need.
这篇关于分解精神规则的共同部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文