我如何使用ASCII队长::空间不跳过停产? [英] How can I use the skipper ascii::space WITHOUT skipping eol?
问题描述
我要使用的boost ::精神解析,我想用phrase_parse功能:
I have to use boost::spirit for parsing, and I want use phrase_parse function :
qi::phrase_parse(str.begin(), str.end(), grammar, ascii::space - qi::eol);
但第四项(ASCII ::空间 - 齐:: EOL),我的心不是编译器允许。
我如何使用ASCII队长::空间不跳过EOL?
But the fourth term (ascii::space - qi::eol), isnt allowed by my compiler. How can I use the skipper ascii::space WITHOUT skipping eol ?
推荐答案
最简单的答案是
qi::phrase_parse(str.begin(), str.end(), grammar, ascii::blank);
当然,这取决于你的语法太:如果希望您可能需要更改特定的船长类。 请参阅下面的的通用的方式来处理(虽然你可以只指定齐:: blank_type
的语法是应该只接受齐::空白
)。
Of course, it depends on your grammar too: if it expects a specific skipper class you might need to change that. See below for a generic way to handle that (although you could just specify qi::blank_type
for a Grammar that should only accept qi::blank
).
样品处理任意船长了。
The sample handles arbitrary skippers too.
精神都有影响使用船长的几个指令:
Spirit has several directives that influence the use of skippers:
-
<一个href=\"http://www.boost.org/doc/libs/1_48_0/libs/spirit/doc/html/spirit/qi/reference/directive/lexeme.html\"><$c$c>qi::lexeme$c$c>
将解析子前pression无论船长(在文法例如字符串有用)
will parse the sub-expression regardless of skipper (useful for e.g. string literals in a grammar)
<一个href=\"http://www.boost.org/doc/libs/1_48_0/libs/spirit/doc/html/spirit/qi/reference/directive/raw.html\"><$c$c>qi::raw$c$c>
将返回原始源迭代范围,即跳过的输入将被包括在结果的意思
will return the raw source iterator range, meaning that skipped input will be included in the result
<一个href=\"http://www.boost.org/doc/libs/1_48_0/libs/spirit/doc/html/spirit/qi/reference/directive/no_skip.html\"><$c$c>qi::no_skip$c$c>, <一href=\"http://www.boost.org/doc/libs/1_48_0/libs/spirit/doc/html/spirit/qi/reference/directive/skip.html\"><$c$c>qi::skip$c$c>
可以用来明确地更改用于SUBEX pression队长的类型
can be used to explicitely change the type of skipper used for the subexpression
升压灵网站有关于这样的事情一个很好的文章
The Boost Spirit site has a nice article about things like this
- Parsing Skippers and Skipping Parsers
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
template <typename It, typename Skipper>
struct parser : qi::grammar<It, Skipper>
{
parser() : parser::base_type(start)
{
start = *qi::int_;
}
private:
qi::rule<It, Skipper> start;
};
template <typename C, typename Skipper>
void doParse(const C& input, const Skipper& skipper)
{
auto f(std::begin(input)), l(std::end(input));
parser<decltype(f), Skipper> p;
bool ok = qi::phrase_parse(f,l,p,skipper);
if (ok)
std::cout << "parse success\n";
}
int main()
{
const std::string input = "1 2 3 4";
doParse(input, qi::blank);
doParse(input, qi::space);
doParse(input, ~qi::char_("0-9"));
}
这篇关于我如何使用ASCII队长::空间不跳过停产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!