Porting Spirit 2.0 (beta) to Spirit 2.1

Spirit 2 has undergone lots of revisions from its inception to what you are seeing now. An early beta  release, dubbed Spirit 2 beta, was included as part of Boost 1.39. The adventurous among you started using it as soon as it was released. Spirit 2.1 is essentially the same as Spirit2 beta apart from some cosmetic differences and QOI changes. For the sake of those who started using Spirit from 2.0 beta, here’s what’s changed:

  1. Namespace spirit::arg_names ceased to exist. All the placeholders (_0…_N, _r1…_rN, _val, _a…_j) are now in boost::spirit.
  2. Components in boost::spirit that are used by qi (and karma) are hoisted into qi and karma. So, you don’t have to memorize which component lives in boost::spirit::qi (or karma) or the outer boost::spirit namespace. Example:
    using boost::spirit::qi::int_;
    using boost::spirit::qi::lit;
    using boost::spirit::qi::unused_type;
    using boost::spirit::qi::_1;
    using boost::spirit::qi::omit;
  3. There are multiple versions of char_ and no_case in different “char encoding” namespaces. For example, there is boost::spirit::ascii::char_ and boost::spirit::iso8859_1::char_.
  4. wchar ceases to exist. Use standard_wide::char_ instead.
  5. xxx(f) where xxx is a spirit parser and  f is a callable function, is possible everywhere. for example: char_(phoenix::var(ch)).
  6. repeat, repeat(from, to), repeat(from, inf) is implemented.
  7. All traits are in spirit::traits. There is no spirit::qi::traits.
  8. Error handling now uses the spirit::info class instead of std::string for the “what” part. There’s support for printing out the info (i.e. operator<<) so, code should run as usual. spirit::info is UTF8 savvy, with additional features to make it easy and more powerful to provide error messages.
  9. Changed parameter sequence of qi::phrase_parse, qi::phrase_match, karma::generate_delimited, and match_delimited. The attribute is now always the last parameter.

The list above enumerates the most important changes you need to know in order to port your Spirit 2.0 beta code over to Spirit 2.1. There are more smaller details here and there. For more info see: What’s New.

One Response to “Porting Spirit 2.0 (beta) to Spirit 2.1”

  1. hauns says:

    [copied here from the gmane.spirit list]

    here a little report for those interested. now that my prototype works fine with spirit 2.1 (b1.41) – thanks to all for your helpful comments – i had the daunting task of integrating it into a larger project that was still on spirit 2.0 (b1.39).

    disclaimer: i am well aware that this is not particularly a best practice. the spirit websites emphasizes that b1.41 spirit headers can happily coexist with boost installations from version 1.37 onwards.

    anyhow here i go with a few observations:

    1 namespaces have changed:

    #include <boost/spirit/version.hpp>
      namespace qi = boost::spirit::qi;   
    #if SPIRIT_VERSION == 0x2000                // namespaces for spirit 2.0 (boost 1.39)
      namespace xi = boost::spirit::arg_names;  // _val, _1, _a
      namespace yi = boost::spirit;             // char_, double_, raw, lexeme, 
                                                // lit, locals
      namespace xi = qi;                        // spirit 2.1 (boost 1.41)
      namespace yi = qi;                        // everything's qi
      namespace ascii = boost::spirit::ascii;

    2 pizza bug?
    the spirit dev team dutifully defines a new favorite pizza for each version:

      #define SPIRIT_VERSION 0x2010

    however preproc conditions based on this – albeit funny – won’t work




    was available in version.hpp, too.

    b1.41 is much more forgiving with raw/lexeme parsers
    this statement work fine without raw in b1.41 but not in b1.39
    identifier %= raw[lexeme[ (ascii::alpha | ‘_’) >> *(ascii::alnum | ‘_’)]];

    phrase_parse() has args three and four switched

    *char_(“A-Z_”) would just not work in b1.39.
    i had to expand it to: *(char_(‘A’,’Z’) | char_(‘_’)). curiously, char_(“A-Z_”) worked fine.

Leave a Reply

preload preload preload