title: How to use boost spirit list operator with mandatory minimum amount of elements?
body: <p>I would like to parse dot language (<a href="http://www.graphviz.org/content/dot-language" rel="nofollow noreferrer">http://www.graphviz.org/content/dot-language</a>). It's a graph definition language that defines nodes and connections between them. A typical statement looks like <code>node1-&gt;node2-&gt;node3;</code>. It would be nice to use a boost::spirit list operator <code>%</code> to make a list of nodes. A naive approach would be:</p>
  
  <pre><code>edge_stmt %=
      (
          node_or_subgraph(_r1) % (qi::eps(_r1) &gt;&gt; tok.diredgeop | tok.undiredgeop)
      ) &gt;&gt; -attr_list;
  </code></pre>
  
  <p><code>_r1</code> indicates if this is directed or undirected graph, <code>diredgeop</code> is a token for <code>-&gt;</code>, <code>undiredgeop</code> is respectively a token for <code>--</code>.</p>
  
  <p>The problem is the above code will succeed for just <code>node1;</code>, which is incorrect. In order to get a correct parser I have to somehow declare that there must be at least two elements in the list built by <code>%</code>. How?</p>
  
  <p>The documentation says that <code>a % b</code> is equivalent to <code>a &gt;&gt; *(omit[b] &gt;&gt; a)</code>, which is incorrect. One might want to try this:</p>
  
  <pre><code>edge_stmt %=
      (
          node_or_subgraph(_r1) &gt;&gt;
              +(
                  qi::omit
                  [
                      qi::eps(_r1) &gt;&gt; tok.diredgeop | tok.undiredgeop
                  ] &gt;&gt;
                  node_or_subgraph(_r1)
              )
      ) &gt;&gt; -attr_list;
  </code></pre>
  
  <p>But this code doesn't produce a vector, its synthesized attribute is a tuple.</p>
  
  <p>I can try semantic actions of course, but is there an elegant alternative without sematic actions?</p>