bit level matching on x3

Takatoshi Kondo <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <CA+SaqLEqcUBbHpOeNJ6rdimMnnjs3ccbJOSXmDknXgQ-BVhJ0w@mail.gmail.com>
Hello,

I'm trying to write bit level matching on SpiritX3.
For example, all of upper 4 bits is 1.

Here is the code:

http://melpon.org/wandbox/permlink/YzhZUNnHWPGQyPUs

#include <boost/config/warning_disable.hpp>
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/binary.hpp>

#include <iostream>

namespace x3 = boost::spirit::x3;

int main() {
    using x3::byte_;

    // input data
    std::string s = {
        char(0b11110000), // match
        char(0b11110001), // not match
        char(0b11110011)  // not match
    };

    // rule
    auto match = +byte_(0b11110000);
    // auto match = +byte_(0b11110000, 0b11111111); // no range
version like char_

    auto it = s.begin();
    auto end = s.end();
    bool r = x3::phrase_parse(
        it, end,
        match, x3::space);

    std::cout << std::boolalpha << r << std::endl;
    std::cout << std::distance(it, end) << " bytes remaining." << std::endl;
}

Unlike char_, byte_ doesn't have range version interface.
The example above uses the rule exact matching to 0b11110000. So the
first byte of the input string is matched, but continuing two byte
doesn't match.

Is there any good way to do that?

I guess that something like byte wise pre-match processing...

---
Thanks,
Takatoshi Kondo

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.