Welcome to Spirit

Spirit is a set of C++ libraries for parsing and output generation implemented as Domain Specific Embedded Languages (DSEL) using Expression templates and Template Meta-Programming. The Spirit libraries enable a target grammar to be written exclusively in C++. Inline grammar specifications can mix freely with other C++ code and, thanks to the generative power of C++ templates, are immediately executable.

Spirit is part of Boost Libraries, a peer-reviewed, open collaborative development effort.

Sep ’14 03

Spirit.Qi numeric parsers are the fastest in the world of C++ and surpasses even hand-written low level parsers such as atoi and atof written in C. This is old news actually. The numeric parsers are highly optimised from the very start, when I started writing Spirit V2. The tests were written in 2009, yet are still very relevant now. Here are the benchmark results from the same tests I ran today on a Mac using Clang. The benchmark code is in Github (qi/workbench):

Integer tests

atoi_test:  4.7452590000 [s] {checksum: 213ce33a}
strtol_test: 4.5116520000 [s] {checksum: 213ce33a}
spirit_int_test: 1.4126110000 [s] {checksum: 213ce33a}

Double Tests

atof_test: 3.2435210000 [s] {checksum: 84a4f7d}
strtod_test: 3.1327660000 [s] {checksum: 84a4f7d}
spirit_double_test: 0.7237810000 [s] {checksum: 84a4f7d}

Dec ’13 13

Boost C++… After more than a decade, I finally retired Phoenix-2 from the Boost Spirit code base. I feel sad. It’s like farewell to a good friend. Onwards to Phoenix-3.

Aug ’11 10

We’ve had a Spirit IRC channel for a few months now. It started out as a semi-private channel. Well, we made it officially public now. You can get Spirit support via the ##spirit or #boost IRC channels at freenode, where you will often find knowledgeable people willing to help with your Spirit questions. The #boost channel is for anything Boost related, including Spirit. The ##spirit channel is solely for Spirit and Spirit related libraries (Fusion, Phoenix and Wave).

See you there!

Jul ’11 24

Spirit is 10 years old!

It’s hard to pinpoint exactly the birthday of Spirit. Looking back, Spirit 1.0 which was uploaded to SourceForge in July 27, 2001 contains this comment in its main header file:

8/28/1999    Original Implementation [ run time polymorphic version ] (JDG)
4/30/2001    Template meta-programming implementation (JDG)
5/13/2001    Major redesign using iterators (JDG)
5/26/2001    Port to G++3.0 and BCC 5.5.1 thanks to Vladimir Prus
5/27/2001    Bug fixes in Difference and Xor classes (JDG)
5/30/2001    Added Iterators (JDG)

Continue reading »

Jul ’11 12

Spirit V2.5 is now available as part of the recently released Boost V1.47. I suggest you look at the What’s New documentation page for a list of things changed. This is a very important release for Spirit, mostly in the area of feature consolidation and less so by adding new functionality. It brings a lot of unification and quite some speedup in the area of attribute handling, both for parsers (Qi) and generators (Karma). Most of the newly added features are in the area of unification of the overall user experience as well. The things added to the Lexer should finally resolve some long standing requests. Most importantly, we are very excited about having added full compatibility with the newly released Phoenix V3 library.

Generally, all changes are supposed to be fully backwards compatible. If you run into problems with your existing code, please tell us by leaving a comment or by sending a message to the Spirit mailing list (as described on our Support page).

Tagged with:
Jun ’11 08

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’s one one that’s relevant to Spirit: “Spirit.Qi in the Real World”, by Robert Stewart. Watch the presentation here:


You can find the slides here: https://github.com/boostcon/2011_presentations/raw/master/tue/spirit_qi_in_the_real_world.pdf

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 “the devil is in the details.” 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.

Tagged with:
Apr ’11 16

The keyword parser construct has recently been added to spirit’s repository (available in 1.47 or from svn) . Here’s a small introduction to help you get started using the keyword parsers.

Those of you familiar with the Nabialek trick will recognize it’s working under the hood. What you can achieve with the keywords parser can also be achieved with the Nabialek trick but not always as elegantly or as efficiently.

Continue reading »

Mar ’11 18

