1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Define a Custom Attribute Mapping for a Parser</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="../auto.html" title="Create Components from Attributes (Qi and Karma)"> 9<link rel="prev" href="../auto.html" title="Create Components from Attributes (Qi and Karma)"> 10<link rel="next" href="create_generator.html" title="Define a Custom Attribute Mapping for a Generator"> 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="../auto.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../auto.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="create_generator.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.advanced.customize.auto.create_parser"></a><a class="link" href="create_parser.html" title="Define a Custom Attribute Mapping for a Parser">Define 28 a Custom Attribute Mapping for a Parser</a> 29</h5></div></div></div> 30<h6> 31<a name="spirit.advanced.customize.auto.create_parser.h0"></a> 32 <span class="phrase"><a name="spirit.advanced.customize.auto.create_parser.create_parser"></a></span><a class="link" href="create_parser.html#spirit.advanced.customize.auto.create_parser.create_parser">create_parser</a> 33 </h6> 34<p> 35 The template <code class="computeroutput"><span class="identifier">create_parser</span></code> 36 is a type used as an customization point. It is invoked by the <span class="emphasis"><em>Qi</em></span> 37 <a class="link" href="../../../qi/reference/parse_api/create_parser.html" title="API for Automatic Parser Creation"><code class="computeroutput"><span class="identifier">create_parser</span></code></a> API function in 38 order to create a custom mapping of the given data type to a parser expression. 39 This parser expression will be returned from <a class="link" href="../../../qi/reference/parse_api/create_parser.html" title="API for Automatic Parser Creation"><code class="computeroutput"><span class="identifier">create_parser</span></code></a> whenever the given 40 data type is encountered. 41 </p> 42<h6> 43<a name="spirit.advanced.customize.auto.create_parser.h1"></a> 44 <span class="phrase"><a name="spirit.advanced.customize.auto.create_parser.module_headers"></a></span><a class="link" href="create_parser.html#spirit.advanced.customize.auto.create_parser.module_headers">Module 45 Headers</a> 46 </h6> 47<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/qi/auto.hpp></span> 48<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> 49</pre> 50<p> 51 Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>. 52 </p> 53<h6> 54<a name="spirit.advanced.customize.auto.create_parser.h2"></a> 55 <span class="phrase"><a name="spirit.advanced.customize.auto.create_parser.namespace"></a></span><a class="link" href="create_parser.html#spirit.advanced.customize.auto.create_parser.namespace">Namespace</a> 56 </h6> 57<div class="informaltable"><table class="table"> 58<colgroup><col></colgroup> 59<thead><tr><th> 60 <p> 61 Name 62 </p> 63 </th></tr></thead> 64<tbody><tr><td> 65 <p> 66 <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></code> 67 </p> 68 </td></tr></tbody> 69</table></div> 70<h6> 71<a name="spirit.advanced.customize.auto.create_parser.h3"></a> 72 <span class="phrase"><a name="spirit.advanced.customize.auto.create_parser.synopsis"></a></span><a class="link" href="create_parser.html#spirit.advanced.customize.auto.create_parser.synopsis">Synopsis</a> 73 </h6> 74<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Enable</span><span class="special">></span> 75<span class="keyword">struct</span> <span class="identifier">create_parser</span> 76<span class="special">{</span> 77 <span class="keyword">typedef</span> <span class="special"><</span><span class="identifier">unspecified</span><span class="special">></span> <span class="identifier">type</span><span class="special">;</span> 78 <span class="keyword">static</span> <span class="identifier">type</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">call</span><span class="special">();</span> 79<span class="special">};</span> 80</pre> 81<h6> 82<a name="spirit.advanced.customize.auto.create_parser.h4"></a> 83 <span class="phrase"><a name="spirit.advanced.customize.auto.create_parser.template_parameters"></a></span><a class="link" href="create_parser.html#spirit.advanced.customize.auto.create_parser.template_parameters">Template 84 parameters</a> 85 </h6> 86<div class="informaltable"><table class="table"> 87<colgroup> 88<col> 89<col> 90<col> 91</colgroup> 92<thead><tr> 93<th> 94 <p> 95 Parameter 96 </p> 97 </th> 98<th> 99 <p> 100 Description 101 </p> 102 </th> 103<th> 104 <p> 105 Default 106 </p> 107 </th> 108</tr></thead> 109<tbody> 110<tr> 111<td> 112 <p> 113 <code class="computeroutput"><span class="identifier">T</span></code> 114 </p> 115 </td> 116<td> 117 <p> 118 The type, <code class="computeroutput"><span class="identifier">T</span></code> 119 for which a custom mapping to a parser should be established. 120 </p> 121 </td> 122<td> 123 <p> 124 none 125 </p> 126 </td> 127</tr> 128<tr> 129<td> 130 <p> 131 <code class="computeroutput"><span class="identifier">Enable</span></code> 132 </p> 133 </td> 134<td> 135 <p> 136 Helper template parameter usable to selectively enable or disable 137 certain specializations of <code class="computeroutput"><span class="identifier">create_generator</span></code> 138 utilizing SFINAE (i.e. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">enable_if</span></code> 139 or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">disable_if</span></code>). 140 </p> 141 </td> 142<td> 143 <p> 144 <code class="computeroutput"><span class="keyword">void</span></code> 145 </p> 146 </td> 147</tr> 148</tbody> 149</table></div> 150<div class="variablelist"> 151<p class="title"><b>Notation</b></p> 152<dl class="variablelist"> 153<dt><span class="term"><code class="computeroutput"><span class="identifier">T</span></code></span></dt> 154<dd><p> 155 An arbitrary type. 156 </p></dd> 157</dl> 158</div> 159<h6> 160<a name="spirit.advanced.customize.auto.create_parser.h5"></a> 161 <span class="phrase"><a name="spirit.advanced.customize.auto.create_parser.expression_semantics"></a></span><a class="link" href="create_parser.html#spirit.advanced.customize.auto.create_parser.expression_semantics">Expression 162 Semantics</a> 163 </h6> 164<div class="informaltable"><table class="table"> 165<colgroup> 166<col> 167<col> 168</colgroup> 169<thead><tr> 170<th> 171 <p> 172 Expression 173 </p> 174 </th> 175<th> 176 <p> 177 Semantics 178 </p> 179 </th> 180</tr></thead> 181<tbody> 182<tr> 183<td> 184 <p> 185 <code class="computeroutput"><span class="identifier">create_parser</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">type</span></code> 186 </p> 187 </td> 188<td> 189 <p> 190 Defines the type of the parser expression returned from <code class="computeroutput"><span class="identifier">call</span></code>. 191 </p> 192 </td> 193</tr> 194<tr> 195<td> 196 <p> 197 <code class="computeroutput"><span class="identifier">create_parser</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">call</span><span class="special">()</span></code> 198 </p> 199 </td> 200<td> 201 <p> 202 Returns a parser expression (usually this is a proto::expression) 203 to be used as the default parser for the given type, <code class="computeroutput"><span class="identifier">T</span></code>. 204 </p> 205 </td> 206</tr> 207</tbody> 208</table></div> 209<h6> 210<a name="spirit.advanced.customize.auto.create_parser.h6"></a> 211 <span class="phrase"><a name="spirit.advanced.customize.auto.create_parser.predefined_specializations"></a></span><a class="link" href="create_parser.html#spirit.advanced.customize.auto.create_parser.predefined_specializations">Predefined 212 Specializations</a> 213 </h6> 214<p> 215 <a href="http://boost-spirit.com" target="_top">Spirit</a> predefines specializations 216 of this customization point for several types. All predefined mappings 217 are listed here: <a class="link" href="../../../qi/reference/auto.html#spirit.qi.reference.auto.additional_requirements">Additional 218 Attribute Requirements for Parsers</a>. 219 </p> 220<div class="note"><table border="0" summary="Note"> 221<tr> 222<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 223<th align="left">Note</th> 224</tr> 225<tr><td align="left" valign="top"><p> 226 It is possible to overload the predefined mappings for the listed types 227 by providing your own specialization of the <code class="computeroutput"><span class="identifier">create_parser</span></code> 228 customization point for the type to modify. 229 </p></td></tr> 230</table></div> 231<h6> 232<a name="spirit.advanced.customize.auto.create_parser.h7"></a> 233 <span class="phrase"><a name="spirit.advanced.customize.auto.create_parser.when_to_implement"></a></span><a class="link" href="create_parser.html#spirit.advanced.customize.auto.create_parser.when_to_implement">When 234 to implement</a> 235 </h6> 236<p> 237 The customization point <code class="computeroutput"><span class="identifier">create_parser</span></code> 238 needs to be implemented for a specific type whenever this type should 239 be usable with the API function <a class="link" href="../../../qi/reference/parse_api/create_parser.html" title="API for Automatic Parser Creation"><code class="computeroutput"><span class="identifier">create_parser</span></code></a> (which includes 240 using the <code class="computeroutput"><span class="identifier">qi</span><span class="special">::</span><span class="identifier">auto_</span></code> parser and the special API functions 241 based on the automatic creation of the matching parser type). 242 </p> 243<h6> 244<a name="spirit.advanced.customize.auto.create_parser.h8"></a> 245 <span class="phrase"><a name="spirit.advanced.customize.auto.create_parser.example"></a></span><a class="link" href="create_parser.html#spirit.advanced.customize.auto.create_parser.example">Example</a> 246 </h6> 247<p> 248 For an example of how to use the customization point <code class="computeroutput"><span class="identifier">create_parser</span></code> 249 please see here: <a class="link" href="../../../qi/reference/auto.html#spirit.qi.reference.auto.example">Example 250 for Using the <code class="computeroutput"><span class="identifier">qi</span><span class="special">::</span><span class="identifier">auto_</span></code> Parser</a>. 251 </p> 252</div> 253<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 254<td align="left"></td> 255<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 256 Distributed under the Boost Software License, Version 1.0. (See accompanying 257 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>) 258 </p> 259</div></td> 260</tr></table> 261<hr> 262<div class="spirit-nav"> 263<a accesskey="p" href="../auto.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../auto.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="create_generator.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 264</div> 265</body> 266</html> 267