Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since sehe's answer was more or less for educational purposes, we have now several solutions:</p> <pre><code>*garbage &gt;&gt; -(item % *garbage) &gt;&gt; *garbage *garbage &gt;&gt; *(item &gt;&gt; *garbage) all = *(garbage | item[phx::push_back(qi::_val,qi::_1)]); </code></pre> <p>And the solution from cv_and_he:</p> <pre><code>#define BOOST_SPIRIT_USE_PHOENIX_V3 #include &lt;boost/config/warning_disable.hpp&gt; #include &lt;boost/spirit/include/qi.hpp&gt; #include &lt;boost/fusion/adapted/struct.hpp&gt; #include &lt;boost/spirit/include/phoenix.hpp&gt; #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;vector&gt; namespace qi = boost::spirit::qi; struct container { std::string name; bool dummy; }; BOOST_FUSION_ADAPT_STRUCT(::container, (std::string, name) (bool, dummy)) struct container_vector { //ADDED std::vector&lt;container&gt; data; }; namespace boost{ namespace spirit{ namespace traits //ADDED { template &lt;&gt; struct is_container&lt;container_vector&gt; : boost::mpl::true_ {}; template &lt;&gt; struct container_value&lt;container_vector&gt; { typedef optional&lt;container&gt; type; }; template &lt;&gt; struct push_back_container&lt;container_vector,optional&lt;container&gt; &gt; { static bool call(container_vector&amp; cont, const optional&lt;container&gt;&amp; val) { if(val) cont.data.push_back(*val); return true; } }; }}} int main() { typedef std::string::const_iterator iterator; qi::rule&lt;iterator, container_vector()&gt; all; //CHANGED qi::rule&lt;iterator, container()&gt; item; qi::rule&lt;iterator, std::string()&gt; string_rule; qi::rule&lt;iterator&gt; garbage; all = *(garbage | item); garbage = qi::char_ - qi::lit("Test"); string_rule = qi::string("Test"); item = string_rule &gt;&gt; qi::attr(true); container_vector ast; //CHANGED std::string input = "blaTestbla"; iterator first = input.begin(); iterator last = input.end(); bool result = qi::parse(first, last, all, ast); if (result) { result = first == last; } if (result) { std::cout &lt;&lt; "Parsed " &lt;&lt; ast.data.size() &lt;&lt; " element(s)" &lt;&lt; std::endl; //CHANGED } else { std::cout &lt;&lt; "failure" &lt;&lt; std::endl; } } </code></pre> <p>Although I didn't want to use a skipper I ended up with:</p> <pre><code>start = qi::skip(garbage.alias())[*item]; </code></pre> <p>This last solution was the fastest (by 1-2%) in my unscientific tests using the c-files of the Linux kernel with my production rules.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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