Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:08

0001 /*=============================================================================
0002     Copyright (c) 1998-2003 Joel de Guzman
0003     Copyright (c) 2003 Vaclav Vesely
0004     http://spirit.sourceforge.net/
0005 
0006   Distributed under the Boost Software License, Version 1.0. (See accompanying
0007   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 =============================================================================*/
0009 #if !defined(BOOST_SPIRIT_DISTINCT_HPP)
0010 #define BOOST_SPIRIT_DISTINCT_HPP
0011 
0012 #include <boost/spirit/home/classic/core/parser.hpp>
0013 #include <boost/spirit/home/classic/core/primitives/primitives.hpp>
0014 #include <boost/spirit/home/classic/core/composite/operators.hpp>
0015 #include <boost/spirit/home/classic/core/composite/directives.hpp>
0016 #include <boost/spirit/home/classic/core/composite/epsilon.hpp>
0017 #include <boost/spirit/home/classic/core/non_terminal/rule.hpp>
0018 #include <boost/spirit/home/classic/utility/chset.hpp>
0019 
0020 #include <boost/spirit/home/classic/utility/distinct_fwd.hpp>
0021 
0022 namespace boost {
0023     namespace spirit {
0024     BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0025 
0026 //-----------------------------------------------------------------------------
0027 // distinct_parser class
0028 
0029 template <typename CharT, typename TailT>
0030 class distinct_parser
0031 {
0032 public:
0033     typedef
0034         contiguous<
0035             sequence<
0036                 chseq<CharT const*>,
0037                 negated_empty_match_parser<
0038                     TailT
0039                 >
0040             >
0041         >
0042             result_t;
0043 
0044     distinct_parser()
0045     :   tail(chset<CharT>())
0046     {
0047     }
0048 
0049     explicit distinct_parser(parser<TailT> const & tail_)
0050     :   tail(tail_.derived())
0051     {
0052     }
0053 
0054     explicit distinct_parser(CharT const* letters)
0055     :   tail(chset_p(letters))
0056     {
0057     }
0058 
0059     result_t operator()(CharT const* str) const
0060     {
0061         return lexeme_d[chseq_p(str) >> ~epsilon_p(tail)];
0062     }
0063 
0064     TailT tail;
0065 };
0066 
0067 //-----------------------------------------------------------------------------
0068 // distinct_directive class
0069 
0070 template <typename CharT, typename TailT>
0071 class distinct_directive
0072 {
0073 public:
0074     template<typename ParserT>
0075     struct result {
0076         typedef
0077             contiguous<
0078                 sequence<
0079                     ParserT,
0080                     negated_empty_match_parser<
0081                         TailT
0082                     >
0083                 >
0084             >
0085                 type;
0086     };
0087 
0088     distinct_directive()
0089     :   tail(chset<CharT>())
0090     {
0091     }
0092 
0093     explicit distinct_directive(CharT const* letters)
0094     :   tail(chset_p(letters))
0095     {
0096     }
0097 
0098     explicit distinct_directive(parser<TailT> const & tail_)
0099     :   tail(tail_.derived())
0100     {
0101     }
0102 
0103     template<typename ParserT>
0104     typename result<typename as_parser<ParserT>::type>::type
0105         operator[](ParserT const &subject) const
0106     {
0107         return
0108             lexeme_d[as_parser<ParserT>::convert(subject) >> ~epsilon_p(tail)];
0109     }
0110 
0111     TailT tail;
0112 };
0113 
0114 //-----------------------------------------------------------------------------
0115 // dynamic_distinct_parser class
0116 
0117 template <typename ScannerT>
0118 class dynamic_distinct_parser
0119 {
0120 public:
0121     typedef typename ScannerT::value_t char_t;
0122 
0123     typedef
0124         rule<
0125             typename no_actions_scanner<
0126                 typename lexeme_scanner<ScannerT>::type
0127             >::type
0128         >
0129             tail_t;
0130 
0131     typedef
0132         contiguous<
0133             sequence<
0134                 chseq<char_t const*>,
0135                 negated_empty_match_parser<
0136                     tail_t
0137                 >
0138             >
0139         >
0140             result_t;
0141 
0142     dynamic_distinct_parser()
0143     :   tail(nothing_p)
0144     {
0145     }
0146 
0147     template<typename ParserT>
0148     explicit dynamic_distinct_parser(parser<ParserT> const & tail_)
0149     :   tail(tail_.derived())
0150     {
0151     }
0152 
0153     explicit dynamic_distinct_parser(char_t const* letters)
0154     :   tail(chset_p(letters))
0155     {
0156     }
0157 
0158     result_t operator()(char_t const* str) const
0159     {
0160         return lexeme_d[chseq_p(str) >> ~epsilon_p(tail)];
0161     }
0162 
0163     tail_t tail;
0164 };
0165 
0166 //-----------------------------------------------------------------------------
0167 // dynamic_distinct_directive class
0168 
0169 template <typename ScannerT>
0170 class dynamic_distinct_directive
0171 {
0172 public:
0173     typedef typename ScannerT::value_t char_t;
0174 
0175     typedef
0176         rule<
0177             typename no_actions_scanner<
0178                 typename lexeme_scanner<ScannerT>::type
0179             >::type
0180         >
0181             tail_t;
0182 
0183     template<typename ParserT>
0184     struct result {
0185         typedef
0186             contiguous<
0187                 sequence<
0188                     ParserT,
0189                     negated_empty_match_parser<
0190                         tail_t
0191                     >
0192                 >
0193             >
0194                 type;
0195     };
0196 
0197     dynamic_distinct_directive()
0198     :   tail(nothing_p)
0199     {
0200     }
0201 
0202     template<typename ParserT>
0203     explicit dynamic_distinct_directive(parser<ParserT> const & tail_)
0204     :   tail(tail_.derived())
0205     {
0206     }
0207 
0208     explicit dynamic_distinct_directive(char_t const* letters)
0209     :   tail(chset_p(letters))
0210     {
0211     }
0212 
0213     template<typename ParserT>
0214     typename result<typename as_parser<ParserT>::type>::type
0215         operator[](ParserT const &subject) const
0216     {
0217         return
0218             lexeme_d[as_parser<ParserT>::convert(subject) >> ~epsilon_p(tail)];
0219     }
0220 
0221     tail_t tail;
0222 };
0223 
0224 //-----------------------------------------------------------------------------
0225     BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0226     } // namespace spirit
0227 } // namespace boost
0228 
0229 #endif // !defined(BOOST_SPIRIT_DISTINCT_HPP)