提振精神写法令牌值回输入流 [英] Boost spirit lex write token value back to input stream
问题描述
我想知道如果有一个在升压方式::精神::法写一个令牌值回输入流(可能是编辑后),并再次重新扫描。什么我基本上寻找的是一个功能,例如,通过在Flex的unput()提供。
I'm wondering if there's a way in boost::spirit::lex to write a token value back to the input stream (possibly after editing) and rescanning again. What I'm basically looking for is a functionality like that offered by unput() in Flex.
谢谢!
推荐答案
我最终实现我自己的unput()的功能如下:
I ended up implementing my own unput() functionality as follows:
struct unputImpl
{
template <typename Iter1T, typename Iter2T, typename StrT>
struct result {
typedef void type;
};
template <typename Iter1T, typename Iter2T, typename StrT>
typename result<Iter1T, Iter2T, StrT>::type operator()(Iter1T& start, Iter2T& end, StrT str) const {
start -= (str.length() - std::distance(start, end));
std::copy(str.begin(), str.end(), start);
end = start;
}
};
phoenix::function<unputImpl> const unput = unputImpl();
这可以被用来象:
this->self += lex::token_def<lex::omit>("{SYMBOL}\\(")
[
unput(_start, _end, "(" + construct<string>(_start, _end - 1) + " "),
_pass = lex::pass_flags::pass_ignore
];
如果该unputted字符串长度比匹配的令牌长度越大,它会覆盖一些previously解析输入。你需要照顾的事情是要确保输入的字符串已经在开始的时候足够的空的空间来处理情况,unput()被调用的情况下的第一个匹配的令牌。
If the unputted string length is bigger than the matched token length, it will override some of the previously parsed input. The thing you need to take care of is to make sure the input string has sufficient empty space at the very beginning to handle the case where unput() is called for the very first matched token.
这篇关于提振精神写法令牌值回输入流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!