| Home | Libraries | People | FAQ | More

##### API for Automatic Parser Creation

###### Description

The library implements a special API returning a parser instance for a supplied attribute type. This function finds the best matching parser type for the attribute based on a set of simple matching rules (as outlined in the table below) applied recursively to the attribute type. The returned parser can be utilized to match input for the provided attribute.

###### Header

    // forwards to <boost/spirit/home/qi/auto.hpp>
    #include <boost/spirit/include/qi_auto.hpp>

Also, see Include Structure.

###### Namespace

Name
`boost::spirit::qi::create_parser`
`boost::spirit::traits::create_parser_exists`

###### Synopsis

    namespace boost { namespace spirit { namespace qi
    {
        template <typename Attr>
        inline <unspecified>
        create_parser();
    }}}

The returned instance can be directly passed as the parser (or the skipping parser) to any of the Spirit.Qi API functions. Additionally it can be assigned to a rule as the rules right hand side expression. This function will return a valid parser type only if the meta function `traits::create_parser_exists` returns `mpl::true_`. Otherwise it will fail compiling.

    namespace boost { namespace spirit { namespace traits
    {
        template <typename Attr>
        struct create_parser_exists;
    }}}

The meta function evaluates to `mpl::true_` if `create_parser` would return a valid parser for the given type `Attr`.

The following table outlines the mapping rules from the attribute type to the parser type. These rules are applied recursively to create the parser type which can be used to match input for the given attribute type.

Attribute type | Generator type
--- | ---
`char`, `wchar_t` | `standard::char_`, `standard_wide::char_`
`short`, `int`, `long` | `short_`, `int_`, `long_`
`unsigned short`, `unsigned int`, `unsigned long` | `ushort_`, `uint_`, `ulong_`
`float`, `double`, `long double` | `float_`, `double_`, `long_double`
`short`, `int`, `long` | `short_`, `int_`, `long_`
`long long`, `unsigned long long` | `long_long`, `ulong_long`
`bool` | `bool_`
Any (STL) container | Kleene Star (unary `'*'`)
Any Fusion sequence | Sequence operator (`'<<'`)
`boost::optional<>` | Optional operator (unary `'-'`)
`boost::variant<>` | Alternative operator (`'|'`)

| Important
The mapping for the parsers `long_long` and `ulong_long` are only available on platforms where the preprocessor constant `BOOST_HAS_LONG_LONG` is defined (i.e. on platforms having native support for `long long` and `unsigned long long` (64 bit) signed and unsigned integer types).

###### Template parameters

Parameter | Description
--- | ---
`Attr` | An attribute type utilized to create the corresponding parser type from.