boost spirit 2 : is there a way to know what is the parser progression percentage?

南笙酒味 提交于 2019-12-10 21:22:29

问题


I managed to parse a pgn file into several games mainly thanks to this forum.

However, as the files I have to deal with have so many games, the process can take two minutes on my recent computer. That's why I would like to animate a progress bar on the GUI application using this parser.

I think the easiest way would be to "ask" spirit how many characters he has already processed, and how many characters remain. (Or how many lines remain and have been processed).

Is it possible ? If so, how do I need to modify the parser file in order to get this ratio ?


回答1:


You can use line_pos_iterator and potentially the iter_pos primitive from the repository.

  • (@GuyGreer:) There is no way to know the amount of backtracking involved (otherwise, there would not need to be backtracking in the first place). So, the best thing to do is accept that you get some kind of "average throughput" that can be a little bursty or laggy at times. If your grammar is that unbalanced that these variations are more than noise, you should consider fixing the the grammar/parser definitions in the first place.

  • To counter the "problem" of not knowing the stream length, you cannot fix it other than not having it as a stream.

    I'd suggest memory mapping. You can use the facilities from boost::iostreams, boost::interprocess or just mmap.

I estimate I have at least 3 answers demonstrating each of the techniques mentioned in this answer, so I'd just search this site for them.



来源:https://stackoverflow.com/questions/34211394/boost-spirit-2-is-there-a-way-to-know-what-is-the-parser-progression-percentag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!