我有以下输入123, test, test456,我想运行一个boost::qi语法,以便输出是一个对向量,其中每个匹配都与某种信息相关联,比如:[(123, Int), (test, String), (test456, String)]
到目前为止,我一直在尝试这样做:
enum class MatchType
{
Int,
String
}在语法里
match = qi::alpha >> *(qi::alnum)[/*How to set the tuple to (matched value _1, string)*/]
| +qi::digit[ /*How to set the tuple to (matched value _1, Int)*/ ]
/* Tied but doesn't compile:
+qi::digit[
[]()
{
phoenix::at_c<0>(_val) = _1;
phoenix::at_c<1>(_val) = MatchType::Int;
}]
*/
qi::rule<Iterator, std::vector<std::pair<MatchType, std::string>>> match;实现这一目标的最佳途径是什么?
发布于 2016-03-06 12:54:08
我只是建议
#include <boost/fusion/adapted/std_pair.hpp>以及以后的
my_pair = (qi::attr(MatchType::Int) >> qi::int_)
| (qi::attr(MatchType::String) >> +qi::alnum);https://stackoverflow.com/questions/35825138
复制相似问题