Note that there are some explanatory texts on larger screens.

plurals
  1. POSkipper does not work in boost::spirit
    text
    copied!<p>I use boost spirit to parse a color. That worked quite well, but after I changed the the iterator type, the skipper stopped working.</p> <pre><code>"rgb(1.0,1.0,0.5)" // this works " rgb(0.2,0.2,0.2)" // this fails </code></pre> <p>Here is the header:</p> <pre><code>struct ColorGrammar : public qi::grammar&lt;StringIterator, Color(), chs::space_type&gt; { //! Iterator type for this grammar typedef StringIterator ItType; //! Skipper type used in this grammar typedef chs::space_type Skipper; //! Rule to parse a number with up to 3 digits qi::uint_parser&lt;uint8, 10, 1, 3&gt; number; //! Rule to parse a hex digit qi::uint_parser&lt;uint8, 16, 1, 1&gt; hexdigit; ColorGrammar(); //! Rule for rgb(...) qi::rule&lt;ItType, Color(), qi::locals&lt;float, float&gt;, Skipper&gt; rule_rgb; //! Rule for rgba(...) qi::rule&lt;ItType, Color(), qi::locals&lt;float, float, float&gt;, Skipper&gt; rule_rgba; //! Mainrule qi::rule&lt;ItType, Color(), Skipper&gt; rule_color; }; </code></pre> <p>Here is the cpp</p> <pre><code>ColorGrammar::ColorGrammar() : ColorGrammar::base_type(rule_color, "color-grammar") { using namespace qi::labels; using boost::phoenix::construct; auto&amp; _1 = qi::_1; rule_rgb = '(' &gt;&gt; qi::float_[_a = _1] &gt;&gt; ',' &gt;&gt; qi::float_[_b = _1] &gt;&gt; ',' &gt;&gt; qi::float_[_val = phx::construct&lt;Color&gt;(_a, _b, _1)] &gt;&gt; ')'; rule_rgba = '(' &gt;&gt; qi::float_[_a = _1] &gt;&gt; ',' &gt;&gt; qi::float_[_b = _1] &gt;&gt; ',' &gt;&gt; qi::float_[_c = _1] &gt;&gt; ',' &gt;&gt; qi::float_[_val = phx::construct&lt;Color&gt;(_a, _b, _c, _1)] &gt;&gt; ')'; rule_color = (qi::lit("rgb") &gt;&gt; rule_rgb) | (qi::lit("rgba") &gt;&gt; rule_rgba); } </code></pre> <p>And the call:</p> <pre><code>Color out; StringIterator begin = str.cbegin(); StringIterator end = str.cend(); bool result = qi::phrase_parse(begin, end, color_, chs::space, out); </code></pre> <p>I'm sure, it is only a little misstake, but I am not able to see it. Maybe i watched too long at the source... can you see a misstake?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload