Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ spirit-从随机放置的条目解析AST样式_C++_Boost Spirit - Fatal编程技术网

C++ spirit-从随机放置的条目解析AST样式

C++ spirit-从随机放置的条目解析AST样式,c++,boost-spirit,C++,Boost Spirit,我的文件中有以下数据: #TITLE:Destiny; #SUBTITLE:; #ARTIST:Smiley; #BACKGROUND:bg.png; #SAMPLESTART:43.960; #SAMPLELENGTH:12.000; 我想使用AST将其解析为如下结构: struct data { std::string title, subtitle, artist, background; double samplestart, samplelength; }; struc

我的文件中有以下数据:

#TITLE:Destiny;
#SUBTITLE:;
#ARTIST:Smiley;
#BACKGROUND:bg.png;
#SAMPLESTART:43.960;
#SAMPLELENGTH:12.000;
我想使用AST将其解析为如下结构:

struct data {
   std::string title, subtitle, artist, background;
   double samplestart, samplelength;
};
struct prs : qi::symbols< char, qi::parser<...> > {
   prs() {
     add
       ("TITLE", link_to_some_str_parser)
       ("SAMPLESTART", link_to_some_dbl_parser);
   }
};
注意:文件中的条目可能以任何顺序出现

我在想这样的事情:

struct data {
   std::string title, subtitle, artist, background;
   double samplestart, samplelength;
};
struct prs : qi::symbols< char, qi::parser<...> > {
   prs() {
     add
       ("TITLE", link_to_some_str_parser)
       ("SAMPLESTART", link_to_some_dbl_parser);
   }
};
struct-prs:qi::symbols{
prs(){
添加
(“标题”,链接到某个语法分析器)
(“SAMPLESTART”,链接到某个dbl解析器);
}
};
然后在运行时使用它找到正确的解析器,可能使用[]语法将解析结果存储到某个变量中

现在是主要问题。这会编译吗?qi::符号可以这样使用吗?这有什么意义吗? 否则你会怎么做

谢谢!
Alex

我建议使用置换解析器(请参阅),它允许在任何序列中匹配一组备选方案。

为什么您认为它不适用于AST?它应该可以正常工作。我看不到任何方法可以将无序条目与AST和我的结构一起使用。我错过什么了吗?感谢如果您调整结构(使用BOOST\u FUSION\u adapt\u struct),它将由置换解析器填充。结构自适应中的元素序列必须与置换解析器中的组件序列相匹配。这非常有趣。我试试看。谢谢