1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Attribute Parser (attr)</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="../auxiliary.html" title="Auxiliary Parsers"> 9<link rel="prev" href="../auxiliary.html" title="Auxiliary Parsers"> 10<link rel="next" href="attr_cast.html" title="Attribute Transformation Pseudo Parser (attr_cast)"> 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="../auxiliary.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../auxiliary.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="attr_cast.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.auxiliary.attr"></a><a class="link" href="attr.html" title="Attribute Parser (attr)">Attribute Parser 28 (<code class="computeroutput"><span class="identifier">attr</span></code>)</a> 29</h5></div></div></div> 30<h6> 31<a name="spirit.qi.reference.auxiliary.attr.h0"></a> 32 <span class="phrase"><a name="spirit.qi.reference.auxiliary.attr.description"></a></span><a class="link" href="attr.html#spirit.qi.reference.auxiliary.attr.description">Description</a> 33 </h6> 34<p> 35 The Attribute parser does not consume any input, for this reason it always 36 matches an empty string and always succeeds. It's purpose is to expose 37 its specified parameter as an attribute. 38 </p> 39<h6> 40<a name="spirit.qi.reference.auxiliary.attr.h1"></a> 41 <span class="phrase"><a name="spirit.qi.reference.auxiliary.attr.header"></a></span><a class="link" href="attr.html#spirit.qi.reference.auxiliary.attr.header">Header</a> 42 </h6> 43<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/qi/auxiliary/attr.hpp></span> 44<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_attr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 45</pre> 46<p> 47 Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>. 48 </p> 49<h6> 50<a name="spirit.qi.reference.auxiliary.attr.h2"></a> 51 <span class="phrase"><a name="spirit.qi.reference.auxiliary.attr.namespace"></a></span><a class="link" href="attr.html#spirit.qi.reference.auxiliary.attr.namespace">Namespace</a> 52 </h6> 53<div class="informaltable"><table class="table"> 54<colgroup><col></colgroup> 55<thead><tr><th> 56 <p> 57 Name 58 </p> 59 </th></tr></thead> 60<tbody><tr><td> 61 <p> 62 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">attr</span> <span class="comment">// alias: 63 boost::spirit::qi::attr</span></code> 64 </p> 65 </td></tr></tbody> 66</table></div> 67<h6> 68<a name="spirit.qi.reference.auxiliary.attr.h3"></a> 69 <span class="phrase"><a name="spirit.qi.reference.auxiliary.attr.model_of"></a></span><a class="link" href="attr.html#spirit.qi.reference.auxiliary.attr.model_of">Model 70 of</a> 71 </h6> 72<div class="blockquote"><blockquote class="blockquote"><p> 73 <a class="link" href="../parser_concepts/primitiveparser.html" title="PrimitiveParser"><code class="computeroutput"><span class="identifier">PrimitiveParser</span></code></a> 74 </p></blockquote></div> 75<div class="variablelist"> 76<p class="title"><b>Notation</b></p> 77<dl class="variablelist"> 78<dt><span class="term"><code class="computeroutput"><span class="identifier">a</span></code></span></dt> 79<dd><p> 80 A arbitrary typed constant value, e.g. 0.0, "Hello", 81 or a variable of arbitrary type or a <a class="link" href="../basics.html#spirit.qi.reference.basics.lazy_argument">Lazy 82 Argument</a> that evaluates to an arbitrary type. 83 </p></dd> 84<dt><span class="term"><code class="computeroutput"><span class="identifier">A</span></code></span></dt> 85<dd><p> 86 The type of <code class="computeroutput"><span class="identifier">a</span></code> or 87 if it is a <a class="link" href="../basics.html#spirit.qi.reference.basics.lazy_argument">Lazy 88 Argument</a>, its return type. 89 </p></dd> 90</dl> 91</div> 92<h6> 93<a name="spirit.qi.reference.auxiliary.attr.h4"></a> 94 <span class="phrase"><a name="spirit.qi.reference.auxiliary.attr.expression_semantics"></a></span><a class="link" href="attr.html#spirit.qi.reference.auxiliary.attr.expression_semantics">Expression 95 Semantics</a> 96 </h6> 97<p> 98 Semantics of an expression is defined only where it differs from, or 99 is not defined in <a class="link" href="../parser_concepts/primitiveparser.html" title="PrimitiveParser"><code class="computeroutput"><span class="identifier">PrimitiveParser</span></code></a>. 100 </p> 101<div class="informaltable"><table class="table"> 102<colgroup> 103<col> 104<col> 105</colgroup> 106<thead><tr> 107<th> 108 <p> 109 Expression 110 </p> 111 </th> 112<th> 113 <p> 114 Semantics 115 </p> 116 </th> 117</tr></thead> 118<tbody><tr> 119<td> 120 <p> 121 <code class="computeroutput"><span class="identifier">attr</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span></code> 122 </p> 123 </td> 124<td> 125 <p> 126 Create a pseudo parser exposing the current value of <code class="computeroutput"><span class="identifier">a</span></code> as its attribute without 127 consuming any input at parse time. 128 </p> 129 </td> 130</tr></tbody> 131</table></div> 132<h6> 133<a name="spirit.qi.reference.auxiliary.attr.h5"></a> 134 <span class="phrase"><a name="spirit.qi.reference.auxiliary.attr.attributes"></a></span><a class="link" href="attr.html#spirit.qi.reference.auxiliary.attr.attributes">Attributes</a> 135 </h6> 136<div class="informaltable"><table class="table"> 137<colgroup> 138<col> 139<col> 140</colgroup> 141<thead><tr> 142<th> 143 <p> 144 Expression 145 </p> 146 </th> 147<th> 148 <p> 149 Attribute 150 </p> 151 </th> 152</tr></thead> 153<tbody><tr> 154<td> 155 <p> 156 <code class="computeroutput"><span class="identifier">attr</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span></code> 157 </p> 158 </td> 159<td> 160 <p> 161 <code class="computeroutput"><span class="identifier">A</span></code> 162 </p> 163 </td> 164</tr></tbody> 165</table></div> 166<h6> 167<a name="spirit.qi.reference.auxiliary.attr.h6"></a> 168 <span class="phrase"><a name="spirit.qi.reference.auxiliary.attr.complexity"></a></span><a class="link" href="attr.html#spirit.qi.reference.auxiliary.attr.complexity">Complexity</a> 169 </h6> 170<div class="blockquote"><blockquote class="blockquote"><p> 171 O(1) 172 </p></blockquote></div> 173<p> 174 The complexity is constant as no input is consumed and no matching is 175 done. 176 </p> 177<h6> 178<a name="spirit.qi.reference.auxiliary.attr.h7"></a> 179 <span class="phrase"><a name="spirit.qi.reference.auxiliary.attr.example"></a></span><a class="link" href="attr.html#spirit.qi.reference.auxiliary.attr.example">Example</a> 180 </h6> 181<div class="note"><table border="0" summary="Note"> 182<tr> 183<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 184<th align="left">Note</th> 185</tr> 186<tr><td align="left" valign="top"><p> 187 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> 188 section. 189 </p></td></tr> 190</table></div> 191<p> 192 Some using declarations: 193 </p> 194<p> 195</p> 196<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">phx</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">;</span> 197<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">attr</span><span class="special">;</span> 198</pre> 199<p> 200 </p> 201<p> 202 Using <code class="computeroutput"><span class="identifier">attr</span></code> with literals: 203 </p> 204<p> 205</p> 206<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">str</span><span class="special">;</span> 207<span class="identifier">test_parser_attr</span><span class="special">(</span><span class="string">""</span><span class="special">,</span> <span class="identifier">attr</span><span class="special">(</span><span class="string">"boost"</span><span class="special">),</span> <span class="identifier">str</span><span class="special">);</span> 208<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">str</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// will print 'boost'</span> 209 210<span class="keyword">double</span> <span class="identifier">d</span><span class="special">;</span> 211<span class="identifier">test_parser_attr</span><span class="special">(</span><span class="string">""</span><span class="special">,</span> <span class="identifier">attr</span><span class="special">(</span><span class="number">1.0</span><span class="special">),</span> <span class="identifier">d</span><span class="special">);</span> 212<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">d</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// will print '1.0'</span> 213</pre> 214<p> 215 </p> 216<p> 217 Using <code class="computeroutput"><span class="identifier">attr</span></code> with <a href="../../../../../../../../libs/phoenix/doc/html/index.html" target="_top">Boost.Phoenix</a> function 218 objects: 219 </p> 220<p> 221</p> 222<pre class="programlisting"><span class="identifier">d</span> <span class="special">=</span> <span class="number">0.0</span><span class="special">;</span> 223<span class="keyword">double</span> <span class="identifier">d1</span> <span class="special">=</span> <span class="number">1.2</span><span class="special">;</span> 224<span class="identifier">test_parser_attr</span><span class="special">(</span><span class="string">""</span><span class="special">,</span> <span class="identifier">attr</span><span class="special">(</span><span class="identifier">phx</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span><span class="identifier">d1</span><span class="special">)),</span> <span class="identifier">d</span><span class="special">);</span> 225<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">d</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// will print '1.2'</span> 226</pre> 227<p> 228 </p> 229</div> 230<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 231<td align="left"></td> 232<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 233 Distributed under the Boost Software License, Version 1.0. (See accompanying 234 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>) 235 </p> 236</div></td> 237</tr></table> 238<hr> 239<div class="spirit-nav"> 240<a accesskey="p" href="../auxiliary.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../auxiliary.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="attr_cast.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 241</div> 242</body> 243</html> 244