#include <xtl_op_impl.h>
Public Member Functions | |
xtl_op_base_unary (ExprT const &expr_) | |
Constructs and initializes the object. | |
Protected Member Functions | |
template<typename SubstrT > | |
size_t | kleene_list (SubstrT &edge_, size_t upper_limit_=0) |
Helper function to exercise Kleene list after first match has been found. | |
Protected Attributes | |
ExprT | m_expr |
Stores grammar expression specified as operand. |
ExprT | specifies type of grammar expression object, determined by the C++ compiler at compile time. |
Definition at line 76 of file xtl_op_impl.h.
cttl_impl::xtl_op_base_unary< ExprT >::xtl_op_base_unary | ( | ExprT const & | expr_ | ) |
Constructs and initializes the object.
Definition at line 86 of file xtl_op_impl.h.
00087 : m_expr( expr_ ) 00088 { 00089 }
size_t cttl_impl::xtl_op_base_unary< ExprT >::kleene_list | ( | SubstrT & | edge_, | |
size_t | upper_limit_ = 0 | |||
) | [protected] |
Helper function to exercise Kleene list after first match has been found.
Finds second, third, and so on, matches for m_expr
SubstrT | specifies type of the parseable substring. Can be either cttl::const_edge or cttl::edge . |
edge_ | reference to the parseable substring. | |
upper_limit_ | If not zero, suggests the upper limit for a number of matches. The matching stops as soon as this exact number of matches is found. |
edge_
parameter, is consumed accordingly to the size of the matched symbols. Definition at line 116 of file xtl_op_impl.h.
00117 { 00118 // if this offset stops progressing, we must bail out of infinite loop 00119 typename SubstrT::offset_guard_T iteration_offset( edge_.first, SubstrT::string_T::npos ); 00120 typename SubstrT::offset_guard_T match_offset( edge_.first, SubstrT::string_T::npos ); 00121 00122 // statically captured offset to watch mutablility of the substring. 00123 // substring is considered mutated if saved_end_offset no longer matches the end of the substring. 00124 size_t saved_end_offset = edge_.second.offset(); 00125 00126 size_t cnt = 0; 00127 while ( ( match_offset = m_expr.match( edge_ ) ) != SubstrT::string_T::npos ) { 00128 // If substring is mutable and the user deleted matched fragment, 00129 // edge_.first.offset() is brought back, therefore, it will appear here 00130 // as an empty (epsilon) match. In such case, if substring has mutated, 00131 // the search should continue. 00132 00133 // Check if the substring has mutated: 00134 if ( saved_end_offset == edge_.second.offset() ) { 00135 if ( iteration_offset == edge_.first.offset() ) { 00136 CTTL_TRACE_TEXT( 'i', "kleene_list: iteration made no progress: bailing out" ); 00137 break; // second, third, etc., iteration hasn't made any progress: bail out 00138 } 00139 00140 ++cnt; 00141 00142 if ( match_offset == edge_.first.offset() ) { 00143 // second, third, etc., iteration succeeded on an empty substring, 00144 // do not count it as a match, bail out of the loop: 00145 CTTL_TRACE_TEXT( 'i', "kleene_list: epsilon match: bailing out" ); 00146 break; 00147 } 00148 00149 } else { 00150 ++cnt; 00151 saved_end_offset = edge_.second.offset(); 00152 } 00153 00154 if ( upper_limit_ && ( cnt == upper_limit_ ) ) { 00155 CTTL_TRACE_TEXT( 'i', "kleene_list: user-specified match limit: bailing out" ); 00156 break; 00157 } 00158 00159 iteration_offset = edge_.first.offset(); 00160 } 00161 return cnt; 00162 }
ExprT cttl_impl::xtl_op_base_unary< ExprT >::m_expr [protected] |