1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Qi Keyword Parser Directive</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 Repository 0.2"> 8<link rel="up" href="../directives.html" title="Qi Parser Directives"> 9<link rel="prev" href="distinct.html" title="Qi Distinct Parser Directive"> 10<link rel="next" href="seek.html" title="Qi Seek Parser Directive"> 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="distinct.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../directives.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="seek.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="spirit_repository.qi_components.directives.kwd"></a><a class="link" href="kwd.html" title="Qi Keyword Parser Directive">Qi 28 Keyword Parser Directive </a> 29</h4></div></div></div> 30<h6> 31<a name="spirit_repository.qi_components.directives.kwd.h0"></a> 32 <span class="phrase"><a name="spirit_repository.qi_components.directives.kwd.description"></a></span><a class="link" href="kwd.html#spirit_repository.qi_components.directives.kwd.description">Description</a> 33 </h6> 34<p> 35 The <code class="computeroutput"><span class="identifier">kwd</span><span class="special">[]</span></code>, 36 <code class="computeroutput"><span class="identifier">dkwd</span><span class="special">[]</span></code> 37 and <code class="computeroutput"><span class="identifier">ikwd</span><span class="special">[]</span></code>, 38 <code class="computeroutput"><span class="identifier">idkwd</span><span class="special">[]</span></code> 39 provide a powerful and flexible mechanism for parsing keyword based input. 40 It works in conjunction with the / operator to create an effective keyword 41 parsing loop. The keyword parsing loop doesn't require the keywords to 42 appear in a defined order in the input but also provides the possibility 43 to check how many times a keyword appears in the input. 44 </p> 45<p> 46 The kwd directive will parse the keywords respecting case sensitivity whereas 47 the ikwd direcive is case insensitive. You can mix the kwd and ikwd directives 48 inside a set of keywords, but be aware that this has a small overhead. 49 It should be preferred not to mix the kwd and ikwd directives. 50 </p> 51<p> 52 The dkwd and idkwd provide a mechanism to pase distinct keywords. These 53 directives require that the skipper successeds parsing input right after 54 the keyword part. 55 </p> 56<p> 57 dkwd("keyword1")<span class="emphasis"><em>='>>int_</em></span> 58 </p> 59<p> 60 is equivalent to: 61 </p> 62<p> 63 lit("keyword1") >> skipper+ >> '=' >> int_ 64 </p> 65<p> 66 All the keyword directives can be mixed inside a keyword list. 67 </p> 68<p> 69 The kwd directive is very similar to the repeat directive in that it enables 70 to enforce keyword occurrence constraints but also provides very interesting 71 speed improvement over the pure EBNF syntax or the Nabialek-Trick. 72 </p> 73<h6> 74<a name="spirit_repository.qi_components.directives.kwd.h1"></a> 75 <span class="phrase"><a name="spirit_repository.qi_components.directives.kwd.header"></a></span><a class="link" href="kwd.html#spirit_repository.qi_components.directives.kwd.header">Header</a> 76 </h6> 77<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/repository/home/qi/directive/kwd.hpp></span> 78<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">repository</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_kwd</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 79</pre> 80<h6> 81<a name="spirit_repository.qi_components.directives.kwd.h2"></a> 82 <span class="phrase"><a name="spirit_repository.qi_components.directives.kwd.synopsis"></a></span><a class="link" href="kwd.html#spirit_repository.qi_components.directives.kwd.synopsis">Synopsis</a> 83 </h6> 84<div class="informaltable"><table class="table"> 85<colgroup> 86<col> 87<col> 88</colgroup> 89<thead><tr> 90<th> 91 <p> 92 Expression 93 </p> 94 </th> 95<th> 96 <p> 97 Semantics 98 </p> 99 </th> 100</tr></thead> 101<tbody> 102<tr> 103<td> 104 <p> 105 <code class="computeroutput"><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">keyword</span><span class="special">)[</span><span class="identifier">subject</span><span class="special">]</span></code> 106 </p> 107 </td> 108<td> 109 <p> 110 Parse ( <code class="computeroutput"><span class="string">"keyword"</span></code> 111 > <code class="computeroutput"><span class="identifier">subject</span></code>) 112 zero or more times. 113 </p> 114 </td> 115</tr> 116<tr> 117<td> 118 <p> 119 <code class="computeroutput"><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">keyword</span><span class="special">,</span><span class="identifier">n</span><span class="special">)[</span><span class="identifier">subject</span><span class="special">]</span></code> 120 </p> 121 </td> 122<td> 123 <p> 124 Parse ( <code class="computeroutput"><span class="string">"keyword"</span></code> 125 > <code class="computeroutput"><span class="identifier">subject</span></code>) 126 exactly <code class="computeroutput"><span class="identifier">n</span></code> times. 127 </p> 128 </td> 129</tr> 130<tr> 131<td> 132 <p> 133 <code class="computeroutput"><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">keyword</span><span class="special">,</span><span class="identifier">min</span><span class="special">,</span> 134 <span class="identifier">max</span><span class="special">)[</span><span class="identifier">subject</span><span class="special">]</span></code> 135 </p> 136 </td> 137<td> 138 <p> 139 Parse ( <code class="computeroutput"><span class="string">"keyword"</span></code> 140 > <code class="computeroutput"><span class="identifier">subject</span></code>) 141 at least <code class="computeroutput"><span class="identifier">min</span></code> 142 times and at most <code class="computeroutput"><span class="identifier">max</span></code> 143 times. 144 </p> 145 </td> 146</tr> 147<tr> 148<td> 149 <p> 150 <code class="computeroutput"><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">keyword</span><span class="special">,</span><span class="identifier">min</span><span class="special">,</span> 151 <span class="identifier">inf</span><span class="special">)[</span><span class="identifier">subject</span><span class="special">]</span></code> 152 </p> 153 </td> 154<td> 155 <p> 156 Parse ( <code class="computeroutput"><span class="string">"keyword"</span></code> 157 > <code class="computeroutput"><span class="identifier">subject</span></code>) 158 at least <code class="computeroutput"><span class="identifier">min</span></code> 159 or more. 160 </p> 161 </td> 162</tr> 163</tbody> 164</table></div> 165<p> 166 For non case sensitive keywords use the ikwd directive. If distinct keyword 167 parsing is required, use the dkwd and idkwd directive instead. 168 </p> 169<h6> 170<a name="spirit_repository.qi_components.directives.kwd.h3"></a> 171 <span class="phrase"><a name="spirit_repository.qi_components.directives.kwd.parameters"></a></span><a class="link" href="kwd.html#spirit_repository.qi_components.directives.kwd.parameters">Parameters</a> 172 </h6> 173<div class="informaltable"><table class="table"> 174<colgroup> 175<col> 176<col> 177</colgroup> 178<thead><tr> 179<th> 180 <p> 181 Parameter 182 </p> 183 </th> 184<th> 185 <p> 186 Description 187 </p> 188 </th> 189</tr></thead> 190<tbody> 191<tr> 192<td> 193 <p> 194 <code class="computeroutput"><span class="identifier">keyword</span></code> 195 </p> 196 </td> 197<td> 198 <p> 199 The parser for the opening (the prefix). 200 </p> 201 </td> 202</tr> 203<tr> 204<td> 205 <p> 206 <code class="computeroutput"><span class="identifier">subject</span></code> 207 </p> 208 </td> 209<td> 210 <p> 211 The parser for the input sequence following the keyword part. 212 </p> 213 </td> 214</tr> 215<tr> 216<td> 217 <p> 218 <code class="computeroutput"><span class="identifier">n</span></code> 219 </p> 220 </td> 221<td> 222 <p> 223 Int representing the exact number of times the keyword must be 224 repeated. 225 </p> 226 </td> 227</tr> 228<tr> 229<td> 230 <p> 231 <code class="computeroutput"><span class="identifier">min</span></code> 232 </p> 233 </td> 234<td> 235 <p> 236 Int representing the minimum number of times the keyword must 237 be repeated. 238 </p> 239 </td> 240</tr> 241<tr> 242<td> 243 <p> 244 <code class="computeroutput"><span class="identifier">max</span></code> 245 </p> 246 </td> 247<td> 248 <p> 249 Int representing the maximum number of times the keyword must 250 be repeated. 251 </p> 252 </td> 253</tr> 254</tbody> 255</table></div> 256<p> 257 The keyword as well as the subject parameters can be any valid spirit parser. 258 The parameter n, min and max are integer constants. 259 </p> 260<h6> 261<a name="spirit_repository.qi_components.directives.kwd.h4"></a> 262 <span class="phrase"><a name="spirit_repository.qi_components.directives.kwd.attributes"></a></span><a class="link" href="kwd.html#spirit_repository.qi_components.directives.kwd.attributes">Attributes</a> 263 </h6> 264<div class="informaltable"><table class="table"> 265<colgroup> 266<col> 267<col> 268</colgroup> 269<thead><tr> 270<th> 271 <p> 272 Expression 273 </p> 274 </th> 275<th> 276 <p> 277 Attribute 278 </p> 279 </th> 280</tr></thead> 281<tbody> 282<tr> 283<td> 284 <p> 285 <code class="computeroutput"><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code> 286 </p> 287 </td> 288<td> 289 <p> 290</p> 291<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">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">A</span><span class="special">></span> <span class="keyword">or</span> <span class="identifier">vector</span><span class="special"><</span><span class="identifier">A</span><span class="special">></span> 292<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--></span> <span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre> 293<p> 294 </p> 295 </td> 296</tr> 297<tr> 298<td> 299 <p> 300 <code class="computeroutput"><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">,</span><span class="identifier">n</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code> 301 </p> 302 </td> 303<td> 304 <p> 305</p> 306<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">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">,</span><span class="identifier">n</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">A</span><span class="special">></span> <span class="keyword">or</span> <span class="identifier">vector</span><span class="special"><</span><span class="identifier">A</span><span class="special">></span> 307<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--></span> <span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">,</span><span class="identifier">n</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre> 308<p> 309 </p> 310 </td> 311</tr> 312<tr> 313<td> 314 <p> 315 <code class="computeroutput"><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">,</span><span class="identifier">min</span><span class="special">,</span> 316 <span class="identifier">max</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code> 317 </p> 318 </td> 319<td> 320 <p> 321</p> 322<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">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">,</span><span class="identifier">min</span><span class="special">,</span> <span class="identifier">max</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">A</span><span class="special">></span> <span class="keyword">or</span> <span class="identifier">vector</span><span class="special"><</span><span class="identifier">A</span><span class="special">></span> 323<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--></span> <span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">,</span><span class="identifier">min</span><span class="special">,</span> <span class="identifier">max</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre> 324<p> 325 </p> 326 </td> 327</tr> 328<tr> 329<td> 330 <p> 331 <code class="computeroutput"><span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">,</span><span class="identifier">min</span><span class="special">,</span> 332 <span class="identifier">inf</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]</span></code> 333 </p> 334 </td> 335<td> 336 <p> 337</p> 338<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">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">,</span><span class="identifier">min</span><span class="special">,</span> <span class="identifier">inf</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">A</span><span class="special">></span> <span class="keyword">or</span> <span class="identifier">vector</span><span class="special"><</span><span class="identifier">A</span><span class="special">></span> 339<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--></span> <span class="identifier">kwd</span><span class="special">(</span><span class="identifier">k1</span><span class="special">,</span><span class="identifier">min</span><span class="special">,</span> <span class="identifier">inf</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">Unused</span></pre> 340<p> 341 </p> 342 </td> 343</tr> 344</tbody> 345</table></div> 346<h6> 347<a name="spirit_repository.qi_components.directives.kwd.h5"></a> 348 <span class="phrase"><a name="spirit_repository.qi_components.directives.kwd.complexity"></a></span><a class="link" href="kwd.html#spirit_repository.qi_components.directives.kwd.complexity">Complexity</a> 349 </h6> 350<div class="blockquote"><blockquote class="blockquote"> 351<p> 352 The overall complexity is defined by the complexity of its subject parser. 353 The complexity of the keyword list construct <code class="computeroutput"><span class="identifier">kwd</span></code> 354 itself is O(N), where N is the number of repetitions executed. 355 </p> 356<p> 357 In the case where all the keywords are strings, the complexity of the 358 keyword list itself determined by the complexity of the internal TST 359 contents : 360 </p> 361<p> 362 O(log n+k) 363 </p> 364<p> 365 Where k is the length of the string to be searched in a TST with n strings. 366 </p> 367<p> 368 When the keywords used are complex parsers, then the complexity is the 369 sum of the sub parser complexities. 370 </p> 371</blockquote></div> 372<h6> 373<a name="spirit_repository.qi_components.directives.kwd.h6"></a> 374 <span class="phrase"><a name="spirit_repository.qi_components.directives.kwd.example"></a></span><a class="link" href="kwd.html#spirit_repository.qi_components.directives.kwd.example">Example</a> 375 </h6> 376<p> 377 Please refer to keyword_list. 378 </p> 379</div> 380<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 381<td align="left"></td> 382<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 383 Distributed under the Boost Software License, Version 1.0. (See accompanying 384 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>) 385 </p> 386</div></td> 387</tr></table> 388<hr> 389<div class="spirit-nav"> 390<a accesskey="p" href="distinct.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../directives.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="seek.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 391</div> 392</body> 393</html> 394