title: Using boost::spirit::qi to parse numbers with separators
body: <p>I am attempting to use boost::spirit::qi to do some parsing.  It's actually going quite well, and I successfully have managed to parse numbers in various bases based on a suffix.  Examples: 123, c12h, 777o, 110101b.</p>
  
  <p>I then wanted to add the ability to allow a completely ignored separator character, to allow values like 123_456 or 1101_0011b to parse.  I tried using the skip parser, but I highly suspect that I completely misunderstood how it was to be used.  It compiles just fine, but my attempt to make it ignore the underscore does absolutely nothing at all.  Any suggestions on how to make this do what I want would be appreciated.  My test code is included below:</p>
  
  <pre><code>#include &lt;boost/spirit/include/qi.hpp&gt;
  #include &lt;boost/spirit/include/phoenix.hpp&gt;
  
  namespace qi = boost::spirit::qi;
  namespace ascii = boost::spirit::ascii;
  using qi::_val;
  using qi::_1;
  using qi::skip;
  using qi::uint_parser;
  using ascii::char_;
  
  template &lt;typename Iterator&gt;
  struct unsigned_parser : qi::grammar&lt;Iterator, uint64_t()&gt; {
  
      unsigned_parser() : unsigned_parser::base_type(start) {
          uint_parser&lt;uint64_t, 10&gt; dec_parser;
          uint_parser&lt;uint64_t, 16&gt; hex_parser;
          uint_parser&lt;uint64_t, 8&gt; oct_parser;
          uint_parser&lt;uint64_t, 2&gt; bin_parser;
  
          start = skip(char_('_'))[
              /* binary with suffix */
              (bin_parser[_val=_1] &gt;&gt; char_("bByY"))
              /* octal with suffix */
              | (oct_parser[_val=_1] &gt;&gt; char_("qQoO"))
              /* hexadecimal with suffix */
              | (hex_parser[_val=_1] &gt;&gt; char_("hHxX"))
              /* decimal with optional suffix */
              | (dec_parser[_val=_1] &gt;&gt; -char_("dDtT"))
              ];
      }
  
      qi::rule&lt;Iterator, uint64_t()&gt; start;
  };
  
  int main(int argv, const char *argc[]) {
      typedef std::string::const_iterator iter;
      unsigned_parser&lt;iter&gt; up;
      uint64_t val;
      if (argv != 2) {
          std::cerr &lt;&lt; "Usage: " &lt;&lt; argc[0] &lt;&lt; " &lt;input&gt;" &lt;&lt; std::endl;
          return 1;
      }
      std::string test(argc[1]);
      iter i = test.begin();
      iter end = test.end();
      bool rv = parse(i, end, up, val);
      if (rv &amp;&amp; i == end) {
          std::cout &lt;&lt; "Succeeded: " &lt;&lt; val &lt;&lt; std::endl;
          return 0;
      }
      if (rv) {
          std::cout &lt;&lt; "Failed partial parse: " &lt;&lt; val &lt;&lt; std::endl;
          return 1;
      }
      std::cout &lt;&lt; "Failed." &lt;&lt; std::endl;
      return 1;
  }
  </code></pre>