Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:01:54

0001 /*=============================================================================
0002     Copyright (c) 1998-2003 Joel de Guzman
0003     Copyright (c) 2001 Daniel Nuffer
0004     Copyright (c) 2002 Hartmut Kaiser
0005     http://spirit.sourceforge.net/
0006 
0007   Distributed under the Boost Software License, Version 1.0. (See accompanying
0008   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 =============================================================================*/
0010 #if !defined(BOOST_SPIRIT_SEQUENCE_HPP)
0011 #define BOOST_SPIRIT_SEQUENCE_HPP
0012 
0013 #include <boost/spirit/home/classic/namespace.hpp>
0014 #include <boost/spirit/home/classic/core/parser.hpp>
0015 #include <boost/spirit/home/classic/core/primitives/primitives.hpp>
0016 #include <boost/spirit/home/classic/core/composite/composite.hpp>
0017 #include <boost/spirit/home/classic/meta/as_parser.hpp>
0018 
0019 namespace boost { namespace spirit {
0020 
0021 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0022 
0023     ///////////////////////////////////////////////////////////////////////////
0024     //
0025     //  sequence class
0026     //
0027     //      Handles expressions of the form:
0028     //
0029     //          a >> b
0030     //
0031     //      where a and b are parsers. The expression returns a composite
0032     //      parser that matches a and b in sequence. One (not both) of the
0033     //      operands may be a literal char, wchar_t or a primitive string
0034     //      char const*, wchar_t const*.
0035     //
0036     //////////////////////////////////////////////////////////////////////////
0037     struct sequence_parser_gen;
0038     
0039 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0040 #pragma warning(push)
0041 #pragma warning(disable:4512) //assignment operator could not be generated
0042 #endif
0043 
0044     template <typename A, typename B>
0045     struct sequence : public binary<A, B, parser<sequence<A, B> > >
0046     {
0047         typedef sequence<A, B>                  self_t;
0048         typedef binary_parser_category          parser_category_t;
0049         typedef sequence_parser_gen             parser_generator_t;
0050         typedef binary<A, B, parser<self_t> >   base_t;
0051     
0052         sequence(A const& a, B const& b)
0053         : base_t(a, b) {}
0054     
0055         template <typename ScannerT>
0056         typename parser_result<self_t, ScannerT>::type
0057         parse(ScannerT const& scan) const
0058         {
0059             typedef typename parser_result<self_t, ScannerT>::type result_t;
0060             if (result_t ma = this->left().parse(scan))
0061                 if (result_t mb = this->right().parse(scan))
0062                 {
0063                     scan.concat_match(ma, mb);
0064                     return ma;
0065                 }
0066             return scan.no_match();
0067         }
0068     };
0069 
0070 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0071 #pragma warning(pop)
0072 #endif
0073     
0074     struct sequence_parser_gen
0075     {
0076         template <typename A, typename B>
0077         struct result 
0078         {
0079             typedef
0080                 sequence<
0081                     typename as_parser<A>::type
0082                   , typename as_parser<B>::type
0083                 >
0084             type;
0085         };
0086     
0087         template <typename A, typename B>
0088         static sequence<
0089             typename as_parser<A>::type
0090           , typename as_parser<B>::type
0091         >
0092         generate(A const& a, B const& b)
0093         {
0094             return sequence<BOOST_DEDUCED_TYPENAME as_parser<A>::type,
0095                 BOOST_DEDUCED_TYPENAME as_parser<B>::type>
0096                     (as_parser<A>::convert(a), as_parser<B>::convert(b));
0097         }
0098     };
0099     
0100     template <typename A, typename B>
0101     sequence<A, B>
0102     operator>>(parser<A> const& a, parser<B> const& b);
0103     
0104     template <typename A>
0105     sequence<A, chlit<char> >
0106     operator>>(parser<A> const& a, char b);
0107     
0108     template <typename B>
0109     sequence<chlit<char>, B>
0110     operator>>(char a, parser<B> const& b);
0111     
0112     template <typename A>
0113     sequence<A, strlit<char const*> >
0114     operator>>(parser<A> const& a, char const* b);
0115     
0116     template <typename B>
0117     sequence<strlit<char const*>, B>
0118     operator>>(char const* a, parser<B> const& b);
0119     
0120     template <typename A>
0121     sequence<A, chlit<wchar_t> >
0122     operator>>(parser<A> const& a, wchar_t b);
0123     
0124     template <typename B>
0125     sequence<chlit<wchar_t>, B>
0126     operator>>(wchar_t a, parser<B> const& b);
0127     
0128     template <typename A>
0129     sequence<A, strlit<wchar_t const*> >
0130     operator>>(parser<A> const& a, wchar_t const* b);
0131     
0132     template <typename B>
0133     sequence<strlit<wchar_t const*>, B>
0134     operator>>(wchar_t const* a, parser<B> const& b);
0135     
0136 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0137 
0138 }} // namespace BOOST_SPIRIT_CLASSIC_NS
0139 
0140 #endif
0141 
0142 #include <boost/spirit/home/classic/core/composite/impl/sequence.ipp>