annotate DEPENDENCIES/generic/include/boost/xpressive/detail/dynamic/sequence.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 ///////////////////////////////////////////////////////////////////////////////
Chris@16 2 // sequence.hpp
Chris@16 3 //
Chris@16 4 // Copyright 2008 Eric Niebler. Distributed under the Boost
Chris@16 5 // Software License, Version 1.0. (See accompanying file
Chris@16 6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7
Chris@16 8 #ifndef BOOST_XPRESSIVE_DETAIL_DYNAMIC_SEQUENCE_HPP_EAN_04_10_2006
Chris@16 9 #define BOOST_XPRESSIVE_DETAIL_DYNAMIC_SEQUENCE_HPP_EAN_04_10_2006
Chris@16 10
Chris@16 11 // MS compatible compilers support #pragma once
Chris@101 12 #if defined(_MSC_VER)
Chris@16 13 # pragma once
Chris@16 14 #endif
Chris@16 15
Chris@16 16 #include <boost/assert.hpp>
Chris@16 17 #include <boost/intrusive_ptr.hpp>
Chris@16 18 #include <boost/xpressive/detail/utility/width.hpp>
Chris@16 19 #include <boost/xpressive/detail/detail_fwd.hpp>
Chris@16 20
Chris@16 21 namespace boost { namespace xpressive { namespace detail
Chris@16 22 {
Chris@16 23
Chris@16 24 ///////////////////////////////////////////////////////////////////////////////
Chris@16 25 // sequence
Chris@16 26 template<typename BidiIter>
Chris@16 27 struct sequence
Chris@16 28 {
Chris@16 29 sequence()
Chris@16 30 : pure_(true)
Chris@16 31 , width_(0)
Chris@16 32 , quant_(quant_none)
Chris@16 33 , head_()
Chris@16 34 , tail_(0)
Chris@16 35 , alt_end_xpr_()
Chris@16 36 , alternates_(0)
Chris@16 37 {
Chris@16 38 }
Chris@16 39
Chris@16 40 template<typename Matcher>
Chris@16 41 sequence(intrusive_ptr<dynamic_xpression<Matcher, BidiIter> > const &xpr)
Chris@16 42 : pure_(Matcher::pure)
Chris@16 43 , width_(xpr->Matcher::get_width())
Chris@16 44 , quant_(static_cast<quant_enum>(Matcher::quant))
Chris@16 45 , head_(xpr)
Chris@16 46 , tail_(&xpr->next_)
Chris@16 47 , alt_end_xpr_()
Chris@16 48 , alternates_(0)
Chris@16 49 {
Chris@16 50 }
Chris@16 51
Chris@16 52 template<typename Traits>
Chris@16 53 sequence(intrusive_ptr<dynamic_xpression<alternate_matcher<alternates_vector<BidiIter>, Traits>, BidiIter> > const &xpr)
Chris@16 54 : pure_(true)
Chris@16 55 , width_(0)
Chris@16 56 , quant_(quant_none)
Chris@16 57 , head_(xpr)
Chris@16 58 , tail_(&xpr->next_)
Chris@16 59 , alt_end_xpr_()
Chris@16 60 , alternates_(&xpr->alternates_)
Chris@16 61 {
Chris@16 62 }
Chris@16 63
Chris@16 64 bool empty() const
Chris@16 65 {
Chris@16 66 return !this->head_;
Chris@16 67 }
Chris@16 68
Chris@16 69 sequence<BidiIter> &operator +=(sequence<BidiIter> const &that)
Chris@16 70 {
Chris@16 71 if(this->empty())
Chris@16 72 {
Chris@16 73 *this = that;
Chris@16 74 }
Chris@16 75 else if(!that.empty())
Chris@16 76 {
Chris@16 77 *this->tail_ = that.head_;
Chris@16 78 this->tail_ = that.tail_;
Chris@16 79 // keep track of sequence width and purity
Chris@16 80 this->width_ += that.width_;
Chris@16 81 this->pure_ = this->pure_ && that.pure_;
Chris@16 82 this->set_quant_();
Chris@16 83 }
Chris@16 84 return *this;
Chris@16 85 }
Chris@16 86
Chris@16 87 sequence<BidiIter> &operator |=(sequence<BidiIter> that)
Chris@16 88 {
Chris@16 89 BOOST_ASSERT(!this->empty());
Chris@16 90 BOOST_ASSERT(0 != this->alternates_);
Chris@16 91
Chris@16 92 // Keep track of width and purity
Chris@16 93 if(this->alternates_->empty())
Chris@16 94 {
Chris@16 95 this->width_ = that.width_;
Chris@16 96 this->pure_ = that.pure_;
Chris@16 97 }
Chris@16 98 else
Chris@16 99 {
Chris@16 100 this->width_ |= that.width_;
Chris@16 101 this->pure_ = this->pure_ && that.pure_;
Chris@16 102 }
Chris@16 103
Chris@16 104 // through the wonders of reference counting, all alternates_ can share an end_alternate
Chris@16 105 if(!this->alt_end_xpr_)
Chris@16 106 {
Chris@16 107 this->alt_end_xpr_ = new alt_end_xpr_type;
Chris@16 108 }
Chris@16 109
Chris@16 110 // terminate each alternate with an alternate_end_matcher
Chris@16 111 that += sequence(this->alt_end_xpr_);
Chris@16 112 this->alternates_->push_back(that.head_);
Chris@16 113 this->set_quant_();
Chris@16 114 return *this;
Chris@16 115 }
Chris@16 116
Chris@16 117 void repeat(quant_spec const &spec)
Chris@16 118 {
Chris@16 119 this->xpr().matchable()->repeat(spec, *this);
Chris@16 120 }
Chris@16 121
Chris@16 122 shared_matchable<BidiIter> const &xpr() const
Chris@16 123 {
Chris@16 124 return this->head_;
Chris@16 125 }
Chris@16 126
Chris@16 127 detail::width width() const
Chris@16 128 {
Chris@16 129 return this->width_;
Chris@16 130 }
Chris@16 131
Chris@16 132 bool pure() const
Chris@16 133 {
Chris@16 134 return this->pure_;
Chris@16 135 }
Chris@16 136
Chris@16 137 quant_enum quant() const
Chris@16 138 {
Chris@16 139 return this->quant_;
Chris@16 140 }
Chris@16 141
Chris@16 142 private:
Chris@16 143 typedef dynamic_xpression<alternate_end_matcher, BidiIter> alt_end_xpr_type;
Chris@16 144
Chris@16 145 void set_quant_()
Chris@16 146 {
Chris@16 147 this->quant_ = (!is_unknown(this->width_) && this->pure_)
Chris@16 148 ? (!this->width_ ? quant_none : quant_fixed_width)
Chris@16 149 : quant_variable_width;
Chris@16 150 }
Chris@16 151
Chris@16 152 bool pure_;
Chris@16 153 detail::width width_;
Chris@16 154 quant_enum quant_;
Chris@16 155 shared_matchable<BidiIter> head_;
Chris@16 156 shared_matchable<BidiIter> *tail_;
Chris@16 157 intrusive_ptr<alt_end_xpr_type> alt_end_xpr_;
Chris@16 158 alternates_vector<BidiIter> *alternates_;
Chris@16 159 };
Chris@16 160
Chris@16 161 template<typename BidiIter>
Chris@16 162 inline sequence<BidiIter> operator +(sequence<BidiIter> left, sequence<BidiIter> const &right)
Chris@16 163 {
Chris@16 164 return left += right;
Chris@16 165 }
Chris@16 166
Chris@16 167 template<typename BidiIter>
Chris@16 168 inline sequence<BidiIter> operator |(sequence<BidiIter> left, sequence<BidiIter> const &right)
Chris@16 169 {
Chris@16 170 return left |= right;
Chris@16 171 }
Chris@16 172
Chris@16 173 }}} // namespace boost::xpressive::detail
Chris@16 174
Chris@16 175 #endif