As I mentioned in yesterday's blog post, Boost.Spirit is a completely new topic, and requires a new kind of thinking / looking at it to make it work to our advantage. Today, I believe I'm starting to understand it, at least a bit better. The key is that you can create small, light-weight, in-place parsers with it. For example, parsing an ed2k:// link using Boost.Spirit looks like this:
uint64_t filesize;
std::string filename;
std::string hash;
std::string link("ed2k://|file|slackware.iso|35623456|def4256fba|/");
rule<> parseLink = "ed2k://|file|"
>> *(ch_p[push_back_a(filename)])
>> '|' >> uint_p[assign_a(filesize)]
>> '|' >> *(ch_p[push_back_a(hash)])
>> "|/"
;
parse(link.c_str(), parseLink);
And that's it, the variables contain the contents. Similar "in-place" parses can be created for all kinds of parsing, for example config file, or in current active topic, .torrent file.
Now, some might argue that Spirit is too complex, and the time spent learning it is not worth it, but I disagree - Spirit gives us yet another very valuable tool for current and future tasks. Just as Boost.MultiIndex, Boost.Signals, and many other Boost libraries, which were initially complex to master have now become our daily tools, without which we'd be helpless, will Boost.Spirit be soon enough.
Anyway, the .torrent parser saw progress today, but the parsing stops mid-way in the chunk-hashes for some reason. Also, as I discovered it doesn't handle unrecognized data very well yet; I'm thinking about re-structuring the parser, have the base as recursive parser which just handles the structure (nested dictionaries and lists), and call sub-parsers for actual values extraction.
On other news, however, I have some news on the GUI design topic. Below's a teaser, see
this thread for more information and discussion.
* Notice: this is just an image created in photoshop, it's not a real screenshot :). Also, as you noticed some parts are still borrowed (e.g. the progressbars, some icons) - those will be replaced shortly as well.Madcat, ZzZz