| Home | Libraries | People | FAQ | More

##### Stream Based Parser API

###### Description

The library provides a couple of Standard IO Manipulators allowing to integrate Spirit.Qi input parsing facilities with Standard input streams. These parser manipulators have two forms. The first form, `match`, works on the character level. The second `phrase_match` works on the phrase level and requires a skip parser. Both versions can take in attributes by reference that will hold the parsed values on a successful parse.

###### Header

    // forwards to <boost/spirit/home/qi/stream/match_manip.hpp>
    #include <boost/spirit/include/qi_match.hpp>

For variadic attributes:

    // forwards to <boost/spirit/home/qi/stream/match_manip_attr.hpp>
    #include <boost/spirit/include/qi_match_attr.hpp>

The variadic attributes version of the API allows one or more attributes to be passed into the parse manipulators. The manipulators taking two or more attributes are usable when the parser expression is a Sequence only. In this case each of the attributes passed have to match the corresponding part of the sequence.

For the API functions deducing the correct (matching) parser type from the supplied attribute type:

    // forwards to <boost/spirit/home/qi/match_auto.hpp>
    #include <boost/spirit/include/qi_match_auto.hpp>

Also, see Include Structure.

###### Namespace

Name
`boost::spirit::qi::match`
`boost::spirit::qi::phrase_match`
`boost::spirit::qi::skip_flag::postskip`
`boost::spirit::qi::skip_flag::dont_postskip`

###### Synopsis

    namespace boost { namespace spirit { namespace qi
    {
        template <typename Expr>
        inline <unspecified>
        match(
            Expr const& xpr);

        template <typename Expr
          , typename Attr1, typename Attr2, ..., typename AttrN>
        inline <unspecified>
        match(
            Expr const& xpr
          , Attr1& attr1, Attr2& attr2, ..., AttrN& attrN);

        template <typename Expr, typename Skipper>
        inline <unspecified>
        phrase_match(
            Expr const& expr
          , Skipper const& s
          , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip);

        template <typename Expr, typename Skipper
          , typename Attr1, typename Attr2, ..., typename AttrN>
        inline <unspecified>
        phrase_match(
            Expr const& expr
          , Skipper const& s
          , Attr1& attr1, Attr2& attr2, ..., AttrN& attrN);

        template <typename Expr, typename Skipper
          , typename Attr1, typename Attr2, ..., typename AttrN>
        inline <unspecified>
        phrase_match(
            Expr const& expr
          , Skipper const& s
          , BOOST_SCOPED_ENUM(skip_flag) post_skip
          , Attr1& attr1, Attr2& attr2, ..., AttrN& attrN);
    }}}

Spirit.Qi parser API functions based on the automatic creation of the matching parser type:

    namespace boost { namespace spirit { namespace qi
    {
        template <typename Attr>
        inline <unspecified>
        match(
            Attr& attr);

        template <typename Attr, typename Skipper>
        inline <unspecified>
        phrase_match(
            Attr& attr
          , Skipper const& s
          , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip);
    }}}

All functions above return a standard IO stream manipulator instance (see Manipulators), which when streamed from an input stream will result in parsing the input using the embedded Spirit.Qi parser expression. Any error (or failed parse) occurring during the invocation of the Spirit.Qi parsers will be reflected in the streams status flag (`std::ios_base::failbit` will be set).

The maximum number of supported arguments is limited by the preprocessor constant `SPIRIT_ARGUMENTS_LIMIT`. This constant defaults to the value defined by the preprocessor constant `PHOENIX_LIMIT` (which in turn defaults to `10`).

| Note
The variadic manipulators with two or more attributes internally combine references to all passed attributes into a `fusion::vector` and forward this as a combined attribute to the corresponding manipulator taking one attribute.

The `phrase_match` manipulators not taking an explicit `skip_flag` as one of their arguments invoke the passed skipper after a successful match of the parser expression. This can be inhibited by using the other versions of that manipulator while passing `skip_flag::dont_postskip` to the corresponding argument.

###### Template parameters

Parameter | Description
--- | ---
`Expr` | An expression that can be converted to a Qi parser.
`Skipper` | Parser used to skip white spaces.
`Attr` | An attribute type utilized to create the corresponding parser type from.
`Attr1`, `Attr2`, ..., `AttrN` | One or more attributes.