Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-01 10:14:52

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_POSITIVE_HPP)
0011 #define BOOST_SPIRIT_POSITIVE_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     //  positive class
0026     //
0027     //      Handles expressions of the form:
0028     //
0029     //          +a
0030     //
0031     //      where a is a parser. The expression returns a composite
0032     //      parser that matches its subject one (1) or more times.
0033     //
0034     ///////////////////////////////////////////////////////////////////////////
0035     struct positive_parser_gen;
0036     
0037 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0038 #pragma warning(push)
0039 #pragma warning(disable:4512) //assignment operator could not be generated
0040 #endif
0041 
0042     template <typename S>
0043     struct positive
0044     :   public unary<S, parser<positive<S> > >
0045     {
0046         typedef positive<S>                 self_t;
0047         typedef unary_parser_category       parser_category_t;
0048         typedef positive_parser_gen         parser_generator_t;
0049         typedef unary<S, parser<self_t> >   base_t;
0050     
0051         positive(S const& a)
0052         : base_t(a) {}
0053     
0054         template <typename ScannerT>
0055         typename parser_result<self_t, ScannerT>::type
0056         parse(ScannerT const& scan) const
0057         {
0058             typedef typename parser_result<self_t, ScannerT>::type result_t;
0059             typedef typename ScannerT::iterator_t iterator_t;
0060             result_t hit = this->subject().parse(scan);
0061     
0062             if (hit)
0063             {
0064                 for (;;)
0065                 {
0066                     iterator_t save = scan.first;
0067                     if (result_t next = this->subject().parse(scan))
0068                     {
0069                         scan.concat_match(hit, next);
0070                     }
0071                     else
0072                     {
0073                         scan.first = save;
0074                         break;
0075                     }
0076                 }
0077             }
0078             return hit;
0079         }
0080     };
0081 
0082 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0083 #pragma warning(pop)
0084 #endif
0085     
0086     struct positive_parser_gen
0087     {
0088         template <typename S>
0089         struct result 
0090         {
0091             typedef positive<S> type;
0092         };
0093     
0094         template <typename S>
0095         static positive<S>
0096         generate(parser<S> const& a)
0097         {
0098             return positive<S>(a.derived());
0099         }
0100     };
0101     
0102     template <typename S>
0103     inline positive<S>
0104     operator+(parser<S> const& a);
0105 
0106 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0107 
0108 }} // namespace BOOST_SPIRIT_CLASSIC_NS
0109 
0110 #endif
0111 
0112 #include <boost/spirit/home/classic/core/composite/impl/positive.ipp>