File indexing completed on 2025-01-18 09:53:51
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_STATIC_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_STATIC_STATIC_HPP_EAN_10_04_2005
0010
0011
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015
0016 #include <boost/mpl/assert.hpp>
0017 #include <boost/xpressive/detail/detail_fwd.hpp>
0018 #include <boost/xpressive/detail/core/state.hpp>
0019 #include <boost/xpressive/detail/core/linker.hpp>
0020 #include <boost/xpressive/detail/core/peeker.hpp>
0021 #include <boost/xpressive/detail/static/placeholders.hpp>
0022 #include <boost/xpressive/detail/utility/width.hpp>
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 namespace boost { namespace xpressive { namespace detail
0033 {
0034
0035
0036
0037
0038 template<typename Top, typename Next>
0039 struct stacked_xpression
0040 : Next
0041 {
0042
0043
0044 template<typename BidiIter>
0045 bool match(match_state<BidiIter> &state) const
0046 {
0047 return static_cast<Next const *>(this)->
0048 BOOST_NESTED_TEMPLATE push_match<Top>(state);
0049 }
0050
0051
0052
0053
0054 template<typename BidiIter>
0055 static bool top_match(match_state<BidiIter> &state, void const *top)
0056 {
0057 return static_cast<Top const *>(top)->
0058 BOOST_NESTED_TEMPLATE push_match<Top>(state);
0059 }
0060
0061
0062
0063
0064 template<typename BidiIter>
0065 static bool pop_match(match_state<BidiIter> &state, void const *top)
0066 {
0067 return static_cast<Top const *>(top)->match(state);
0068 }
0069
0070
0071
0072
0073 template<typename BidiIter>
0074 bool skip_match(match_state<BidiIter> &state) const
0075 {
0076
0077
0078
0079 return Top::skip_impl(*static_cast<Next const *>(this), state);
0080 }
0081
0082
0083
0084
0085
0086 template<typename That, typename BidiIter>
0087 static bool skip_impl(That const &that, match_state<BidiIter> &state)
0088 {
0089 return that.BOOST_NESTED_TEMPLATE push_match<Top>(state);
0090 }
0091 };
0092
0093
0094
0095
0096 template<typename Top, typename Next>
0097 inline stacked_xpression<Top, Next> const &stacked_xpression_cast(Next const &next)
0098 {
0099
0100
0101
0102
0103 BOOST_MPL_ASSERT_RELATION(sizeof(stacked_xpression<Top, Next>), ==, sizeof(Next));
0104 return *static_cast<stacked_xpression<Top, Next> const *>(&next);
0105 }
0106
0107
0108
0109
0110 template<typename Matcher, typename Next>
0111 struct static_xpression
0112 : Matcher
0113 {
0114 Next next_;
0115
0116 BOOST_STATIC_CONSTANT(bool, pure = Matcher::pure && Next::pure);
0117 BOOST_STATIC_CONSTANT(
0118 std::size_t
0119 , width =
0120 Matcher::width != unknown_width::value && Next::width != unknown_width::value
0121 ? Matcher::width + Next::width
0122 : unknown_width::value
0123 );
0124
0125 static_xpression(Matcher const &matcher = Matcher(), Next const &next = Next())
0126 : Matcher(matcher)
0127 , next_(next)
0128 {
0129 }
0130
0131
0132
0133 template<typename BidiIter>
0134 bool match(match_state<BidiIter> &state) const
0135 {
0136 return this->Matcher::match(state, this->next_);
0137 }
0138
0139
0140
0141
0142 template<typename Top, typename BidiIter>
0143 bool push_match(match_state<BidiIter> &state) const
0144 {
0145 return this->Matcher::match(state, stacked_xpression_cast<Top>(this->next_));
0146 }
0147
0148
0149
0150 template<typename That, typename BidiIter>
0151 static bool skip_impl(That const &that, match_state<BidiIter> &state)
0152 {
0153 return that.match(state);
0154 }
0155
0156
0157 template<typename Char>
0158 void link(xpression_linker<Char> &linker) const
0159 {
0160 linker.accept(*static_cast<Matcher const *>(this), &this->next_);
0161 this->next_.link(linker);
0162 }
0163
0164
0165 template<typename Char>
0166 void peek(xpression_peeker<Char> &peeker) const
0167 {
0168 this->peek_next_(peeker.accept(*static_cast<Matcher const *>(this)), peeker);
0169 }
0170
0171
0172 detail::width get_width() const
0173 {
0174 return this->get_width_(mpl::size_t<width>());
0175 }
0176
0177 private:
0178
0179 static_xpression &operator =(static_xpression const &);
0180
0181 template<typename Char>
0182 void peek_next_(mpl::true_, xpression_peeker<Char> &peeker) const
0183 {
0184 this->next_.peek(peeker);
0185 }
0186
0187 template<typename Char>
0188 void peek_next_(mpl::false_, xpression_peeker<Char> &) const
0189 {
0190
0191 }
0192
0193 template<std::size_t Width>
0194 detail::width get_width_(mpl::size_t<Width>) const
0195 {
0196 return Width;
0197 }
0198
0199 detail::width get_width_(unknown_width) const
0200 {
0201
0202
0203 return this->Matcher::get_width() + this->next_.get_width();
0204 }
0205 };
0206
0207
0208
0209
0210 template<typename Matcher>
0211 inline static_xpression<Matcher> const
0212 make_static(Matcher const &matcher)
0213 {
0214 return static_xpression<Matcher>(matcher);
0215 }
0216
0217 template<typename Matcher, typename Next>
0218 inline static_xpression<Matcher, Next> const
0219 make_static(Matcher const &matcher, Next const &next)
0220 {
0221 return static_xpression<Matcher, Next>(matcher, next);
0222 }
0223
0224
0225
0226
0227 struct no_next
0228 {
0229 BOOST_STATIC_CONSTANT(std::size_t, width = 0);
0230 BOOST_STATIC_CONSTANT(bool, pure = true);
0231
0232 template<typename Char>
0233 void link(xpression_linker<Char> &) const
0234 {
0235 }
0236
0237 template<typename Char>
0238 void peek(xpression_peeker<Char> &peeker) const
0239 {
0240 peeker.fail();
0241 }
0242
0243 detail::width get_width() const
0244 {
0245 return 0;
0246 }
0247 };
0248
0249
0250
0251
0252 inline int get_mark_number(basic_mark_tag const &mark)
0253 {
0254 return proto::value(mark).mark_number_;
0255 }
0256
0257 }}}
0258
0259 #endif