1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>API for Automatic Parser Creation</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="../parse_api.html" title="Parser API"> 9<link rel="prev" href="stream_api.html" title="Stream Based Parser API"> 10<link rel="next" href="../action.html" title="Semantic Actions with Parsers"> 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="stream_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../parse_api.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="../action.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.parse_api.create_parser"></a><a class="link" href="create_parser.html" title="API for Automatic Parser Creation">API 28 for Automatic Parser Creation</a> 29</h5></div></div></div> 30<h6> 31<a name="spirit.qi.reference.parse_api.create_parser.h0"></a> 32 <span class="phrase"><a name="spirit.qi.reference.parse_api.create_parser.description"></a></span><a class="link" href="create_parser.html#spirit.qi.reference.parse_api.create_parser.description">Description</a> 33 </h6> 34<p> 35 The library implements a special API returning a parser instance for 36 a supplied attribute type. This function finds the best matching parser 37 type for the attribute based on a set of simple matching rules (as outlined 38 in the table below) applied recursively to the attribute type. The returned 39 parser can be utilized to match input for the provided attribute. 40 </p> 41<h6> 42<a name="spirit.qi.reference.parse_api.create_parser.h1"></a> 43 <span class="phrase"><a name="spirit.qi.reference.parse_api.create_parser.header"></a></span><a class="link" href="create_parser.html#spirit.qi.reference.parse_api.create_parser.header">Header</a> 44 </h6> 45<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/qi/auto.hpp></span> 46<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_auto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 47</pre> 48<p> 49 Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>. 50 </p> 51<h6> 52<a name="spirit.qi.reference.parse_api.create_parser.h2"></a> 53 <span class="phrase"><a name="spirit.qi.reference.parse_api.create_parser.namespace"></a></span><a class="link" href="create_parser.html#spirit.qi.reference.parse_api.create_parser.namespace">Namespace</a> 54 </h6> 55<div class="informaltable"><table class="table"> 56<colgroup><col></colgroup> 57<thead><tr><th> 58 <p> 59 Name 60 </p> 61 </th></tr></thead> 62<tbody> 63<tr><td> 64 <p> 65 <code class="computeroutput"><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">create_parser</span></code> 66 </p> 67 </td></tr> 68<tr><td> 69 <p> 70 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">traits</span><span class="special">::</span><span class="identifier">create_parser_exists</span></code> 71 </p> 72 </td></tr> 73</tbody> 74</table></div> 75<h6> 76<a name="spirit.qi.reference.parse_api.create_parser.h3"></a> 77 <span class="phrase"><a name="spirit.qi.reference.parse_api.create_parser.synopsis"></a></span><a class="link" href="create_parser.html#spirit.qi.reference.parse_api.create_parser.synopsis">Synopsis</a> 78 </h6> 79<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">qi</span> 80<span class="special">{</span> 81 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">></span> 82 <span class="keyword">inline</span> <span class="special"><</span><span class="identifier">unspecified</span><span class="special">></span> 83 <span class="identifier">create_parser</span><span class="special">();</span> 84<span class="special">}}}</span> 85</pre> 86<p> 87 The returned instance can be directly passed as the parser (or the skipping 88 parser) to any of the <span class="emphasis"><em>Spirit.Qi</em></span> API functions. Additionally 89 it can be assigned to a rule as the rules right hand side expression. 90 This function will return a valid parser type only if the meta function 91 <code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">create_parser_exists</span></code> returns <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>. Otherwise it will fail compiling. 92 </p> 93<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">traits</span> 94<span class="special">{</span> 95 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">></span> 96 <span class="keyword">struct</span> <span class="identifier">create_parser_exists</span><span class="special">;</span> 97<span class="special">}}}</span> 98</pre> 99<p> 100 The meta function evaluates to <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code> 101 if <code class="computeroutput"><span class="identifier">create_parser</span></code> would 102 return a valid parser for the given type <code class="computeroutput"><span class="identifier">Attr</span></code>. 103 </p> 104<p> 105 The following table outlines the mapping rules from the attribute type 106 to the parser type. These rules are applied recursively to create the 107 parser type which can be used to match input for the given attribute 108 type. 109 </p> 110<div class="informaltable"><table class="table"> 111<colgroup> 112<col> 113<col> 114</colgroup> 115<thead><tr> 116<th> 117 <p> 118 Attribute type 119 </p> 120 </th> 121<th> 122 <p> 123 Generator type 124 </p> 125 </th> 126</tr></thead> 127<tbody> 128<tr> 129<td> 130 <p> 131 <code class="computeroutput"><span class="keyword">char</span></code>, <code class="computeroutput"><span class="keyword">wchar_t</span></code> 132 </p> 133 </td> 134<td> 135 <p> 136 <code class="computeroutput"><span class="identifier">standard</span><span class="special">::</span><span class="identifier">char_</span></code>, <code class="computeroutput"><span class="identifier">standard_wide</span><span class="special">::</span><span class="identifier">char_</span></code> 137 </p> 138 </td> 139</tr> 140<tr> 141<td> 142 <p> 143 <code class="computeroutput"><span class="keyword">short</span></code>, <code class="computeroutput"><span class="keyword">int</span></code>, <code class="computeroutput"><span class="keyword">long</span></code> 144 </p> 145 </td> 146<td> 147 <p> 148 <code class="computeroutput"><span class="identifier">short_</span></code>, <code class="computeroutput"><span class="identifier">int_</span></code>, <code class="computeroutput"><span class="identifier">long_</span></code> 149 </p> 150 </td> 151</tr> 152<tr> 153<td> 154 <p> 155 <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">short</span></code>, 156 <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">int</span></code>, 157 <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">long</span></code> 158 </p> 159 </td> 160<td> 161 <p> 162 <code class="computeroutput"><span class="identifier">ushort_</span></code>, <code class="computeroutput"><span class="identifier">uint_</span></code>, <code class="computeroutput"><span class="identifier">ulong_</span></code> 163 </p> 164 </td> 165</tr> 166<tr> 167<td> 168 <p> 169 <code class="computeroutput"><span class="keyword">float</span></code>, <code class="computeroutput"><span class="keyword">double</span></code>, <code class="computeroutput"><span class="keyword">long</span> 170 <span class="keyword">double</span></code> 171 </p> 172 </td> 173<td> 174 <p> 175 <code class="computeroutput"><span class="identifier">float_</span></code>, <code class="computeroutput"><span class="identifier">double_</span></code>, <code class="computeroutput"><span class="identifier">long_double</span></code> 176 </p> 177 </td> 178</tr> 179<tr> 180<td> 181 <p> 182 <code class="computeroutput"><span class="keyword">short</span></code>, <code class="computeroutput"><span class="keyword">int</span></code>, <code class="computeroutput"><span class="keyword">long</span></code> 183 </p> 184 </td> 185<td> 186 <p> 187 <code class="computeroutput"><span class="identifier">short_</span></code>, <code class="computeroutput"><span class="identifier">int_</span></code>, <code class="computeroutput"><span class="identifier">long_</span></code> 188 </p> 189 </td> 190</tr> 191<tr> 192<td> 193 <p> 194 <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">long</span></code>, 195 <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">long</span> 196 <span class="keyword">long</span></code> 197 </p> 198 </td> 199<td> 200 <p> 201 <code class="computeroutput"><span class="identifier">long_long</span></code>, 202 <code class="computeroutput"><span class="identifier">ulong_long</span></code> 203 </p> 204 </td> 205</tr> 206<tr> 207<td> 208 <p> 209 <code class="computeroutput"><span class="keyword">bool</span></code> 210 </p> 211 </td> 212<td> 213 <p> 214 <code class="computeroutput"><span class="identifier">bool_</span></code> 215 </p> 216 </td> 217</tr> 218<tr> 219<td> 220 <p> 221 Any (STL) container 222 </p> 223 </td> 224<td> 225 <p> 226 Kleene Star (unary <code class="computeroutput"><span class="char">'*'</span></code>) 227 </p> 228 </td> 229</tr> 230<tr> 231<td> 232 <p> 233 Any Fusion sequence 234 </p> 235 </td> 236<td> 237 <p> 238 Sequence operator (<code class="computeroutput"><span class="char">'>>'</span></code>) 239 </p> 240 </td> 241</tr> 242<tr> 243<td> 244 <p> 245 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><></span></code> 246 </p> 247 </td> 248<td> 249 <p> 250 Optional operator (unary <code class="computeroutput"><span class="char">'-'</span></code>) 251 </p> 252 </td> 253</tr> 254<tr> 255<td> 256 <p> 257 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">variant</span><span class="special"><></span></code> 258 </p> 259 </td> 260<td> 261 <p> 262 Alternative operator (<code class="computeroutput"><span class="char">'|'</span></code>) 263 </p> 264 </td> 265</tr> 266</tbody> 267</table></div> 268<div class="important"><table border="0" summary="Important"> 269<tr> 270<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../images/important.png"></td> 271<th align="left">Important</th> 272</tr> 273<tr><td align="left" valign="top"><p> 274 The mapping for the parsers <code class="computeroutput"><span class="identifier">long_long</span></code> 275 and <code class="computeroutput"><span class="identifier">ulong_long</span></code> are 276 only available on platforms where the preprocessor constant <code class="computeroutput"><span class="identifier">BOOST_HAS_LONG_LONG</span></code> is defined (i.e. 277 on platforms having native support for <code class="computeroutput"><span class="keyword">long</span> 278 <span class="keyword">long</span></code> and <code class="computeroutput"><span class="keyword">unsigned</span> 279 <span class="keyword">long</span> <span class="keyword">long</span></code> 280 (64 bit) signed and unsigned integer types). 281 </p></td></tr> 282</table></div> 283<h6> 284<a name="spirit.qi.reference.parse_api.create_parser.h4"></a> 285 <span class="phrase"><a name="spirit.qi.reference.parse_api.create_parser.template_parameters"></a></span><a class="link" href="create_parser.html#spirit.qi.reference.parse_api.create_parser.template_parameters">Template 286 parameters</a> 287 </h6> 288<div class="informaltable"><table class="table"> 289<colgroup> 290<col> 291<col> 292</colgroup> 293<thead><tr> 294<th> 295 <p> 296 Parameter 297 </p> 298 </th> 299<th> 300 <p> 301 Description 302 </p> 303 </th> 304</tr></thead> 305<tbody><tr> 306<td> 307 <p> 308 <code class="computeroutput"><span class="identifier">Attr</span></code> 309 </p> 310 </td> 311<td> 312 <p> 313 An attribute type utilized to create the corresponding parser 314 type from. 315 </p> 316 </td> 317</tr></tbody> 318</table></div> 319</div> 320<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 321<td align="left"></td> 322<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 323 Distributed under the Boost Software License, Version 1.0. (See accompanying 324 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>) 325 </p> 326</div></td> 327</tr></table> 328<hr> 329<div class="spirit-nav"> 330<a accesskey="p" href="stream_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../parse_api.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="../action.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 331</div> 332</body> 333</html> 334