Somewhere over the past days we crossed a major milestone with Spirit’s website. Granted, it went by unnoticed, but we celebrated our 300,000 visitor since the launch of the new website in November 2009! As you can see from the Google analytics plot below, the average number of daily visitors stayed pretty constant over the last year, showing a slight increase lately.

I find it to be very encouraging that the average time people spend on the Spirit site is over 6 minutes. Compared to other websites (even purely technical ones), this number is huge. It is an indication that the contents we try to provide are useful and interesting to our visitors.


Continue reading »

Feb ’11 26

Frank Dellaert was asking a valid question on the Spirit mailing list where he pointed out some things he was not able to understand. His question clearly uncovered an inconsistency in Spirit’s API. This lead us to implement some minor additional feature, which in the end turned out to make more uniform the way semantic actions are handled.

Continue reading »

Tagged with:
Jan ’11 19

You might have wondered where do all those names like Spirit, Qi, or Karma come from? Well, Joachim Faulhaber gave the explanation on the Boost mailing list yesterday:

because xpressive names have a better spirit, bring qi to your software and will enhance your karma so they can heal your (con)fusion and make you wave like a phoenix from the ashes.

This is simply brilliant and I thought to share it with you! Smile

Dec ’10 24

The year 2010 will soon come to an end. This is reason enough to look at the statistics collected for our website and to publish a list of the most popular posts and articles. I will use the number of hits as a metric of popularity. But first a couple of overall statistics.

  • To date, we have had 203,233 page views on this website, that’s an average of 569 a day. If you add the documentation, we saw an overall number of page views of 1,289,260, amounting to an daily average of 3,611! Simply amazing!
  • The most visitors came from the U.S.A. (53,237 visits, 313,566 page views), followed by Germany (27,391 visits, 154,759 page views), Russia (15,509 visits, 79,406 page views), France (15,436 visits, 89,528 page views), and United Kingdom (14,615 visits, 90,467 page views).
  • We deleted 15,147 spam comments, where the spam is growing at an ever increasing speed. Hah, the spam bots are getting to know Spirit‘s website! That’s actually good news.

Thanks to everybody for your support!

Overall, we published 33 new posts. Here are the most popular ones:

I’m very happy to see that the articles showing how to use Spirit for specific tasks draw a lot of attention. You might want to get back to those and re-read them (and all the others as well).

Last but not least, on behalf of Joel and myself, let me express our gratitude for all the support we received over the last year. We have a lot of ideas how to improve Spirit and we will continue to need your help in the future. Stay tuned!

Merry Christmas and a Happy New Year to you all!

Oct ’10 14

Care about how Spirit got started? Here’s a link to our BoostCon 2010 presentation:


This year, we celebrate Spirit’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 “Is there interest in this library?” 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.
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’s worth of experience being Boost authors and bonafide crazy template metaprogrammers who abuse operators like Mad Scientists. Of course, we can’t help it if we show off some C++ tricks here and there, but we’ll try to keep it as light as we can.

Tagged with:
Mar ’10 09

Tino Didriksin published yet another speed comparison of different ways to convert an integer into a string (see his blog A howl on the Wind…). And again, Karma turns out to be the leader of the pack by being upto 10 times faster than the other tested methods. This nicely supports our own measurements (see here). Thanks Tino!

Tagged with:
Mar ’10 03

The concept of Spirit’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 straighforward to grasp. Earlier versions of Spirit required a semantic action to conform to a very specific interface. Today’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 Spirit Qi.

Continue reading »

Tagged with:
Feb ’10 05

Promising to be the main face-to-face event for all things Boost, BoostCon 2010 opens the door to your C++ future. From using the Boost libraries to writing and maintaining them, from evangelizing to deploying Boost within your organization, from infrastructure and process to vision and mission, and from TR1 to TR2, BoostCon brings together the sessions, the colleagues, and the inspiration to support your work with Boost for the next year.

To reflect the breadth of the Boost community, the conference includes sessions aimed at two constituencies: Boost end-users and hard-core Boost library and tool developers. The program fosters interaction and engagement within and across those two groups, with an emphasis on hands-on, participatory sessions.

Continue reading »

preload preload preload