File indexing completed on 2025-01-31 10:01:55
0001
0002
0003
0004
0005
0006
0007
0008
0009 #if !defined(BOOST_SPIRIT_SKIPPER_IPP)
0010 #define BOOST_SPIRIT_SKIPPER_IPP
0011
0012
0013 namespace boost { namespace spirit {
0014
0015 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0016
0017 struct space_parser;
0018 template <typename BaseT>
0019 struct no_skipper_iteration_policy;
0020
0021 namespace impl
0022 {
0023 template <typename ST, typename ScannerT, typename BaseT>
0024 inline void
0025 skipper_skip(
0026 ST const& s,
0027 ScannerT const& scan,
0028 skipper_iteration_policy<BaseT> const&)
0029 {
0030 typedef scanner_policies<
0031 no_skipper_iteration_policy<
0032 BOOST_DEDUCED_TYPENAME ScannerT::iteration_policy_t>,
0033 BOOST_DEDUCED_TYPENAME ScannerT::match_policy_t,
0034 BOOST_DEDUCED_TYPENAME ScannerT::action_policy_t
0035 > policies_t;
0036
0037 scanner<BOOST_DEDUCED_TYPENAME ScannerT::iterator_t, policies_t>
0038 scan2(scan.first, scan.last, policies_t(scan));
0039 typedef typename ScannerT::iterator_t iterator_t;
0040
0041 for (;;)
0042 {
0043 iterator_t save = scan.first;
0044 if (!s.parse(scan2))
0045 {
0046 scan.first = save;
0047 break;
0048 }
0049 }
0050 }
0051
0052 template <typename ST, typename ScannerT, typename BaseT>
0053 inline void
0054 skipper_skip(
0055 ST const& s,
0056 ScannerT const& scan,
0057 no_skipper_iteration_policy<BaseT> const&)
0058 {
0059 for (;;)
0060 {
0061 typedef typename ScannerT::iterator_t iterator_t;
0062 iterator_t save = scan.first;
0063 if (!s.parse(scan))
0064 {
0065 scan.first = save;
0066 break;
0067 }
0068 }
0069 }
0070
0071 template <typename ST, typename ScannerT>
0072 inline void
0073 skipper_skip(
0074 ST const& s,
0075 ScannerT const& scan,
0076 iteration_policy const&)
0077 {
0078 for (;;)
0079 {
0080 typedef typename ScannerT::iterator_t iterator_t;
0081 iterator_t save = scan.first;
0082 if (!s.parse(scan))
0083 {
0084 scan.first = save;
0085 break;
0086 }
0087 }
0088 }
0089
0090 template <typename SkipT>
0091 struct phrase_parser
0092 {
0093 template <typename IteratorT, typename ParserT>
0094 static parse_info<IteratorT>
0095 parse(
0096 IteratorT const& first_,
0097 IteratorT const& last,
0098 ParserT const& p,
0099 SkipT const& skip)
0100 {
0101 typedef skip_parser_iteration_policy<SkipT> it_policy_t;
0102 typedef scanner_policies<it_policy_t> scan_policies_t;
0103 typedef scanner<IteratorT, scan_policies_t> scanner_t;
0104
0105 it_policy_t iter_policy(skip);
0106 scan_policies_t policies(iter_policy);
0107 IteratorT first = first_;
0108 scanner_t scan(first, last, policies);
0109 match<nil_t> hit = p.parse(scan);
0110 return parse_info<IteratorT>(
0111 first, hit, hit && (first == last),
0112 hit.length());
0113 }
0114 };
0115
0116 template <>
0117 struct phrase_parser<space_parser>
0118 {
0119 template <typename IteratorT, typename ParserT>
0120 static parse_info<IteratorT>
0121 parse(
0122 IteratorT const& first_,
0123 IteratorT const& last,
0124 ParserT const& p,
0125 space_parser const&)
0126 {
0127 typedef skipper_iteration_policy<> it_policy_t;
0128 typedef scanner_policies<it_policy_t> scan_policies_t;
0129 typedef scanner<IteratorT, scan_policies_t> scanner_t;
0130
0131 IteratorT first = first_;
0132 scanner_t scan(first, last);
0133 match<nil_t> hit = p.parse(scan);
0134 return parse_info<IteratorT>(
0135 first, hit, hit && (first == last),
0136 hit.length());
0137 }
0138 };
0139 }
0140
0141
0142
0143
0144
0145
0146 template <typename IteratorT, typename ParserT, typename SkipT>
0147 inline parse_info<IteratorT>
0148 parse(
0149 IteratorT const& first,
0150 IteratorT const& last,
0151 parser<ParserT> const& p,
0152 parser<SkipT> const& skip)
0153 {
0154 return impl::phrase_parser<SkipT>::
0155 parse(first, last, p.derived(), skip.derived());
0156 }
0157
0158
0159
0160
0161
0162
0163 template <typename CharT, typename ParserT, typename SkipT>
0164 inline parse_info<CharT const*>
0165 parse(
0166 CharT const* str,
0167 parser<ParserT> const& p,
0168 parser<SkipT> const& skip)
0169 {
0170 CharT const* last = str;
0171 while (*last)
0172 last++;
0173 return parse(str, last, p, skip);
0174 }
0175
0176 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0177
0178 }}
0179
0180 #endif
0181