1 /*=============================================================================
2 Copyright (c) 1998-2003 Joel de Guzman
3 Copyright (c) 2003 Vaclav Vesely
4 http://spirit.sourceforge.net/
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_DISTINCT_HPP)
10 #define BOOST_SPIRIT_DISTINCT_HPP
12 #include <boost/spirit/home/classic/core/parser.hpp>
13 #include <boost/spirit/home/classic/core/primitives/primitives.hpp>
14 #include <boost/spirit/home/classic/core/composite/operators.hpp>
15 #include <boost/spirit/home/classic/core/composite/directives.hpp>
16 #include <boost/spirit/home/classic/core/composite/epsilon.hpp>
17 #include <boost/spirit/home/classic/core/non_terminal/rule.hpp>
18 #include <boost/spirit/home/classic/utility/chset.hpp>
20 #include <boost/spirit/home/classic/utility/distinct_fwd.hpp>
24 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
26 //-----------------------------------------------------------------------------
27 // distinct_parser class
29 template <typename CharT, typename TailT>
37 negated_empty_match_parser<
45 : tail(chset<CharT>())
49 explicit distinct_parser(parser<TailT> const & tail_)
50 : tail(tail_.derived())
54 explicit distinct_parser(CharT const* letters)
55 : tail(chset_p(letters))
59 result_t operator()(CharT const* str) const
61 return lexeme_d[chseq_p(str) >> ~epsilon_p(tail)];
67 //-----------------------------------------------------------------------------
68 // distinct_directive class
70 template <typename CharT, typename TailT>
71 class distinct_directive
74 template<typename ParserT>
80 negated_empty_match_parser<
89 : tail(chset<CharT>())
93 explicit distinct_directive(CharT const* letters)
94 : tail(chset_p(letters))
98 explicit distinct_directive(parser<TailT> const & tail_)
99 : tail(tail_.derived())
103 template<typename ParserT>
104 typename result<typename as_parser<ParserT>::type>::type
105 operator[](ParserT const &subject) const
108 lexeme_d[as_parser<ParserT>::convert(subject) >> ~epsilon_p(tail)];
114 //-----------------------------------------------------------------------------
115 // dynamic_distinct_parser class
117 template <typename ScannerT>
118 class dynamic_distinct_parser
121 typedef typename ScannerT::value_t char_t;
125 typename no_actions_scanner<
126 typename lexeme_scanner<ScannerT>::type
134 chseq<char_t const*>,
135 negated_empty_match_parser<
142 dynamic_distinct_parser()
147 template<typename ParserT>
148 explicit dynamic_distinct_parser(parser<ParserT> const & tail_)
149 : tail(tail_.derived())
153 explicit dynamic_distinct_parser(char_t const* letters)
154 : tail(chset_p(letters))
158 result_t operator()(char_t const* str) const
160 return lexeme_d[chseq_p(str) >> ~epsilon_p(tail)];
166 //-----------------------------------------------------------------------------
167 // dynamic_distinct_directive class
169 template <typename ScannerT>
170 class dynamic_distinct_directive
173 typedef typename ScannerT::value_t char_t;
177 typename no_actions_scanner<
178 typename lexeme_scanner<ScannerT>::type
183 template<typename ParserT>
189 negated_empty_match_parser<
197 dynamic_distinct_directive()
202 template<typename ParserT>
203 explicit dynamic_distinct_directive(parser<ParserT> const & tail_)
204 : tail(tail_.derived())
208 explicit dynamic_distinct_directive(char_t const* letters)
209 : tail(chset_p(letters))
213 template<typename ParserT>
214 typename result<typename as_parser<ParserT>::type>::type
215 operator[](ParserT const &subject) const
218 lexeme_d[as_parser<ParserT>::convert(subject) >> ~epsilon_p(tail)];
224 //-----------------------------------------------------------------------------
225 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
226 } // namespace spirit
229 #endif // !defined(BOOST_SPIRIT_DISTINCT_HPP)