1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>List Parser (a % b)</title> 5<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../../index.html" title="Spirit 2.5.8"> 8<link rel="up" href="../operator.html" title="Parser Operators"> 9<link rel="prev" href="kleene.html" title="Kleene Parser (*a)"> 10<link rel="next" href="not_predicate.html" title="Not-Predicate Parser (!a)"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="kleene.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operator.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="not_predicate.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h5 class="title"> 27<a name="spirit.qi.reference.operator.list"></a><a class="link" href="list.html" title="List Parser (a % b)">List Parser (<code class="computeroutput"><span class="identifier">a</span> <span class="special">%</span> <span class="identifier">b</span></code>)</a> 28</h5></div></div></div> 29<h6> 30<a name="spirit.qi.reference.operator.list.h0"></a> 31 <span class="phrase"><a name="spirit.qi.reference.operator.list.description"></a></span><a class="link" href="list.html#spirit.qi.reference.operator.list.description">Description</a> 32 </h6> 33<p> 34 The list operator, <code class="computeroutput"><span class="identifier">a</span> <span class="special">%</span> <span class="identifier">b</span></code>, 35 is a binary operator that matches a list of one or more repetitions of 36 <code class="computeroutput"><span class="identifier">a</span></code> separated by occurrences 37 of <code class="computeroutput"><span class="identifier">b</span></code>. This is equivalent 38 to <code class="computeroutput"><span class="identifier">a</span> <span class="special">>></span> 39 <span class="special">*(</span><span class="identifier">b</span> 40 <span class="special">>></span> <span class="identifier">a</span><span class="special">)</span></code>. 41 </p> 42<h6> 43<a name="spirit.qi.reference.operator.list.h1"></a> 44 <span class="phrase"><a name="spirit.qi.reference.operator.list.header"></a></span><a class="link" href="list.html#spirit.qi.reference.operator.list.header">Header</a> 45 </h6> 46<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/qi/operator/list.hpp></span> 47<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_list</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 48</pre> 49<p> 50 Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>. 51 </p> 52<h6> 53<a name="spirit.qi.reference.operator.list.h2"></a> 54 <span class="phrase"><a name="spirit.qi.reference.operator.list.model_of"></a></span><a class="link" href="list.html#spirit.qi.reference.operator.list.model_of">Model 55 of</a> 56 </h6> 57<div class="blockquote"><blockquote class="blockquote"><p> 58 <a class="link" href="../parser_concepts/binaryparser.html" title="BinaryParser"><code class="computeroutput"><span class="identifier">BinaryParser</span></code></a> 59 </p></blockquote></div> 60<div class="variablelist"> 61<p class="title"><b>Notation</b></p> 62<dl class="variablelist"> 63<dt><span class="term"><code class="computeroutput"><span class="identifier">a</span></code>, <code class="computeroutput"><span class="identifier">b</span></code></span></dt> 64<dd><p> 65 A <a class="link" href="../parser_concepts/parser.html" title="Parser"><code class="computeroutput"><span class="identifier">Parser</span></code></a> 66 </p></dd> 67</dl> 68</div> 69<h6> 70<a name="spirit.qi.reference.operator.list.h3"></a> 71 <span class="phrase"><a name="spirit.qi.reference.operator.list.expression_semantics"></a></span><a class="link" href="list.html#spirit.qi.reference.operator.list.expression_semantics">Expression 72 Semantics</a> 73 </h6> 74<p> 75 Semantics of an expression is defined only where it differs from, or 76 is not defined in <a class="link" href="../parser_concepts/binaryparser.html" title="BinaryParser"><code class="computeroutput"><span class="identifier">BinaryParser</span></code></a>. 77 </p> 78<div class="informaltable"><table class="table"> 79<colgroup> 80<col> 81<col> 82</colgroup> 83<thead><tr> 84<th> 85 <p> 86 Expression 87 </p> 88 </th> 89<th> 90 <p> 91 Semantics 92 </p> 93 </th> 94</tr></thead> 95<tbody><tr> 96<td> 97 <p> 98 <code class="computeroutput"><span class="identifier">a</span> <span class="special">%</span> 99 <span class="identifier">b</span></code> 100 </p> 101 </td> 102<td> 103 <p> 104 Match a list of one or more repetitions of <code class="computeroutput"><span class="identifier">a</span></code> 105 separated by occurrences of <code class="computeroutput"><span class="identifier">b</span></code>. 106 This is equivalent to <code class="computeroutput"><span class="identifier">a</span> 107 <span class="special">>></span> <span class="special">*(</span><span class="identifier">omit</span><span class="special">[</span><span class="identifier">b</span><span class="special">]</span> 108 <span class="special">>></span> <span class="identifier">a</span><span class="special">)</span></code>. 109 </p> 110 </td> 111</tr></tbody> 112</table></div> 113<div class="note"><table border="0" summary="Note"> 114<tr> 115<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 116<th align="left">Note</th> 117</tr> 118<tr><td align="left" valign="top"><p> 119 The list operator <code class="computeroutput"><span class="identifier">a</span> <span class="special">%</span> <span class="identifier">b</span></code> 120 omits the attribute of parser <code class="computeroutput"><span class="identifier">b</span></code>. 121 If you need <code class="computeroutput"><span class="identifier">b</span></code> to contribute 122 to the result attribute choose <code class="computeroutput"><span class="identifier">a</span> 123 <span class="special">>></span> <span class="special">*(</span><span class="identifier">b</span> <span class="special">>></span> 124 <span class="identifier">a</span><span class="special">)</span></code> 125 over the list operator <code class="computeroutput"><span class="identifier">a</span> 126 <span class="special">%</span> <span class="identifier">b</span></code>. 127 </p></td></tr> 128</table></div> 129<h6> 130<a name="spirit.qi.reference.operator.list.h4"></a> 131 <span class="phrase"><a name="spirit.qi.reference.operator.list.attributes"></a></span><a class="link" href="list.html#spirit.qi.reference.operator.list.attributes">Attributes</a> 132 </h6> 133<p> 134 See <a class="link" href="../../quick_reference/compound_attribute_rules.html#spirit.qi.quick_reference.compound_attribute_rules.notation">Compound 135 Attribute Notation</a>. 136 </p> 137<div class="informaltable"><table class="table"> 138<colgroup> 139<col> 140<col> 141</colgroup> 142<thead><tr> 143<th> 144 <p> 145 Expression 146 </p> 147 </th> 148<th> 149 <p> 150 Attribute 151 </p> 152 </th> 153</tr></thead> 154<tbody><tr> 155<td> 156 <p> 157 <code class="computeroutput"><span class="identifier">a</span> <span class="special">%</span> 158 <span class="identifier">b</span></code> 159 </p> 160 </td> 161<td> 162 <p> 163</p> 164<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">B</span> <span class="special">--></span> <span class="special">(</span><span class="identifier">a</span> <span class="special">%</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">vector</span><span class="special"><</span><span class="identifier">A</span><span class="special">></span> 165<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">B</span> <span class="special">--></span> <span class="special">(</span><span class="identifier">a</span> <span class="special">%</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">Unused</span></pre> 166<p> 167 </p> 168 </td> 169</tr></tbody> 170</table></div> 171<h6> 172<a name="spirit.qi.reference.operator.list.h5"></a> 173 <span class="phrase"><a name="spirit.qi.reference.operator.list.complexity"></a></span><a class="link" href="list.html#spirit.qi.reference.operator.list.complexity">Complexity</a> 174 </h6> 175<div class="blockquote"><blockquote class="blockquote"><p> 176 The overall complexity of the List is defined by the complexity of 177 its subject, <code class="computeroutput"><span class="identifier">a</span></code>, multiplied 178 by the number of repetitions. The complexity of the List itself is 179 O(N), where N is the number successful repetitions. 180 </p></blockquote></div> 181<h6> 182<a name="spirit.qi.reference.operator.list.h6"></a> 183 <span class="phrase"><a name="spirit.qi.reference.operator.list.example"></a></span><a class="link" href="list.html#spirit.qi.reference.operator.list.example">Example</a> 184 </h6> 185<div class="note"><table border="0" summary="Note"> 186<tr> 187<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 188<th align="left">Note</th> 189</tr> 190<tr><td align="left" valign="top"><p> 191 The test harness for the example(s) below is presented in the <a class="link" href="../basics.html#spirit.qi.reference.basics.examples">Basics Examples</a> 192 section. 193 </p></td></tr> 194</table></div> 195<p> 196 Some using declarations: 197 </p> 198<p> 199</p> 200<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">int_</span><span class="special">;</span> 201</pre> 202<p> 203 </p> 204<p> 205 Parse a comma separated list of numbers and put them in a vector: 206 </p> 207<p> 208</p> 209<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">attr</span><span class="special">;</span> 210<span class="identifier">test_phrase_parser_attr</span><span class="special">(</span> 211 <span class="string">"111, 222, 333, 444, 555"</span><span class="special">,</span> <span class="identifier">int_</span> <span class="special">%</span> <span class="char">','</span><span class="special">,</span> <span class="identifier">attr</span><span class="special">);</span> 212<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> 213 <span class="special"><<</span> <span class="identifier">attr</span><span class="special">[</span><span class="number">0</span><span class="special">]</span> <span class="special"><<</span> <span class="char">','</span> <span class="special"><<</span> <span class="identifier">attr</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special"><<</span> <span class="char">','</span> <span class="special"><<</span> <span class="identifier">attr</span><span class="special">[</span><span class="number">2</span><span class="special">]</span> <span class="special"><<</span> <span class="char">','</span> 214 <span class="special"><<</span> <span class="identifier">attr</span><span class="special">[</span><span class="number">3</span><span class="special">]</span> <span class="special"><<</span> <span class="char">','</span> <span class="special"><<</span> <span class="identifier">attr</span><span class="special">[</span><span class="number">4</span><span class="special">]</span> 215 <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 216</pre> 217<p> 218 </p> 219</div> 220<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 221<td align="left"></td> 222<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 223 Distributed under the Boost Software License, Version 1.0. (See accompanying 224 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 225 </p> 226</div></td> 227</tr></table> 228<hr> 229<div class="spirit-nav"> 230<a accesskey="p" href="kleene.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operator.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="not_predicate.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 231</div> 232</body> 233</html> 234