File indexing completed on 2025-01-31 10:02:35
0001
0002
0003
0004
0005
0006
0007 #if !defined(BOOST_SPIRIT_X3_PARSE_APRIL_16_2006_0442PM)
0008 #define BOOST_SPIRIT_X3_PARSE_APRIL_16_2006_0442PM
0009
0010 #include <boost/spirit/home/x3/support/context.hpp>
0011 #include <boost/spirit/home/x3/core/parser.hpp>
0012 #include <boost/spirit/home/x3/core/skip_over.hpp>
0013 #include <boost/iterator/iterator_concepts.hpp>
0014
0015 namespace boost { namespace spirit { namespace x3
0016 {
0017
0018 template <typename Iterator, typename Parser, typename Attribute>
0019 inline bool
0020 parse_main(
0021 Iterator& first
0022 , Iterator last
0023 , Parser const& p
0024 , Attribute& attr)
0025 {
0026
0027
0028
0029
0030 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<Iterator>));
0031 BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversalConcept<Iterator>));
0032
0033
0034
0035
0036 return as_parser(p).parse(first, last, unused, unused, attr);
0037 }
0038
0039
0040 template <typename Iterator, typename Parser, typename Attribute>
0041 inline bool
0042 parse(
0043 Iterator& first
0044 , Iterator last
0045 , Parser const& p
0046 , Attribute& attr)
0047 {
0048 return parse_main(first, last, p, attr);
0049 }
0050
0051
0052 template <typename Iterator, typename Parser, typename Attribute>
0053 inline bool
0054 parse(
0055 Iterator const& first_
0056 , Iterator last
0057 , Parser const& p
0058 , Attribute& attr)
0059 {
0060 Iterator first = first_;
0061 return parse_main(first, last, p, attr);
0062 }
0063
0064
0065 template <typename Iterator, typename Parser>
0066 inline bool
0067 parse(
0068 Iterator& first
0069 , Iterator last
0070 , Parser const& p)
0071 {
0072 return parse_main(first, last, p, unused);
0073 }
0074
0075
0076 template <typename Iterator, typename Parser>
0077 inline bool
0078 parse(
0079 Iterator const& first_
0080 , Iterator last
0081 , Parser const& p)
0082 {
0083 Iterator first = first_;
0084 return parse_main(first, last, p, unused);
0085 }
0086
0087
0088 enum class skip_flag
0089 {
0090 post_skip,
0091 dont_post_skip
0092 };
0093
0094
0095 template <typename Iterator, typename Parser, typename Skipper, typename Attribute>
0096 inline bool
0097 phrase_parse_main(
0098 Iterator& first
0099 , Iterator last
0100 , Parser const& p
0101 , Skipper const& s
0102 , Attribute& attr
0103 , skip_flag post_skip = skip_flag::post_skip)
0104 {
0105
0106
0107
0108
0109 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<Iterator>));
0110 BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversalConcept<Iterator>));
0111
0112 static_assert(!std::is_same<Skipper, unused_type>::value,
0113 "Error! Skipper cannot be unused_type.");
0114
0115
0116
0117
0118 auto skipper_ctx = make_context<skipper_tag>(as_parser(s));
0119 bool r = as_parser(p).parse(first, last, skipper_ctx, unused, attr);
0120 if (post_skip == skip_flag::post_skip)
0121 x3::skip_over(first, last, skipper_ctx);
0122 return r;
0123 }
0124
0125
0126 template <typename Iterator, typename Parser, typename Skipper, typename Attribute>
0127 inline bool
0128 phrase_parse(
0129 Iterator& first
0130 , Iterator last
0131 , Parser const& p
0132 , Skipper const& s
0133 , Attribute& attr
0134 , skip_flag post_skip = skip_flag::post_skip)
0135 {
0136 return phrase_parse_main(first, last, p, s, attr, post_skip);
0137 }
0138
0139
0140 template <typename Iterator, typename Parser, typename Skipper, typename Attribute>
0141 inline bool
0142 phrase_parse(
0143 Iterator const& first_
0144 , Iterator last
0145 , Parser const& p
0146 , Skipper const& s
0147 , Attribute& attr
0148 , skip_flag post_skip = skip_flag::post_skip)
0149 {
0150 Iterator first = first_;
0151 return phrase_parse_main(first, last, p, s, attr, post_skip);
0152 }
0153
0154
0155 template <typename Iterator, typename Parser, typename Skipper>
0156 inline bool
0157 phrase_parse(
0158 Iterator& first
0159 , Iterator last
0160 , Parser const& p
0161 , Skipper const& s
0162 , skip_flag post_skip = skip_flag::post_skip)
0163 {
0164 return phrase_parse_main(first, last, p, s, unused, post_skip);
0165 }
0166
0167
0168 template <typename Iterator, typename Parser, typename Skipper>
0169 inline bool
0170 phrase_parse(
0171 Iterator const& first_
0172 , Iterator last
0173 , Parser const& p
0174 , Skipper const& s
0175 , skip_flag post_skip = skip_flag::post_skip)
0176 {
0177 Iterator first = first_;
0178 return phrase_parse_main(first, last, p, s, unused, post_skip);
0179 }
0180
0181
0182 template <typename Skipper>
0183 struct phrase_parse_context
0184 {
0185 typedef decltype(
0186 make_context<skipper_tag>(as_parser(std::declval<Skipper>())))
0187 type;
0188 };
0189 }}}
0190
0191 #endif