Added initial support for recursive expressions.

Updated docs and tests accordingly.

[SVN r54994]
This commit is contained in:
John Maddock
2009-07-17 10:23:50 +00:00
parent 02a629baf7
commit 5a6bc29d7c
44 changed files with 1013 additions and 264 deletions

View File

@ -285,7 +285,8 @@ public:
}
~repeater_count()
{
*stack = next;
if(next)
*stack = next;
}
std::size_t get_count() { return count; }
int get_id() { return state_id; }
@ -325,6 +326,17 @@ enum saved_state_type
saved_state_count = 14
};
template <class Results>
struct recursion_info
{
typedef typename Results::value_type value_type;
typedef typename value_type::iterator iterator;
int id;
const re_syntax_base* preturn_address;
Results results;
repeater_count<iterator>* repeater_stack;
};
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4251 4231 4660)
@ -340,6 +352,7 @@ public:
typedef std::size_t traits_size_type;
typedef typename is_byte<char_type>::width_type width_type;
typedef typename regex_iterator_traits<BidiIterator>::difference_type difference_type;
typedef match_results<BidiIterator, Allocator> results_type;
perl_matcher(BidiIterator first, BidiIterator end,
match_results<BidiIterator, Allocator>& what,
@ -348,7 +361,7 @@ public:
BidiIterator l_base)
: m_result(what), base(first), last(end),
position(first), backstop(l_base), re(e), traits_inst(e.get_traits()),
m_independent(false), next_count(&rep_obj), rep_obj(&next_count)
m_independent(false), next_count(&rep_obj), rep_obj(&next_count), recursion_stack_position(0)
{
construct_init(e, f);
}
@ -413,6 +426,7 @@ private:
#ifdef BOOST_REGEX_RECURSIVE
bool backtrack_till_match(std::size_t count);
#endif
bool match_recursion();
// find procs stored in s_find_vtable:
bool find_restart_any();
@ -468,6 +482,9 @@ private:
typename traits::char_class_type m_word_mask;
// the bitmask to use when determining whether a match_any matches a newline or not:
unsigned char match_any_mask;
// recursion information:
recursion_info<results_type> recursion_stack[50];
unsigned recursion_stack_position;
#ifdef BOOST_REGEX_NON_RECURSIVE
//
@ -491,6 +508,8 @@ private:
bool unwind_short_set_repeat(bool);
bool unwind_long_set_repeat(bool);
bool unwind_non_greedy_repeat(bool);
bool unwind_recursion(bool);
bool unwind_recursion_pop(bool);
void destroy_single_repeat();
void push_matched_paren(int index, const sub_match<BidiIterator>& sub);
void push_recursion_stopper();
@ -499,7 +518,8 @@ private:
void push_repeater_count(int i, repeater_count<BidiIterator>** s);
void push_single_repeat(std::size_t c, const re_repeat* r, BidiIterator last_position, int state_id);
void push_non_greedy_repeat(const re_syntax_base* ps);
void push_recursion(int id, const re_syntax_base* p, results_type* presults);
void push_recursion_pop();
// pointer to base of stack:
saved_state* m_stack_base;