开发者

boost::spirit - parsing AST style from randomly placed entries

I have this data in my file:

#TITLE:Destiny;
#SUBTITLE:;
#ARTIST:Smiley;
#BACKGROUND:bg.png;
#SAMPLESTART:43.960;
#SAMPLELENGTH:12.000;

I want to parse it using AST into a structure like this:

struct data {
   std::string title, subtitle, artist, background;
   double samplestart, samplelength;
};

Note: the entries in the file may appear in any order.

I was thinking about something like this:

struct prs : qi::symbol开发者_StackOverflow中文版s< char, qi::parser<...> > {
   prs() {
     add
       ("TITLE", link_to_some_str_parser)
       ("SAMPLESTART", link_to_some_dbl_parser);
   }
};

And then use it to get to the correct parser in runtime probably using the [] syntax to store the parsed result into some variable.

Now the main question. Would this even compile? Can qi::symbols be used that way and does that make any sense? How would you do it otherwise?

Thanks! Alex


I'd suggest to utilize the permutation parser (see here), which allows to match a bunch of alternatives in any sequence.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