1 /*=============================================================================
2 Copyright (c) 1998-2003 Joel de Guzman
3 http://spirit.sourceforge.net/
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #if !defined(BOOST_SPIRIT_SKIPPER_HPP)
9 #define BOOST_SPIRIT_SKIPPER_HPP
11 ///////////////////////////////////////////////////////////////////////////////
14 #include <boost/spirit/home/classic/namespace.hpp>
15 #include <boost/spirit/home/classic/core/scanner/scanner.hpp>
16 #include <boost/spirit/home/classic/core/primitives/impl/primitives.ipp>
18 #include <boost/spirit/home/classic/core/scanner/skipper_fwd.hpp>
20 namespace boost { namespace spirit {
22 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
24 ///////////////////////////////////////////////////////////////////////////
26 // skipper_iteration_policy class
28 ///////////////////////////////////////////////////////////////////////////
29 template <typename BaseT>
30 struct skipper_iteration_policy : public BaseT
34 skipper_iteration_policy()
37 template <typename PolicyT>
38 skipper_iteration_policy(PolicyT const& other)
41 template <typename ScannerT>
43 advance(ScannerT const& scan) const
49 template <typename ScannerT>
51 at_end(ScannerT const& scan) const
54 return BaseT::at_end(scan);
57 template <typename ScannerT>
59 skip(ScannerT const& scan) const
61 while (!BaseT::at_end(scan) && impl::isspace_(BaseT::get(scan)))
66 ///////////////////////////////////////////////////////////////////////////
68 // no_skipper_iteration_policy class
70 ///////////////////////////////////////////////////////////////////////////
71 template <typename BaseT>
72 struct no_skipper_iteration_policy : public BaseT
76 no_skipper_iteration_policy()
79 template <typename PolicyT>
80 no_skipper_iteration_policy(PolicyT const& other)
83 template <typename ScannerT>
85 skip(ScannerT const& /*scan*/) const {}
88 ///////////////////////////////////////////////////////////////////////////
90 // skip_parser_iteration_policy class
92 ///////////////////////////////////////////////////////////////////////////
95 template <typename ST, typename ScannerT, typename BaseT>
100 skipper_iteration_policy<BaseT> const&);
102 template <typename ST, typename ScannerT, typename BaseT>
106 ScannerT const& scan,
107 no_skipper_iteration_policy<BaseT> const&);
109 template <typename ST, typename ScannerT>
113 ScannerT const& scan,
114 iteration_policy const&);
117 template <typename ParserT, typename BaseT>
118 class skip_parser_iteration_policy : public skipper_iteration_policy<BaseT>
122 typedef skipper_iteration_policy<BaseT> base_t;
124 skip_parser_iteration_policy(
125 ParserT const& skip_parser,
126 base_t const& base = base_t())
127 : base_t(base), subject(skip_parser) {}
129 template <typename PolicyT>
130 skip_parser_iteration_policy(PolicyT const& other)
131 : base_t(other), subject(other.skipper()) {}
133 template <typename ScannerT>
135 skip(ScannerT const& scan) const
137 impl::skipper_skip(subject, scan, scan);
148 ParserT const& subject;
151 ///////////////////////////////////////////////////////////////////////////////
153 // Free parse functions using the skippers
155 ///////////////////////////////////////////////////////////////////////////////
156 template <typename IteratorT, typename ParserT, typename SkipT>
157 parse_info<IteratorT>
159 IteratorT const& first,
160 IteratorT const& last,
161 parser<ParserT> const& p,
162 parser<SkipT> const& skip);
164 ///////////////////////////////////////////////////////////////////////////////
166 // Parse function for null terminated strings using the skippers
168 ///////////////////////////////////////////////////////////////////////////////
169 template <typename CharT, typename ParserT, typename SkipT>
170 parse_info<CharT const*>
173 parser<ParserT> const& p,
174 parser<SkipT> const& skip);
176 ///////////////////////////////////////////////////////////////////////////////
178 // phrase_scanner_t and wide_phrase_scanner_t
180 // The most common scanners. Use these typedefs when you need
181 // a scanner that skips white spaces.
183 ///////////////////////////////////////////////////////////////////////////////
184 typedef skipper_iteration_policy<> iter_policy_t;
185 typedef scanner_policies<iter_policy_t> scanner_policies_t;
186 typedef scanner<char const*, scanner_policies_t> phrase_scanner_t;
187 typedef scanner<wchar_t const*, scanner_policies_t> wide_phrase_scanner_t;
189 ///////////////////////////////////////////////////////////////////////////////
191 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
193 }} // namespace BOOST_SPIRIT_CLASSIC_NS
195 #include <boost/spirit/home/classic/core/scanner/impl/skipper.ipp>