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_INTERSECTION_HPP)
0011 #define BOOST_SPIRIT_INTERSECTION_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     //  intersection 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. One (not both) of the operands may
0033     //      be a literal char, wchar_t or a primitive string char const*,
0034     //      wchar_t const*.
0035     //
0036     //      The expression is short circuit evaluated. b is never touched
0037     //      when a is returns a no-match.
0038     //
0039     ///////////////////////////////////////////////////////////////////////////
0040     struct intersection_parser_gen;
0041     
0042     template <typename A, typename B>
0043     struct intersection
0044     :   public binary<A, B, parser<intersection<A, B> > >
0045     {
0046         typedef intersection<A, B>              self_t;
0047         typedef binary_parser_category          parser_category_t;
0048         typedef intersection_parser_gen         parser_generator_t;
0049         typedef binary<A, B, parser<self_t> >   base_t;
0050     
0051         intersection(A const& a, B const& b)
0052         : base_t(a, b) {}
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             iterator_t save = scan.first;
0061             if (result_t hl = this->left().parse(scan))
0062             {
0063                 ScannerT bscan(scan.first, scan.first, scan);
0064                 scan.first = save;
0065                 result_t hr = this->right().parse(bscan);
0066                 if (hl.length() == hr.length())
0067                     return hl;
0068             }
0069     
0070             return scan.no_match();
0071         }
0072     };
0073     
0074     struct intersection_parser_gen
0075     {
0076         template <typename A, typename B>
0077         struct result 
0078         {
0079             typedef 
0080                 intersection<
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 intersection<
0089             typename as_parser<A>::type
0090           , typename as_parser<B>::type
0091         >
0092         generate(A const& a, B const& b)
0093         {
0094             return intersection<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     intersection<A, B>
0102     operator&(parser<A> const& a, parser<B> const& b);
0103     
0104     template <typename A>
0105     intersection<A, chlit<char> >
0106     operator&(parser<A> const& a, char b);
0107     
0108     template <typename B>
0109     intersection<chlit<char>, B>
0110     operator&(char a, parser<B> const& b);
0111     
0112     template <typename A>
0113     intersection<A, strlit<char const*> >
0114     operator&(parser<A> const& a, char const* b);
0115     
0116     template <typename B>
0117     intersection<strlit<char const*>, B>
0118     operator&(char const* a, parser<B> const& b);
0119     
0120     template <typename A>
0121     intersection<A, chlit<wchar_t> >
0122     operator&(parser<A> const& a, wchar_t b);
0123     
0124     template <typename B>
0125     intersection<chlit<wchar_t>, B>
0126     operator&(wchar_t a, parser<B> const& b);
0127     
0128     template <typename A>
0129     intersection<A, strlit<wchar_t const*> >
0130     operator&(parser<A> const& a, wchar_t const* b);
0131     
0132     template <typename B>
0133     intersection<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/intersection.ipp>