Back to home page

EIC code displayed by LXR

 
 

    


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

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_DIFFERENCE_HPP)
0011 #define BOOST_SPIRIT_DIFFERENCE_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     //  difference: a - b; Matches a but not b
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 but not b. One (not both) of the operands
0033     //      may be a literal char, wchar_t or a primitive string char const*,
0034     //      wchar_t const*.
0035     //
0036     ///////////////////////////////////////////////////////////////////////////
0037     struct difference_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 difference
0046     :   public binary<A, B, parser<difference<A, B> > >
0047     {
0048         typedef difference<A, B>                self_t;
0049         typedef binary_parser_category          parser_category_t;
0050         typedef difference_parser_gen           parser_generator_t;
0051         typedef binary<A, B, parser<self_t> >   base_t;
0052     
0053         difference(A const& a, B const& b)
0054         : base_t(a, b) {}
0055     
0056         template <typename ScannerT>
0057         typename parser_result<self_t, ScannerT>::type
0058         parse(ScannerT const& scan) const
0059         {
0060             typedef typename parser_result<self_t, ScannerT>::type result_t;
0061             typedef typename ScannerT::iterator_t iterator_t;
0062             iterator_t save = scan.first;
0063             if (result_t hl = this->left().parse(scan))
0064             {
0065                 std::swap(save, scan.first);
0066                 result_t hr = this->right().parse(scan);
0067                 if (!hr || (hr.length() < hl.length()))
0068                 {
0069                     scan.first = save;
0070                     return hl;
0071                 }
0072             }
0073     
0074             return scan.no_match();
0075         }
0076     };
0077 
0078 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0079 #pragma warning(pop)
0080 #endif
0081     
0082     struct difference_parser_gen
0083     {
0084         template <typename A, typename B>
0085         struct result 
0086         {
0087             typedef 
0088                 difference<
0089                     typename as_parser<A>::type
0090                   , typename as_parser<B>::type
0091                 > 
0092             type;
0093         };
0094     
0095         template <typename A, typename B>
0096         static difference<
0097             typename as_parser<A>::type
0098           , typename as_parser<B>::type
0099         >
0100         generate(A const& a, B const& b)
0101         {
0102             return difference<BOOST_DEDUCED_TYPENAME as_parser<A>::type,
0103                 BOOST_DEDUCED_TYPENAME as_parser<B>::type>
0104                     (as_parser<A>::convert(a), as_parser<B>::convert(b));
0105         }
0106     };
0107     
0108     template <typename A, typename B>
0109     difference<A, B>
0110     operator-(parser<A> const& a, parser<B> const& b);
0111     
0112     template <typename A>
0113     difference<A, chlit<char> >
0114     operator-(parser<A> const& a, char b);
0115     
0116     template <typename B>
0117     difference<chlit<char>, B>
0118     operator-(char a, parser<B> const& b);
0119     
0120     template <typename A>
0121     difference<A, strlit<char const*> >
0122     operator-(parser<A> const& a, char const* b);
0123     
0124     template <typename B>
0125     difference<strlit<char const*>, B>
0126     operator-(char const* a, parser<B> const& b);
0127     
0128     template <typename A>
0129     difference<A, chlit<wchar_t> >
0130     operator-(parser<A> const& a, wchar_t b);
0131     
0132     template <typename B>
0133     difference<chlit<wchar_t>, B>
0134     operator-(wchar_t a, parser<B> const& b);
0135     
0136     template <typename A>
0137     difference<A, strlit<wchar_t const*> >
0138     operator-(parser<A> const& a, wchar_t const* b);
0139     
0140     template <typename B>
0141     difference<strlit<wchar_t const*>, B>
0142     operator-(wchar_t const* a, parser<B> const& b);
0143 
0144 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0145 
0146 }} // namespace BOOST_SPIRIT_CLASSIC_NS
0147 
0148 #endif
0149 
0150 #include <boost/spirit/home/classic/core/composite/impl/difference.ipp>