First public contribution.
1 /*=============================================================================
2 Copyright (c) 1998-2003 Joel de Guzman
3 Copyright (c) 2003 Vaclav Vesely
4 http://spirit.sourceforge.net/
6 Use, modification and distribution is subject to the Boost Software
7 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
10 #if !defined(BOOST_SPIRIT_DISTINCT_HPP)
11 #define BOOST_SPIRIT_DISTINCT_HPP
13 #include <boost/spirit/core/parser.hpp>
14 #include <boost/spirit/core/primitives/primitives.hpp>
15 #include <boost/spirit/core/composite/operators.hpp>
16 #include <boost/spirit/core/composite/directives.hpp>
17 #include <boost/spirit/core/composite/epsilon.hpp>
18 #include <boost/spirit/core/non_terminal/rule.hpp>
19 #include <boost/spirit/utility/chset.hpp>
21 #include <boost/spirit/utility/distinct_fwd.hpp>
25 //-----------------------------------------------------------------------------
26 // distinct_parser class
28 template <typename CharT, typename TailT>
36 negated_empty_match_parser<
44 : tail(chset<CharT>())
48 explicit distinct_parser(parser<TailT> const & tail_)
49 : tail(tail_.derived())
53 explicit distinct_parser(CharT const* letters)
54 : tail(chset_p(letters))
58 result_t operator()(CharT const* str) const
60 return lexeme_d[chseq_p(str) >> ~epsilon_p(tail)];
66 //-----------------------------------------------------------------------------
67 // distinct_directive class
69 template <typename CharT, typename TailT>
70 class distinct_directive
73 template<typename ParserT>
79 negated_empty_match_parser<
88 : tail(chset<CharT>())
92 explicit distinct_directive(CharT const* letters)
93 : tail(chset_p(letters))
97 explicit distinct_directive(parser<TailT> const & tail_)
98 : tail(tail_.derived())
102 template<typename ParserT>
103 typename result<typename as_parser<ParserT>::type>::type
104 operator[](ParserT const &subject) const
107 lexeme_d[as_parser<ParserT>::convert(subject) >> ~epsilon_p(tail)];
113 //-----------------------------------------------------------------------------
114 // dynamic_distinct_parser class
116 template <typename ScannerT>
117 class dynamic_distinct_parser
120 typedef typename ScannerT::value_t char_t;
124 typename no_actions_scanner<
125 typename lexeme_scanner<ScannerT>::type
133 chseq<char_t const*>,
134 negated_empty_match_parser<
141 dynamic_distinct_parser()
146 template<typename ParserT>
147 explicit dynamic_distinct_parser(parser<ParserT> const & tail_)
148 : tail(tail_.derived())
152 explicit dynamic_distinct_parser(char_t const* letters)
153 : tail(chset_p(letters))
157 result_t operator()(char_t const* str) const
159 return lexeme_d[chseq_p(str) >> ~epsilon_p(tail)];
165 //-----------------------------------------------------------------------------
166 // dynamic_distinct_directive class
168 template <typename ScannerT>
169 class dynamic_distinct_directive
172 typedef typename ScannerT::value_t char_t;
176 typename no_actions_scanner<
177 typename lexeme_scanner<ScannerT>::type
182 template<typename ParserT>
188 negated_empty_match_parser<
196 dynamic_distinct_directive()
201 template<typename ParserT>
202 explicit dynamic_distinct_directive(parser<ParserT> const & tail_)
203 : tail(tail_.derived())
207 explicit dynamic_distinct_directive(char_t const* letters)
208 : tail(chset_p(letters))
212 template<typename ParserT>
213 typename result<typename as_parser<ParserT>::type>::type
214 operator[](ParserT const &subject) const
217 lexeme_d[as_parser<ParserT>::convert(subject) >> ~epsilon_p(tail)];
223 //-----------------------------------------------------------------------------
224 } // namespace spirit
227 #endif // !defined(BOOST_SPIRIT_DISTINCT_HPP)