File indexing completed on 2025-01-31 10:01:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #if !defined(BOOST_SPIRIT_DIRECTIVES_IPP)
0013 #define BOOST_SPIRIT_DIRECTIVES_IPP
0014
0015
0016 #include <boost/spirit/home/classic/core/scanner/skipper.hpp>
0017
0018 namespace boost { namespace spirit {
0019
0020 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0021
0022 template <typename BaseT>
0023 struct no_skipper_iteration_policy;
0024
0025 template <typename BaseT>
0026 struct inhibit_case_iteration_policy;
0027
0028 template <typename A, typename B>
0029 struct alternative;
0030
0031 template <typename A, typename B>
0032 struct longest_alternative;
0033
0034 template <typename A, typename B>
0035 struct shortest_alternative;
0036
0037 namespace impl
0038 {
0039 template <typename RT, typename ST, typename ScannerT, typename BaseT>
0040 inline RT
0041 contiguous_parser_parse(
0042 ST const& s,
0043 ScannerT const& scan,
0044 skipper_iteration_policy<BaseT> const&)
0045 {
0046 typedef scanner_policies<
0047 no_skipper_iteration_policy<
0048 BOOST_DEDUCED_TYPENAME ScannerT::iteration_policy_t>,
0049 BOOST_DEDUCED_TYPENAME ScannerT::match_policy_t,
0050 BOOST_DEDUCED_TYPENAME ScannerT::action_policy_t
0051 > policies_t;
0052
0053 scan.skip(scan);
0054 RT hit = s.parse(scan.change_policies(policies_t(scan)));
0055
0056 return hit;
0057 }
0058
0059 template <typename RT, typename ST, typename ScannerT, typename BaseT>
0060 inline RT
0061 contiguous_parser_parse(
0062 ST const& s,
0063 ScannerT const& scan,
0064 no_skipper_iteration_policy<BaseT> const&)
0065 {
0066 return s.parse(scan);
0067 }
0068
0069 template <typename RT, typename ST, typename ScannerT>
0070 inline RT
0071 contiguous_parser_parse(
0072 ST const& s,
0073 ScannerT const& scan,
0074 iteration_policy const&)
0075 {
0076 return s.parse(scan);
0077 }
0078
0079 template <
0080 typename RT,
0081 typename ParserT,
0082 typename ScannerT,
0083 typename BaseT>
0084 inline RT
0085 implicit_lexeme_parse(
0086 ParserT const& p,
0087 ScannerT const& scan,
0088 skipper_iteration_policy<BaseT> const&)
0089 {
0090 typedef scanner_policies<
0091 no_skipper_iteration_policy<
0092 BOOST_DEDUCED_TYPENAME ScannerT::iteration_policy_t>,
0093 BOOST_DEDUCED_TYPENAME ScannerT::match_policy_t,
0094 BOOST_DEDUCED_TYPENAME ScannerT::action_policy_t
0095 > policies_t;
0096
0097 scan.skip(scan);
0098 RT hit = p.parse_main(scan.change_policies(policies_t(scan)));
0099
0100 return hit;
0101 }
0102
0103 template <
0104 typename RT,
0105 typename ParserT,
0106 typename ScannerT,
0107 typename BaseT>
0108 inline RT
0109 implicit_lexeme_parse(
0110 ParserT const& p,
0111 ScannerT const& scan,
0112 no_skipper_iteration_policy<BaseT> const&)
0113 {
0114 return p.parse_main(scan);
0115 }
0116
0117 template <typename RT, typename ParserT, typename ScannerT>
0118 inline RT
0119 implicit_lexeme_parse(
0120 ParserT const& p,
0121 ScannerT const& scan,
0122 iteration_policy const&)
0123 {
0124 return p.parse_main(scan);
0125 }
0126
0127 template <typename RT, typename ST, typename ScannerT>
0128 inline RT
0129 inhibit_case_parser_parse(
0130 ST const& s,
0131 ScannerT const& scan,
0132 iteration_policy const&)
0133 {
0134 typedef scanner_policies<
0135 inhibit_case_iteration_policy<
0136 BOOST_DEDUCED_TYPENAME ScannerT::iteration_policy_t>,
0137 BOOST_DEDUCED_TYPENAME ScannerT::match_policy_t,
0138 BOOST_DEDUCED_TYPENAME ScannerT::action_policy_t
0139 > policies_t;
0140
0141 return s.parse(scan.change_policies(policies_t(scan)));
0142 }
0143
0144 template <typename RT, typename ST, typename ScannerT, typename BaseT>
0145 inline RT
0146 inhibit_case_parser_parse(
0147 ST const& s,
0148 ScannerT const& scan,
0149 inhibit_case_iteration_policy<BaseT> const&)
0150 {
0151 return s.parse(scan);
0152 }
0153
0154 template <typename T>
0155 struct to_longest_alternative
0156 {
0157 typedef T result_t;
0158 static result_t const&
0159 convert(T const& a)
0160 { return a; }
0161 };
0162
0163 template <typename A, typename B>
0164 struct to_longest_alternative<alternative<A, B> >
0165 {
0166 typedef typename to_longest_alternative<A>::result_t a_t;
0167 typedef typename to_longest_alternative<B>::result_t b_t;
0168 typedef longest_alternative<a_t, b_t> result_t;
0169
0170 static result_t
0171 convert(alternative<A, B> const& alt)
0172 {
0173 return result_t(
0174 to_longest_alternative<A>::convert(alt.left()),
0175 to_longest_alternative<B>::convert(alt.right()));
0176 }
0177 };
0178
0179 template <typename T>
0180 struct to_shortest_alternative
0181 {
0182 typedef T result_t;
0183 static result_t const&
0184 convert(T const& a)
0185 { return a; }
0186 };
0187
0188 template <typename A, typename B>
0189 struct to_shortest_alternative<alternative<A, B> >
0190 {
0191 typedef typename to_shortest_alternative<A>::result_t a_t;
0192 typedef typename to_shortest_alternative<B>::result_t b_t;
0193 typedef shortest_alternative<a_t, b_t> result_t;
0194
0195 static result_t
0196 convert(alternative<A, B> const& alt)
0197 {
0198 return result_t(
0199 to_shortest_alternative<A>::convert(alt.left()),
0200 to_shortest_alternative<B>::convert(alt.right()));
0201 }
0202 };
0203 }
0204
0205 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0206
0207 }}
0208
0209 #endif
0210