I have been successfully using boost::spirit::qi
to to parse a stream consisting of the built-in parsers (e.g. byte_
, little_word
, etc). However, I now need to parse data that doesn't neatly fall into one of these categories. For example, I would like to convert a 16.16 fixed-point binary number into a double; e.g. so little_word << little_16p16
would parse a uint16_t
followed by a double
(parses from a fixed-point number).
I first considered semantic actions, but (I think...) that they are not appropriate because they do not change the type of the attribute associated with a parser. I also cannot figure out how to adapt the employee struct-parsing example to this situation because it relies on implicit casts provided by boost::fusion
. That approach won't work here because I obviously can't define an implicit cast from uint32_t
to double
without causing major problems.
My inclination is that I need to add non-terminals to wrap the built-in binary primitive parsers or write a terminal parser from scratch. Even after looking at the source of qi_binary.hpp
, I am not sure how to do either. Could anyone provide some sample code and/or direct me to the relevant references to get started?