1 /*=============================================================================
2 Copyright (c) 1998-2003 Joel de Guzman
3 Copyright (c) 2001 Daniel Nuffer
4 Copyright (c) 2001 Bruce Florman
5 Copyright (c) 2002 Raghavendra Satish
6 http://spirit.sourceforge.net/
8 Use, modification and distribution is subject to the Boost Software
9 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 http://www.boost.org/LICENSE_1_0.txt)
11 =============================================================================*/
12 #if !defined(BOOST_SPIRIT_DIRECTIVES_IPP)
13 #define BOOST_SPIRIT_DIRECTIVES_IPP
15 ///////////////////////////////////////////////////////////////////////////////
16 #include <boost/spirit/home/classic/core/scanner/skipper.hpp>
18 namespace boost { namespace spirit {
20 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
22 template <typename BaseT>
23 struct no_skipper_iteration_policy;
25 template <typename BaseT>
26 struct inhibit_case_iteration_policy;
28 template <typename A, typename B>
31 template <typename A, typename B>
32 struct longest_alternative;
34 template <typename A, typename B>
35 struct shortest_alternative;
39 template <typename RT, typename ST, typename ScannerT, typename BaseT>
41 contiguous_parser_parse(
44 skipper_iteration_policy<BaseT> const&)
46 typedef scanner_policies<
47 no_skipper_iteration_policy<
48 BOOST_DEDUCED_TYPENAME ScannerT::iteration_policy_t>,
49 BOOST_DEDUCED_TYPENAME ScannerT::match_policy_t,
50 BOOST_DEDUCED_TYPENAME ScannerT::action_policy_t
54 RT hit = s.parse(scan.change_policies(policies_t(scan)));
55 // We will not do a post skip!!!
59 template <typename RT, typename ST, typename ScannerT, typename BaseT>
61 contiguous_parser_parse(
64 no_skipper_iteration_policy<BaseT> const&)
69 template <typename RT, typename ST, typename ScannerT>
71 contiguous_parser_parse(
74 iteration_policy const&)
85 implicit_lexeme_parse(
88 skipper_iteration_policy<BaseT> const&)
90 typedef scanner_policies<
91 no_skipper_iteration_policy<
92 BOOST_DEDUCED_TYPENAME ScannerT::iteration_policy_t>,
93 BOOST_DEDUCED_TYPENAME ScannerT::match_policy_t,
94 BOOST_DEDUCED_TYPENAME ScannerT::action_policy_t
98 RT hit = p.parse_main(scan.change_policies(policies_t(scan)));
99 // We will not do a post skip!!!
109 implicit_lexeme_parse(
111 ScannerT const& scan,
112 no_skipper_iteration_policy<BaseT> const&)
114 return p.parse_main(scan);
117 template <typename RT, typename ParserT, typename ScannerT>
119 implicit_lexeme_parse(
121 ScannerT const& scan,
122 iteration_policy const&)
124 return p.parse_main(scan);
127 template <typename RT, typename ST, typename ScannerT>
129 inhibit_case_parser_parse(
131 ScannerT const& scan,
132 iteration_policy const&)
134 typedef scanner_policies<
135 inhibit_case_iteration_policy<
136 BOOST_DEDUCED_TYPENAME ScannerT::iteration_policy_t>,
137 BOOST_DEDUCED_TYPENAME ScannerT::match_policy_t,
138 BOOST_DEDUCED_TYPENAME ScannerT::action_policy_t
141 return s.parse(scan.change_policies(policies_t(scan)));
144 template <typename RT, typename ST, typename ScannerT, typename BaseT>
146 inhibit_case_parser_parse(
148 ScannerT const& scan,
149 inhibit_case_iteration_policy<BaseT> const&)
151 return s.parse(scan);
154 template <typename T>
155 struct to_longest_alternative
158 static result_t const&
159 convert(T const& a) // Special (end) case
163 template <typename A, typename B>
164 struct to_longest_alternative<alternative<A, B> >
166 typedef typename to_longest_alternative<A>::result_t a_t;
167 typedef typename to_longest_alternative<B>::result_t b_t;
168 typedef longest_alternative<a_t, b_t> result_t;
171 convert(alternative<A, B> const& alt) // Recursive case
174 to_longest_alternative<A>::convert(alt.left()),
175 to_longest_alternative<B>::convert(alt.right()));
179 template <typename T>
180 struct to_shortest_alternative
183 static result_t const&
184 convert(T const& a) // Special (end) case
188 template <typename A, typename B>
189 struct to_shortest_alternative<alternative<A, B> >
191 typedef typename to_shortest_alternative<A>::result_t a_t;
192 typedef typename to_shortest_alternative<B>::result_t b_t;
193 typedef shortest_alternative<a_t, b_t> result_t;
196 convert(alternative<A, B> const& alt) // Recursive case
199 to_shortest_alternative<A>::convert(alt.left()),
200 to_shortest_alternative<B>::convert(alt.right()));
205 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
207 }} // namespace boost::spirit