title: Using Spirit, how to populate vector within a struct of the AST?
body: <p>I tried to adjust this example to make use of a variable number of elements using a group vector instead of hard coding 3 ints (n1, n2, n3), but to no avail.</p>
  
  <p>Here is the example I've tried to modify. coliru.stacked-crooked.com/a/90110f91a4ac466a</p>
  
  <p>Here's the code.</p>
  
  <pre><code>#define BOOST_SPIRIT_X3_DEBUG
  #include &lt;iostream&gt;
  #include &lt;boost/spirit/home/x3.hpp&gt;
  #include &lt;boost/fusion/include/adapt_struct.hpp&gt;
  #include &lt;boost/fusion/include/io.hpp&gt;
  
  namespace client { 
      namespace ast {
  
          struct number {
              //struct group { int n1, n2, n3; }; // instead of 3 ints ...
              struct group {
                  std::vector&lt;int&gt; persons;       // get a variable number
                  //bool dummy;
              };
  
              std::vector&lt;group&gt; groups;
              bool dummy;
          };
  
          struct comment {
              std::string text;
              bool dummy;
          };
  
          struct input {
              std::vector&lt;comment&gt; comments;  
              std::vector&lt;number&gt; numbers;
          }; 
      } 
  }
  
  BOOST_FUSION_ADAPT_STRUCT(client::ast::comment, text, dummy)
  BOOST_FUSION_ADAPT_STRUCT(client::ast::number::group, persons)
  BOOST_FUSION_ADAPT_STRUCT(client::ast::number, groups, dummy)
  BOOST_FUSION_ADAPT_STRUCT(client::ast::input, comments, numbers)
  
  namespace client {      
      namespace parser {
  
          namespace x3 = boost::spirit::x3;
          using namespace x3;
  
          typedef std::string::const_iterator It;
  
          using namespace x3;
  
          auto const comment = rule&lt;struct _c, ast::comment&gt; {"comment"} = lexeme[*(char_ - eol)] &gt;&gt; attr(false);
          auto const number  = rule&lt;struct _n, ast::number&gt; {"number"}   = *(int_ &gt;&gt; int_ &gt;&gt; int_) &gt;&gt; attr(false);
  
          auto lines = [](auto p) { return *(p &gt;&gt; eol); };
  
          auto const input = 
              repeat(1)[comment] &gt;&gt; eol &gt;&gt;
              lines(number);
      }
  }
  
  int main() {
      namespace x3 = boost::spirit::x3;
  
      std::string const iss("any char string here\n1 2 3\n1 2 3 4 5 6\n1 2 3 4 5 6 7 8 9\n");
  
      auto iter = iss.begin(), eof = iss.end();
  
      client::ast::input types;
  
      bool ok = phrase_parse(iter, eof, client::parser::input, x3::blank, types);
  
      if (iter != eof) {
          std::cout &lt;&lt; "Remaining unparsed: '" &lt;&lt; std::string(iter, eof) &lt;&lt; "'\n";
      }
      std::cout &lt;&lt; "Parsed: " &lt;&lt; (100.0 * std::distance(iss.begin(), iter) / iss.size()) &lt;&lt; "%\n";
      std::cout &lt;&lt; "ok = " &lt;&lt; ok &lt;&lt; std::endl;
  
      for (auto &amp;item : types.comments) {
          std::cout &lt;&lt; "comment: " &lt;&lt; boost::fusion::as_deque(item) &lt;&lt; "\n";
      }
      /*for (auto&amp; item : types.numbers) {
          std::cout &lt;&lt; "number:  ";
          for (auto&amp; g : item.groups)
              std::cout &lt;&lt; boost::fusion::as_deque(g) &lt;&lt; " ";
          std::cout &lt;&lt; "\n";
      }*/
  }
  </code></pre>
  
  <p>The error messages always look the same, deep in the templates. So instead of hard-coding the number of int's to be parsed, the number of int's should be variable, but still divisible by 3 (i.e., total number of ints on a line is 3, 6, 9, etc...). </p>