<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Boost.Spirit &#187; Beginner</title>
	<atom:link href="http://boost-spirit.com/home/category/experience-level/beginner/feed/" rel="self" type="application/rss+xml" />
	<link>http://boost-spirit.com/home</link>
	<description>Home of The Boost.Spirit Library</description>
	<lastBuildDate>Sun, 04 Dec 2011 22:11:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Phoenix V3 – An Overview</title>
		<link>http://boost-spirit.com/home/2011/06/08/phoenix-v3-%e2%80%93-an-overview/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=phoenix-v3-%25e2%2580%2593-an-overview</link>
		<comments>http://boost-spirit.com/home/2011/06/08/phoenix-v3-%e2%80%93-an-overview/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 21:36:05 +0000</pubDate>
		<dc:creator>Joel de Guzman</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Boost Con 2011]]></category>
		<category><![CDATA[BoostCon]]></category>
		<category><![CDATA[Experience Level]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Phoenix]]></category>

		<guid isPermaLink="false">http://boost-spirit.com/home/?p=1498</guid>
		<description><![CDATA[Here&#8217;s another BoostCon video uploaded by Marshall Clow. This one is about Phoenix V3, by Hartmut Kaiser: http://blip.tv/boostcon/phoenix-v3-an-overview-5250984 The slides for this talk can be found here: https://github.com/boostcon/2011_presentations/blob/master/mon/phoenix_v3.pdf?raw=true. Phoenix will be the next generation of creating unnamed, inlined polymorphic function objects. With V3 we combine the functionality of Boost.Bind and Boost.Lambda, and arranges it into [...]<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (2 votes cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s another BoostCon video uploaded by Marshall Clow. This one is about Phoenix V3, by Hartmut Kaiser:</p>
<p><a href="http://blip.tv/boostcon/phoenix-v3-an-overview-5250984">http://blip.tv/boostcon/phoenix-v3-an-overview-5250984</a></p>
<p>The slides for this talk can be found here: <a rel="nofollow" href="https://github.com/boostcon/2011_presentations/blob/master/mon/phoenix_v3.pdf?raw=true">https://github.com/boostcon/2011_presentations/blob/master/mon/phoenix_v3.pdf?raw=true</a>.</p>
<blockquote><p>Phoenix will be the next generation of creating unnamed, inlined  polymorphic function objects. With V3 we combine the functionality of  Boost.Bind and Boost.Lambda, and arranges it into a new library. By  writing this new library, we were able to fix some limitations of the  aforementioned libraries without breaking backwardscompatibility. The  purpose of the talk will be to outline the importance and elegance of  functional programming (FP) in C++. The first part of the talk will give  an introduction into the Domain Specific Embedded Language (DSEL) we  defined with Phoenix. A DSEL is built with the help of regular C++  function and operator overloads. For Phoenix we defined such a language  that emulates C++, to give potential users a low entry into the world of  FP. While a lot of existing C++ code relies on higher order functions  (better known as function objects), e.g. the C++ standard library use  them as a way to let users customize operations in certain algorithms.  We focus the second part of the talk on examples on how to use Phoenix  instead of writing regular function objects and how to enable your  legacy code to be used inside Phoenix expressions. However, Phoenix is  more. Phoenix is equipped with a unique (in C++) mechanism to handle the  expressions discussed in the previous sections as data. This allows us  to handle Phoenix not in the C++ standard way but in any way you like.  An overview of these mechanisms will be given in the last part of the  talk to give potential users an insight on possible future applications  that might evolve around Phoenix.</p></blockquote>
<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (2 votes cast)</div><br />]]></content:encoded>
			<wfw:commentRss>http://boost-spirit.com/home/2011/06/08/phoenix-v3-%e2%80%93-an-overview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spirit.Qi in the Real World</title>
		<link>http://boost-spirit.com/home/2011/06/08/spirit-qi-in-the-real-world/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spirit-qi-in-the-real-world</link>
		<comments>http://boost-spirit.com/home/2011/06/08/spirit-qi-in-the-real-world/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 21:34:32 +0000</pubDate>
		<dc:creator>Joel de Guzman</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Boost Con 2011]]></category>
		<category><![CDATA[BoostCon]]></category>
		<category><![CDATA[Experience Level]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Qi Example]]></category>
		<category><![CDATA[User Experience]]></category>
		<category><![CDATA[BoostCon 2011]]></category>

		<guid isPermaLink="false">http://boost-spirit.com/home/?p=1496</guid>
		<description><![CDATA[This is the first time I missed attending BoostCon (May 15-20, 2011 – Aspen, Colorado). Fortunately, for us who were not able to attend, Marshall Clow uploaded some videos. Here&#8217;s one one that&#8217;s relevant to Spirit: &#8220;Spirit.Qi in the Real World&#8221;, by Robert Stewart. Watch the presentation here: http://blip.tv/boostcon/spirit-qi-in-the-real-world-5254335 You can find the slides here: [...]<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (1 vote cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p>This is the first time I missed attending BoostCon (May 15-20, 2011 – Aspen, Colorado). Fortunately, for us who were not able to attend, Marshall Clow uploaded some videos. Here&#8217;s one one that&#8217;s relevant to Spirit: &#8220;Spirit.Qi in the Real World&#8221;, by Robert Stewart. Watch the presentation here:</p>
<p><a href="http://blip.tv/boostcon/spirit-qi-in-the-real-world-5254335">http://blip.tv/boostcon/spirit-qi-in-the-real-world-5254335</a></p>
<p>You can find the slides here: <a rel="nofollow" href="https://github.com/boostcon/2011_presentations/raw/master/tue/spirit_qi_in_the_real_world.pdf">https://github.com/boostcon/2011_presentations/raw/master/tue/spirit_qi_in_the_real_world.pdf</a></p>
<blockquote><p>Past sessions on Spirit have focused on introducing Spirit or showing  extracts of real use, intermingled with tutorial highlights. Upon  writing real Spirit.Qi parsers, however, one quickly discovers that &#8220;the  devil is in the details.&#8221; There are special cases, tricks, and idioms  that one must discover by trial and error or, perhaps, by following the  Spirit mailing list, all of which take time and may not be convenient.  In this session, we’ll walk through the development of a Spirit.Qi  parser for printf()-style format strings. The result will be a  replacement for printf() that is typesafe and efficient.</p></blockquote>
<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (1 vote cast)</div><br />]]></content:encoded>
			<wfw:commentRss>http://boost-spirit.com/home/2011/06/08/spirit-qi-in-the-real-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Attribute Propagation and Attribute Compatibility</title>
		<link>http://boost-spirit.com/home/2011/02/12/attribute-propagation-and-attribute-compatibility/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=attribute-propagation-and-attribute-compatibility</link>
		<comments>http://boost-spirit.com/home/2011/02/12/attribute-propagation-and-attribute-compatibility/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 22:15:46 +0000</pubDate>
		<dc:creator>Hartmut Kaiser</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Documentation Addendum]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Karma]]></category>
		<category><![CDATA[Qi]]></category>

		<guid isPermaLink="false">http://boost-spirit.com/home/?p=1321</guid>
		<description><![CDATA[Narinder Claire asked a seemingly innocent question on the Spirit mailing list the other day. After starting to write an answer I realized that this question is not innocent at all as it touches the very fabric of Spirit: the rules of attribute handling. Many people have a hard time to properly understand what is [...]<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (2 votes cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p>Narinder Claire asked a seemingly innocent question on the Spirit mailing list the other day. After starting to write an answer I realized that this question is not innocent at all as it touches the very fabric of Spirit: the rules of attribute handling. Many people have a hard time to properly understand what is going on in the nether regions of Spirit. More importantly, they have a hard time to understand why is Spirit implemented the way it is.</p>
<p>The new article <a href="http://boost-spirit.com/home/articles/attribute_handling/attribute-propagation-and-attribute-compatibility/">Attribute Propagation and Attribute Compatibility</a> not only answers Narinders questions but tries to explain those important concepts in more detail.</p>
<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (2 votes cast)</div><br />]]></content:encoded>
			<wfw:commentRss>http://boost-spirit.com/home/2011/02/12/attribute-propagation-and-attribute-compatibility/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Boost.Spirit V2: Qi and Karma</title>
		<link>http://boost-spirit.com/home/2010/12/03/using-boost-spirit-v2-qi-and-karma/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-boost-spirit-v2-qi-and-karma</link>
		<comments>http://boost-spirit.com/home/2010/12/03/using-boost-spirit-v2-qi-and-karma/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 04:04:46 +0000</pubDate>
		<dc:creator>Joel de Guzman</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[BoostCon 2010]]></category>
		<category><![CDATA[User Experience]]></category>
		<category><![CDATA[Karma]]></category>
		<category><![CDATA[Qi]]></category>

		<guid isPermaLink="false">http://boost-spirit.com/home/?p=1263</guid>
		<description><![CDATA[These are links to the slides and video of Michael Caisse&#8217;s BoostCon 2010 talk: slides: &#60;http://www.objectmodelingdesigns.com/boostcon10/&#62; video: &#60;http://blip.tv/file/4143337 &#62; Enjoy! Machinery, sensors, equipment, client/server communications, even file formats&#8230; Parsing and producing communication streams is everywhere you look. Often these tasks are simple or small enough to tempt ad-hoc solutions. The Spirit 2.1 library provides a [...]<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=3.5" /></div><div>Rating: 3.5/<strong>5</strong> (4 votes cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p>These are links to the slides and video of Michael Caisse&#8217;s BoostCon 2010 talk:</p>
<p>slides: <a href="http://www.objectmodelingdesigns.com/boostcon10/">&lt;http://www.objectmodelingdesigns.com/boostcon10/&gt;</a><br />
video: <a href="http://blip.tv/file/4143337">&lt;http://blip.tv/file/4143337 &gt;</a></p>
<p>Enjoy!</p>
<blockquote><p>Machinery, sensors, equipment, client/server communications, even file formats&#8230; Parsing and producing communication streams is everywhere you look. Often these tasks are simple or small enough to tempt ad-hoc solutions. The Spirit 2.1 library provides a model that is simple enough to tackle those &#8220;quick hacks&#8221; and easily scales for full-featured AST generation.</p>
<p>This session will explore real-life experiences with the parser and generator (Qi/Karma) portions of the Spirit library. As we look at various small and medium-sized parsers/generators employed in various products we will establish some &#8220;rules-of-thumb&#8221; and guidelines for tackling the parser/generator domain with Qi/Karma. The session will end with the implementation of a usable XML parser and a simplified XPath-like node extractor.</p>
<p>The session will include some lecture and a lot of tutorial. Attendees will walk away with the knowledge and tools to begin parsing and generating with Spirit Qi/Karma.</p>
<p>—Michael Caisse</p></blockquote>
<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=3.5" /></div><div>Rating: 3.5/<strong>5</strong> (4 votes cast)</div><br />]]></content:encoded>
			<wfw:commentRss>http://boost-spirit.com/home/2010/12/03/using-boost-spirit-v2-qi-and-karma/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Parsing Escaped String Input Using Spirit.Qi</title>
		<link>http://boost-spirit.com/home/2010/11/13/parsing-escaped-string-input-using-spirit-qi/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=parsing-escaped-string-input-using-spirit-qi</link>
		<comments>http://boost-spirit.com/home/2010/11/13/parsing-escaped-string-input-using-spirit-qi/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 20:28:40 +0000</pubDate>
		<dc:creator>Hartmut Kaiser</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Qi Example]]></category>
		<category><![CDATA[Qi]]></category>

		<guid isPermaLink="false">http://boost-spirit.com/home/?p=1182</guid>
		<description><![CDATA[Jeroen Habraken (a.k.a VeXocide) sent an article about parsing escaped strings using Qi, which we happily publish for everybody to read. Thanks Jeroen! Continue reading here. Rating: 4.5/5 (2 votes cast)<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=4.5" /></div><div>Rating: 4.5/<strong>5</strong> (2 votes cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p>Jeroen Habraken (a.k.a VeXocide) sent an article about parsing escaped strings using <em>Qi</em>, which we happily publish for everybody to read. Thanks Jeroen!</p>
<p>Continue reading <a href="http://boost-spirit.com/home/articles/qi-example/parsing-escaped-string-input-using-spirit-qi/">here</a>.</p>
<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=4.5" /></div><div>Rating: 4.5/<strong>5</strong> (2 votes cast)</div><br />]]></content:encoded>
			<wfw:commentRss>http://boost-spirit.com/home/2010/11/13/parsing-escaped-string-input-using-spirit-qi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Joel de Guzman, Hartmut Kaiser: Spirit: History and Evolution</title>
		<link>http://boost-spirit.com/home/2010/10/14/joel-de-guzman-hartmut-kaiser-spirit-history-and-evolution/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=joel-de-guzman-hartmut-kaiser-spirit-history-and-evolution</link>
		<comments>http://boost-spirit.com/home/2010/10/14/joel-de-guzman-hartmut-kaiser-spirit-history-and-evolution/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 18:03:35 +0000</pubDate>
		<dc:creator>Joel de Guzman</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[BoostCon 2010]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Spirit]]></category>

		<guid isPermaLink="false">http://boost-spirit.com/home/?p=1149</guid>
		<description><![CDATA[Care about how Spirit got started? Here&#8217;s a link to our BoostCon 2010 presentation: http://blip.tv/file/4245756 This year, we celebrate Spirit&#8217;s 10th anniversary from its early beginnings as an offshoot from a much larger GUI library in the 90s and debuted into Boost in May 2001 in the typical &#8220;Is there interest in this library?&#8221; fashion [...]<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (1 vote cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p>Care about how Spirit got started? Here&#8217;s a link to our BoostCon 2010 presentation:</p>
<p><a href="http://blip.tv/file/4245756">http://blip.tv/file/4245756</a></p>
<blockquote><p>This year, we celebrate Spirit&#8217;s 10th anniversary from its early beginnings as an offshoot from a much larger GUI library in the 90s and debuted into Boost in May 2001 in the typical &#8220;Is there interest in this library?&#8221; fashion like all would be Boost libraries. From a humble 7 header file library, Spirit has grown to be one of the most sophisticated Boost libraries and along the way became the incubator of other Boost libraries such as Boost.Fusion, Boost.Phoenix, and Boost.Wave and played a significant role for Boost.Proto getting mature.<br />
We would like to present Spirit (and the libraries it inspired) in a historical perspective. The presentation will aim to provide a lighter, more intimate perspective into the development of at least 4 libraries with almost a decade&#8217;s worth of experience being Boost authors and bonafide crazy template metaprogrammers who abuse operators like Mad Scientists. Of course, we can&#8217;t help it if we show off some C++ tricks here and there, but we&#8217;ll try to keep it as light as we can.</p></blockquote>
<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (1 vote cast)</div><br />]]></content:encoded>
			<wfw:commentRss>http://boost-spirit.com/home/2010/10/14/joel-de-guzman-hartmut-kaiser-spirit-history-and-evolution/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tracking the Input Position While Parsing</title>
		<link>http://boost-spirit.com/home/2010/03/05/tracking-the-input-position-while-parsing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tracking-the-input-position-while-parsing</link>
		<comments>http://boost-spirit.com/home/2010/03/05/tracking-the-input-position-while-parsing/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 16:21:53 +0000</pubDate>
		<dc:creator>Peter Schüller</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Qi Example]]></category>
		<category><![CDATA[MultiPass]]></category>
		<category><![CDATA[Qi]]></category>

		<guid isPermaLink="false">http://boost-spirit.com/home/?p=1026</guid>
		<description><![CDATA[The following article is about tracking the parsing position with Spirit V2. This is useful for generating error messages which tell the user exactly where an error has occurred. We also show how to use Spirit V2 to parse from an input stream without first reading the whole stream into a std::string. Continue reading » [...]<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (1 vote cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p>The following article is about tracking the parsing position with <em>Spirit</em> V2. This is useful for generating error messages which tell the user exactly where an error has occurred. We also show how to use <em>Spirit</em> V2 to parse from an input stream without first reading the whole stream into a std::string.</p>
<p><a href="http://boost-spirit.com/home/articles/qi-example/tracking-the-input-position-while-parsing/">Continue reading »</a></p>
<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (1 vote cast)</div><br />]]></content:encoded>
			<wfw:commentRss>http://boost-spirit.com/home/2010/03/05/tracking-the-input-position-while-parsing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Anatomy of Semantic Actions in Qi</title>
		<link>http://boost-spirit.com/home/2010/03/03/the-anatomy-of-semantic-actions-in-qi/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-anatomy-of-semantic-actions-in-qi</link>
		<comments>http://boost-spirit.com/home/2010/03/03/the-anatomy-of-semantic-actions-in-qi/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 18:04:35 +0000</pubDate>
		<dc:creator>Hartmut Kaiser</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Tip of the Day]]></category>
		<category><![CDATA[Karma]]></category>
		<category><![CDATA[Qi]]></category>

		<guid isPermaLink="false">http://boost-spirit.com/home/?p=1010</guid>
		<description><![CDATA[The concept of Spirit&#8217;s semantic actions seems to be easy enough to understand as most people new to the library prefer their usage over applying the built-in attribute propagation rules. That is not surprising. The idea of attaching a function to any point of a grammar which is called whenever the corresponding parser matched is [...]<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (7 votes cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p>The concept of <em>Spirit&#8217;s</em> semantic actions seems to be easy enough to understand as most people new to the library prefer their usage over applying the built-in attribute propagation rules. That is not surprising. The idea of attaching a function to any point of a grammar which is called whenever the corresponding parser matched is straighforward to grasp. Earlier versions of <em>Spirit</em> required a semantic action to conform to a very specific interface. Today&#8217;s semantic actions are more flexible and more powerful. Recently, a couple of people asked questions about them. So I decided dedicating this Tip of the Day to the specifics and the usage model of semantic actions in <em>Spirit Qi</em>.</p>
<p><span id="more-1010"></span></p>
<p>All three of <em>Spirit&#8217;s</em> sub-libraries &#8211; <em>Qi</em>, <em>Karma</em>, and <em>Lex</em> – support semantic actions. In each case they are different and have some specifics. Today I will highlight semantic actions in <em>Qi</em>. But I will dedicate later Tips of the Day to semantic actions in <em>Karma</em> and  <em>Lex</em>.</p>
<p>Semantic actions are functions or function objects attached to some specific part of a grammar. In <em>Qi</em> they are invoked <em>after</em> the corresponding parser successfully recognizes a portion of the input. Here the semantic action receives the attribute value of the matching parser.</p>
<h5>Semantic Actions – a General View</h5>
<p>A semantic action <span style="font-family: Courier New;">f</span> are attached to a <em>Qi</em> parser <span style="font-family: Courier New;">p</span> by simply writing:</p>
<pre class="brush: cpp; title: ; notranslate">
p[f]
</pre>
<p>The function (or function object) <span style="font-family: Courier New;">f</span> has to expose a certain interface allowing <em>Spirit</em> to pass the proper argument types. In the simplest case this can be a global function taking no arguments at all.</p>
<pre class="brush: cpp; title: ; notranslate">
void func()
{
    std::cout &lt;&lt; &quot;Matched an integer!\n&quot;;
}

std::string input(&quot;1234&quot;);
std::string::const_iterator begin = input.begin();
std::string::const_iterator end = input.end();
qi::parse(begin, end, qi::int_[func]);     // this will call func
</pre>
<p>Most of the time this is not sufficient as a semantic action is expected to receive the matched attribute value. This is possible by writing:</p>
<pre class="brush: cpp; title: ; notranslate">
void func(int attribute)
{
    std::cout &lt;&lt; &quot;Matched integer: &quot; &lt;&lt; attribute &lt;&lt; &quot;\n&quot;;
}
</pre>
<p>The type of the expected parameter (in this case the <span style="font-family: Courier New;">int</span>) depends on the parser the semantic action is attached to. The attribute type exposed by the parser has to be convertible to the argument type.</p>
<p>There are actually 2 more arguments being passed: the parser context and a reference to a boolean &#8216;hit&#8217; parameter. The parser context is meaningful only if the semantic action is attached somewhere to the right hand side of a rule. We will see more information about this shortly. The boolean value can be set to false inside the semantic action invalidating the match in retrospective, making the parser fail. <em>Qi</em> allows us to bind a nullary or a single argument function, like above. The other arguments are simply ignored.</p>
<p>It is feasible to bind any function object (such as generated by <a href="http://www.boost.org/doc/libs/1_42_0/libs/bind/index.html">Boost.Bind</a> or <a href="http://www.boost.org/doc/libs/1_42_0/libs/lambda/index.html">Boost.Lambda</a>) as an semantic action. Even if the documentation shows a couple of examples (see <a href="http://www.boost.org/doc/libs/1_42_0/libs/spirit/doc/html/spirit/qi/tutorials/semantic_actions.html#spirit.qi.tutorials.semantic_actions.examples_of_semantic_actions">here</a>), I would not recommend using those libraries in this context. For me the preferred method of writing semantic actions is to employ <a href="http://www.boost.org/doc/libs/1_42_0/libs/spirit/phoenix/doc/html/index.html">Boost.Phoenix</a> &#8211; a companion library bundled with <em>Spirit</em>. It is like <a href="http://www.boost.org/libs/lambda/index.html">Boost.Lambda</a> on steroids, with special custom features that make it easy to integrate semantic actions with Spirit. If your requirements go beyond simple parsing, I suggest that you use this library. All the following examples in this article will use <a href="http://www.boost.org/phoenix/doc/html/index.html">Boost.Phoenix</a> for semantic actions. But whatever method you use, please let me highlight the following:</p>
<blockquote><p>The three libraries allow you to utilize special placeholders to control parameter placement (<code>_1</code>, <code>_2</code>, etc.). Unfortunately, each of those libraries has it&#8217;s own implementation of the placeholders, all in different namespaces. You have to make sure not to mix placeholders with a library they don&#8217;t belong to and not to use different libraries while writing a semantic action.</p>
<p>Generally, for <a href="http://www.boost.org/libs/bind/index.html">Boost.Bind</a>, use <code>::_1</code>, <code>::_2</code>, etc. (yes, these placeholders are defined in the global namespace).</p>
<p>For <a href="http://www.boost.org/libs/lambda/index.html">Boost.Lambda</a> use the placeholders defined in the namespace <code>boost::lambda</code>.</p>
<p>For semantic actions written using <a href="http://www.boost.org/phoenix/doc/html/index.html">Boost.Phoenix</a> use the placeholders defined in the namespace <code>boost::spirit</code>. Please note that all existing placeholders for your convenience are also available from the namespace <code>boost::spirit::qi</code>.</p></blockquote>
<p>The current version of Spirit (V2.2) does not yet support binding a native C++0x lambda function as a semantic action, but this is something we are currently working on. You can expect this to be possible in the near future.</p>
<h5>Writing Phoenix based Semantic Actions</h5>
<p>Writing a semantic action with Phoenix is beneficial as <em>Spirit</em>  &#8216;knows&#8217; about Phoenix. If you write them with the help of Phoenix you can utilize special placeholders <em>Spirit</em> provides you with. Those placeholders refer to elements in the context of the current parser execution such as attributes, local variables and inherited attributes of rules, etc. None of the other means of writing semantic actions (using Bind, Lambda, or hand written function objects) gives you direct access to those elements. The following table lists all available placeholders exposed by Spirit (as mentioned earlier, all are defined in the namespace <span style="font-family: Courier New;">boost::spirit::qi</span>). Again, please note, these are only available inside a semantic action and only if the semantic action is written utilizing Phoenix.</p>
<table border="1" cellspacing="0" cellpadding="2" width="600">
<tbody>
<tr>
<td width="206" valign="top"><strong>Placeholder</strong></td>
<td width="394" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td width="206" valign="top"><code>_1, _2, ... , _N</code></td>
<td width="394" valign="top">Nth attribute of the parser <code>p</code></td>
</tr>
<tr>
<td width="206" valign="top">
<dt><code>_pass</code></dt>
</td>
<td width="394" valign="top">Assign <code>false</code> to <code>_pass</code> to force a generator failure.</td>
</tr>
<tr>
<td width="206" valign="top">
<dt><code>_val</code></dt>
</td>
<td width="394" valign="top">The enclosing rule&#8217;s synthesized attribute.</td>
</tr>
<tr>
<td width="206" valign="top">
<dt><code>_r1, _r2, ... , _rN</code></dt>
</td>
<td width="394" valign="top">The enclosing rule&#8217;s Nth inherited attribute.</td>
</tr>
<tr>
<td width="206" valign="top">
<dt><code>_a, _b, ... , _j</code></dt>
</td>
<td width="394" valign="top">The enclosing rule&#8217;s local variables (<code>_a</code> refers to the first).</td>
</tr>
<tr>
<td width="206" valign="top"> </td>
<td width="394" valign="top"> </td>
</tr>
</tbody>
</table>
<p>Obviously, the placeholders listed in the last three rows of the table are meaningful only if used in a rule definition. As an example, let us rewrite the semantic action from above with Phoenix:</p>
<pre class="brush: cpp; title: ; notranslate">
std::string input(&quot;1234&quot;);
std::string::const_iterator begin = input.begin();
std::string::const_iterator end = input.end();
qi::parse(begin, end,
    qi::int_
    [
        std::cout &lt;&lt; &quot;Matched integer: &quot; &lt;&lt; qi::_1 &lt;&lt; &quot;\n&quot;;
    ]
);
</pre>
<p>One problem with earlier versions of Spirit (i.e. <em>Spirit.Classic</em>) was that while parsing sequences of things it was difficult to avoid calling a semantic action prematurely. For instance, in a parser sequence of two integer parsers (<span style="font-family: Courier New;">int_[f1] &gt;&gt; &#8216;,&#8217; &gt;&gt; int_[f2]</span>) the function <span style="font-family: Courier New;">f1</span> got called immediately after the first integer matched, and even if the second integer parser would fail later on. In the current version of Spirit this is not an issue anymore as it is possible to attach a semantic action to the whole sequence while still referring to the single attributes of the different sequence elements:</p>
<pre class="brush: cpp; title: ; notranslate">
std::string input(&quot;1234,2345&quot;);
std::string::const_iterator begin = input.begin();
std::string::const_iterator end = input.end();
qi::parse(begin, end,
    (qi::int_ &gt;&gt; ',' &gt;&gt; qi::int_)
    [
        std::cout &lt;&lt; &quot;Matched integers: &quot;
              &lt;&lt; qi::_1 &lt;&lt; &quot; and &quot; &lt;&lt; qi::_2 &lt;&lt; &quot;\n&quot;;
    ]
);
</pre>
<p>Here, <span style="font-family: Courier New;">qi::_1</span> refers to the attribute matched by the first integer parser, and <span style="font-family: Courier New;">qi::_2</span> to the second one.</p>
<p>Initially I was planning to additionally describe the internal interface of a semantic action. Utilizing this interface allows you to write your own function objects and still to get access to the elements of the parser context mentioned above (attributes, the rule&#8217;s local variables and inherited attributes, etc.). But this post already got longer as anticipated, which is why I defer this discussion to a second Tip of the Day. Stay tuned!</p>
<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (7 votes cast)</div><br />]]></content:encoded>
			<wfw:commentRss>http://boost-spirit.com/home/2010/03/03/the-anatomy-of-semantic-actions-in-qi/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Parsing Skippers and Skipping Parsers</title>
		<link>http://boost-spirit.com/home/2010/02/24/parsing-skippers-and-skipping-parsers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=parsing-skippers-and-skipping-parsers</link>
		<comments>http://boost-spirit.com/home/2010/02/24/parsing-skippers-and-skipping-parsers/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 13:32:08 +0000</pubDate>
		<dc:creator>Hartmut Kaiser</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Qi Example]]></category>
		<category><![CDATA[Tip of the Day]]></category>
		<category><![CDATA[Qi]]></category>

		<guid isPermaLink="false">http://boost-spirit.com/home/?p=989</guid>
		<description><![CDATA[Spirit supports skipper based parsing since its very invention. So this is definitely not something new to Spirit V2. Nevertheless, the recent discussion on the Spirit mailing list around the semantics of Qi&#8217;s lexeme[] directive shows the need for some clarification. Today I try to answer questions like: &#8220;What does it mean to use a [...]<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (7 votes cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p><em>Spirit</em> supports skipper based parsing since its very invention. So this is definitely not something new to Spirit V2. Nevertheless, the recent discussion on the <a href="http://boost-spirit.com/home/feedback-and-support/">Spirit mailing list</a> around the semantics of <em>Qi&#8217;s</em> <span style="font-family: Courier New;">lexeme[]</span> directive shows the need for some clarification. Today I try to answer questions like: &#8220;What does it mean to use a skipper while parsing?&#8221;, or &#8220;When do I want to use a skipper and when not?&#8221;.</p>
<p><span id="more-989"></span></p>
<p>While parsing some formatted data stream it is very often desirable to ignore some parts of the input. A common example would be the need to skip whitespace and comments while parsing some computer language. Certainly it is possible to explicitly account for the tokens to skip (such as the whitespace or the comments) while writing the grammar. But this can get very tedious as those tokens are valid to appear at any point in the input.</p>
<p>For the sake of simplicity, let us assume we want to parse a simple key/value expression: <span style="font-family: Courier New;">key=value</span>, where we want to allow for any number of space characters before, in between, or after the <span style="font-family: Courier New;">key</span> or the <span style="font-family: Courier New;">value</span>. A naive grammar matching the plain key/value pair without whitespace skipping would look like (see <a href="http://boost-spirit.com/home/articles/qi-example/parsing-a-list-of-key-value-pairs-using-spirit-qi/">Parsing a List of Key-Value Pairs Using Spirit.Qi</a> for more details):</p>
<pre class="brush: cpp; title: ; notranslate">
pair  =  key &gt;&gt; '=' &gt;&gt; value;
key   =  qi::char_(&quot;a-zA-Z_&quot;) &gt;&gt; *qi::char_(&quot;a-zA-Z_0-9&quot;);
value = +qi::char_(&quot;a-zA-Z_0-9&quot;);
</pre>
<p>If we want to explicitly accommodate the rule <span style="font-family: Courier New;">pair</span> to match any interspersed space characters we get:</p>
<pre class="brush: cpp; title: ; notranslate">
pair  = *space &gt;&gt; key &gt;&gt; *space &gt;&gt; '=' *space &gt;&gt; value &gt;&gt; *space;
</pre>
<p>which, while it produces the desired result, is not only error prone, but additionally difficult to write, to understand, and to maintain. If we look closer we see, that the process of skipping the whitespace tokens is easily automated. It seems to be sufficient to insert a repeated invocation of the <span style="font-family: Courier New;">space</span> parser (or generally, any skip parser) in between the elements of the user defined parser expression sequences.</p>
<p>In fact, that is exactly what <em>Spirit</em> can do for you! The library invokes any supplied skip parser upon entry to the parse member function of any parser conforming to the <a href="http://www.boost.org/doc/libs/1_42_0/libs/spirit/doc/html/spirit/qi/reference/parser_concepts/primitiveparser.html"><span style="font-family: Courier New;">PrimitiveParser</span></a> concept. The skip parser has to be supplied by calling a special API function: <span style="font-family: Courier New;">phrase_parse:</span></p>
<pre class="brush: cpp; title: ; notranslate">
namespace qi = boost::spirit::qi;
typedef std::string::const_iterator iterator;

qi::rule&lt;iterator, qi::space_type&gt; pair = key &gt;&gt; '=' &gt;&gt; value;
qi::rule&lt;iterator&gt; key = qi::char_(&quot;a-zA-Z_&quot;) &gt;&gt; *qi::char_(&quot;a-zA-Z_0-9&quot;);
qi::rule&lt;iterator&gt; value = +qi::char_(&quot;a-zA-Z_0-9&quot;);

std::string input(&quot; key = value &quot;);
iterator_type begin = input.begin();
iterator_type end = input.end();
qi::phrase_parse(begin, end, pair, qi::space);
</pre>
<p>This code snippet illustrates several important things:</p>
<ul>
<li>The function <span style="font-family: Courier New;">qi::phrase_parse</span> is equivalent to the API function <span style="font-family: Courier New;">qi::parse</span> except for its additional parameter, the skip parser. Our example utilizes <span style="font-family: Courier New;">qi::space</span>, but it is possible to use any other, even more complex parser expression as the skipper instead.</li>
<li>All rules which we want to perform the skip parsing need to be declared with the type of the skip parser they are going to be used with. Our example specifies the type of the <span style="font-family: Courier New;">qi::space</span> parser expression, which is <span style="font-family: Courier New;">qi::space_type</span>. For more complex parser expressions you might want to use a (mini) grammar or take advantage of <span style="font-family: Courier New;">BOOST_TYPEOF</span> to let the compiler deduce the actual type.</li>
<li>All rules which should not perform skip parsing have to be declared without an additional skip parser type. These rules behave like an implicit <span style="font-family: Courier New;">lexeme[]</span> directive (for more information about <span style="font-family: Courier New;">lexeme[]</span>, see below), they inhibit the invocation of the skip parser even if they are executed as part of a rule with an associated skipper.</li>
</ul>
<p>In the example above we suppressed skipping while matching either the <span style="font-family: Courier New;">key</span> or the <span style="font-family: Courier New;">value,</span> otherwise our grammar would match any additional <span style="font-family: Courier New;">space</span> character inside the <span style="font-family: Courier New;">key</span> or <span style="font-family: Courier New;">value</span> as well. Remember, the expression <span style="font-family: Courier New;">char_</span> conforms to the <a href="http://www.boost.org/doc/libs/1_42_0/libs/spirit/doc/html/spirit/qi/reference/parser_concepts/primitiveparser.html">PrimitiveParser</a> concept, it will execute the skip parser for each of its invocations. In this case any skip parser would be executed in between any two of the matched characters.</p>
<p>Sometimes it is necessary to turn of skipping for a smaller part of the grammar only. For this purpose Spirit implements the <span style="font-family: Courier New;">lexeme[]</span> directive. This directive inhibits skipping during the execution of the embedded parser. For instance, parsing a quoted string of alphanumeric characters would look like this:</p>
<pre class="brush: cpp; title: ; notranslate">
string = lexeme['&quot;' &gt;&gt; *alnum &gt;&gt; '&quot;'];
</pre>
<p>Here the lexeme directive disables skipping while matching the string, which avoids &#8216;loosing&#8217; characters otherwise matched by the skipper. Please note: <span style="font-family: Courier New;">lexeme[]</span> performs a pre-skip step, even if it is not a <a href="http://www.boost.org/doc/libs/1_42_0/libs/spirit/doc/html/spirit/qi/reference/parser_concepts/primitiveparser.html">PrimitiveParser</a> itself (it is essentially considered to be a logical primitive by design). If this is undesired, you can utilize the <span style="font-family: Courier New;">no_skip[]</span> directive instead:</p>
<pre class="brush: cpp; title: ; notranslate">
string = '&quot;' &gt;&gt; no_skip[*alnum] &gt;&gt; '&quot;';
</pre>
<p>This parser will match all the characters in between the quotes, even if the string starts with a character sequence matched by the applied skip parser. The <span style="font-family: Courier New;">no_skip[]</span> directive is semantically equivalent to <span style="font-family: Courier New;">lexeme[]</span> except it does not perform a pre-skip before executing the embedded parser. Note: the <span style="font-family: Courier New;">no_skip[]</span> directive has been added only recently. It will be available starting with the next release (Boost V1.43).</p>
<p>This short article would not be complete without mentioning the <span style="font-family: Courier New;">skip[]</span> directive. This directive is the counterpart to <span style="font-family: Courier New;">lexeme[]</span>. It enables skipping for the embedded parser. Without any argument it can be used inside a lexeme or no_skip directive only. In this case it just re-enables the outer skipper:</p>
<pre class="brush: cpp; title: ; notranslate">
string = lexeme['&quot;' &gt;&gt; *(alpha | skip[digit]) &gt;&gt; '&quot;'];
</pre>
<p>This (purely hypothetical) parser would enable skipping inside a string as long as it matches digits. But the skip directive can do more. It may take an additional argument allowing to specify a new skipper, for instance:</p>
<pre class="brush: cpp; title: ; notranslate">
skip(qi::space)[*alnum]
</pre>
<p>which will skip spaces while executing the embedded <span style="font-family: Courier New;">*alnum</span> parser. This form of the directive can be applied for two purposes. It can be used either for changing the current skip parser or to establish skipping inside a context otherwise not doing skipping at all (even if invoked with the <span style="font-family: Courier New;">qi::parse()</span> API function).</p>
<p>For more detailed information about all the mentioned directives please see the corresponding documentation.</p>
<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (7 votes cast)</div><br />]]></content:encoded>
			<wfw:commentRss>http://boost-spirit.com/home/2010/02/24/parsing-skippers-and-skipping-parsers/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Parsing Arbitrary Things in Any Sequence</title>
		<link>http://boost-spirit.com/home/2010/02/17/parsing-arbitrary-things-in-any-sequence/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=parsing-arbitrary-things-in-any-sequence</link>
		<comments>http://boost-spirit.com/home/2010/02/17/parsing-arbitrary-things-in-any-sequence/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 15:45:25 +0000</pubDate>
		<dc:creator>Hartmut Kaiser</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Qi Example]]></category>
		<category><![CDATA[Tip of the Day]]></category>
		<category><![CDATA[Qi]]></category>

		<guid isPermaLink="false">http://boost-spirit.com/home/?p=977</guid>
		<description><![CDATA[Recently, there have been a couple of questions on the Spirit mailing list asking how to parse as set of things known in advance in any sequence and any combination. A simple example would be a list of key/value pairs with known keys but the keys may be ordered in any sequence. This use case [...]<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (1 vote cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p>Recently, there have been a couple of questions on the <em><a href="http://boost-spirit.com/home/info/mailing-list/">Spirit mailing list</a></em> asking how to parse as set of things known in advance in any sequence and any combination. A simple example would be a list of key/value pairs with known keys but the keys may be ordered in any sequence. This use case seems to be quite common. Fortunately Spirit provides you with a predefined parser component designed for exactly that purpose: the permutation parser.</p>
<p><span id="more-977"></span></p>
<p><em>Spirit&#8217;s</em> permutation parser <span style="font-family: Courier New;">a ^ b</span> matches either <span style="font-family: Courier New;">a</span>, <span style="font-family: Courier New;">b</span>, <span style="font-family: Courier New;">a &gt;&gt; b</span>, or <span style="font-family: Courier New;">b &gt;&gt; a</span>, where <span style="font-family: Courier New;">a</span> and <span style="font-family: Courier New;">b</span> can be arbitrary parser expressions. Just like normal sequences this operator can be utilized to combine more than two operands. For instance, the expression <span style="font-family: Courier New;">a ^ b ^ c</span> will match <span style="font-family: Courier New;">a</span> or <span style="font-family: Courier New;">b</span> or <span style="font-family: Courier New;">c</span> (or an combination thereof) in any sequence. The attribute propagation rule for the permutation parser is</p>
<pre class="brush: cpp; title: ; notranslate">
a: A, b: B --&gt; (a ^ b): tuple&lt;optional&lt;A&gt;, optional&lt;B&gt; &gt;
</pre>
<p>As usual, if one or more operand of the expression do not expose any attribute (expose <span style="font-family: Courier New;">unused_type</span> as their attribute, which is equivalent), this operand disappears from attribute handling:</p>
<pre class="brush: cpp; title: ; notranslate">
a: A, b: Unused --&gt; (a ^ b): optional&lt;A&gt;;
</pre>
<p>The permutation parser works out of the box whenever you do not require to match all of the elements in the input. But what if you want strict permutation (operands get matched exactly once)? You have two possibilities, as often, one simple and less versatile and one more complex but universally applicable solution. The simple solution is to parse the input and to check afterward whether all optionals in the resulting attribute have been filled. I will leave that solution as an exercise for the reader.</p>
<p>If we assume the attribute to be a (<em>Fusion</em>) tuple of optionals, containing one optional for each of the parser components in the permutation parser we can write the following code (thanks to Carl Barron for the initial idea).</p>
<p>This code defines a <em>Phoenix</em> function (a lazy function encapsulating some custom functionality) checking whether one or more of the optionals in a given <em>Fusion</em> sequence are empty. The <em>Fusion</em> algorithm <span style="font-family: Courier New;">find_if</span> iterates over the given sequence of optionals, invoking the <span style="font-family: Courier New;">option_empty::operator()</span> for each of the elements. <span style="font-family: Courier New;">fusion::find_if</span> stops iterating on the first invocation returning <span style="font-family: Courier New;">true</span> and returns the iterator to the element it stopped on. This is very similar to the well known <span style="font-family: Courier New;">std::find_if</span> algorithm.</p>
<pre class="brush: cpp; title: ; notranslate">
namespace phoenix = boost::phoenix;
namespace fusion = boost::fusion;
namespace qi = boost::spirit::qi;

class no_empties_impl
{
    // helper function object to be invoked by fusion::find_if
    struct optional_empty
    {
        template &lt;typename T&gt;
        bool operator ()(T const&amp; val) const
        {
            return !val;  // return true if 'val' is empty.
        }
    };

public:
    template &lt;typename T&gt;
    struct result { typedef bool type; };

    // This operator will get called from the semantic action attached
    // to the permutation parser. The parameter refers to its overall
    // attribute: the fusion tuple of optionals.
    template &lt;typename T&gt;
    bool operator ()(T const&amp; t) const
    {
        // look for an empty optional, if any return false.
        return fusion::find_if&lt;optional_empty&gt;(t) ==
               fusion::end(t);
    }
};

// define the Phoenix function
phoenix::function&lt;no_empties_impl&gt; const no_empties = no_empties_impl();
</pre>
<p>The overall Phoenix function <span style="font-family: Courier New;">no_empties</span> will return <span style="font-family: Courier New;">false</span> if we found at least one non-initialized optional in the passed sequence. The following code snippet illustrates how everything fits together:</p>
<pre class="brush: cpp; title: ; notranslate">
std::string input (&quot;BCA&quot;);
std::string::const_iterator begin = input.begin();
std::string::const_iterator end = input.end();
qi::parse(begin, end,
    (qi::char_('A') ^ 'B' ^ 'C')[qi::_pass = no_empties(qi::_0)]);
</pre>
<p>We assign the result of the invocation of <span style="font-family: Courier New;">no_empties</span> to Qi&#8217;s predefined placeholder <span style="font-family: Courier New;">_pass</span>. If we assign <span style="font-family: Courier New;">false</span>, then the parser the semantic action is attached to will be forced to fail in retrospective (even if it matched the input successfully before). As a result the overall parser expression will succeed as long as a) the permutation parser matches its input and b) the <em>Phoenix</em> function inside the semantic action returns <span style="font-family: Courier New;">true</span>.</p>
<p>For more information about the permutation parser please consult its documentation <a title="Permutation parser documentation" href="http://www.boost.org/doc/libs/1_41_0/libs/spirit/doc/html/spirit/qi/reference/operator/permutation.html">here</a>. Overall, this example is a bit more complex than the average parser you might usually write. It utilizes three libraries: <em>Spirit</em>, <em>Phoenix</em>, and <em>Fusion</em> in a seamless manner. But for sure, once you understand the idea, it will be easier for you to come up with similar solutions. <em>Spirit</em> has been designed with <em>Phoenix</em> and <em>Fusion</em> in mind, and in fact it relies on <em>Fusion</em> heavily itself. As a result, the integration of those libraries is almost perfect.</p>
<br /><div><img src="http://boost-spirit.com/home/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (1 vote cast)</div><br />]]></content:encoded>
			<wfw:commentRss>http://boost-spirit.com/home/2010/02/17/parsing-arbitrary-things-in-any-sequence/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

