Get commit working in recursive mode.

This commit is contained in:
jzmaddock
2015-09-29 19:20:09 +01:00
parent c281c9cc40
commit b208ef4eed
5 changed files with 43 additions and 44 deletions

View File

@ -446,7 +446,9 @@ private:
bool match_fail();
bool match_accept();
bool match_commit();
#ifdef BOOST_REGEX_NON_RECURSIVE
bool skip_until_paren(int index, bool match = true);
#endif
// find procs stored in s_find_vtable:
bool find_restart_any();
@ -504,7 +506,10 @@ private:
unsigned char match_any_mask;
// recursion information:
std::vector<recursion_info<results_type> > recursion_stack;
#ifdef BOOST_REGEX_RECURSIVE
// Set to false by a (*COMMIT):
bool m_can_backtrack;
#endif
#ifdef BOOST_REGEX_NON_RECURSIVE
//
// additional members for non-recursive version:

View File

@ -80,6 +80,8 @@ void perl_matcher<BidiIterator, Allocator, traits>::construct_init(const basic_r
#ifdef BOOST_REGEX_NON_RECURSIVE
m_stack_base = 0;
m_backup_state = 0;
#elif defined(BOOST_REGEX_RECURSIVE)
m_can_backtrack = true;
#endif
// find the value to use for matching word boundaries:
m_word_mask = re.get_data().m_word_mask;
@ -803,6 +805,7 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_fail()
return false;
}
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::find_restart_any()
{

View File

@ -1073,39 +1073,6 @@ bool perl_matcher<BidiIterator, Allocator, traits>::skip_until_paren(int index,
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_accept()
{
#if 0
// Almost the same as match_match, but we need to close any half-open capturing groups:
for(unsigned i = 1; i < m_result.size(); ++i)
{
if((m_result[i].matched == false) && (m_result[i].first != last))
{
m_result.set_second(position, i);
}
}
if(!recursion_stack.empty())
{
// Skip forward to the end of this recursion:
while(pstate)
{
if(pstate->type == syntax_element_endmark)
if(static_cast<const re_brace*>(pstate)->index == recursion_stack.back().idx)
break;
pstate = pstate->next.p;
}
return true;
/*
int index = recursion_stack.back().idx;
pstate = recursion_stack.back().preturn_address;
*m_presult = recursion_stack.back().results;
push_recursion(index, recursion_stack.back().preturn_address, &recursion_stack.back().results);
recursion_stack.pop_back();
push_repeater_count(-(2 + index), &next_count);
return true;
*/
}
else
return match_match();
#endif
if(!recursion_stack.empty())
{
skip_until_paren(recursion_stack.back().idx);

View File

@ -151,7 +151,9 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_startmark()
m_independent = true;
const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
pstate = pstate->next.p->next.p;
bool can_backtrack = m_can_backtrack;
r = match_all_states();
m_can_backtrack = can_backtrack;
pstate = next_pstate;
m_independent = old_independent;
#ifdef BOOST_REGEX_MATCH_EXTRA
@ -286,7 +288,7 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_alt()
pstate = old_pstate;
position = oldposition;
}
return true;
return m_can_backtrack;
}
pstate = pstate->next.p;
return true;
@ -357,6 +359,8 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_rep()
pstate = rep->next.p;
if(match_all_states())
return true;
if(!m_can_backtrack)
return false;
// failed repeat, reset posistion and fall through for alternative:
position = pos;
}
@ -377,6 +381,8 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_rep()
pstate = rep->alt.p;
if(match_all_states())
return true;
if(!m_can_backtrack)
return false;
// failed alternative, reset posistion and fall through for repeat:
position = pos;
}
@ -441,7 +447,7 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_slow()
++state_count;
if(match_all_states())
return true;
if(count >= rep->max)
if((count >= rep->max) || !m_can_backtrack)
return false;
++count;
pstate = psingle;
@ -506,7 +512,7 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_fast()
++state_count;
if(match_all_states())
return true;
if(count >= rep->max)
if((count >= rep->max) || !m_can_backtrack)
return false;
if(save_pos == last)
return false;
@ -600,7 +606,7 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_char_repeat()
++state_count;
if(match_all_states())
return true;
if(count >= rep->max)
if((count >= rep->max) || !m_can_backtrack)
return false;
position = save_pos;
if(position == last)
@ -695,7 +701,7 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_set_repeat()
++state_count;
if(match_all_states())
return true;
if(count >= rep->max)
if((count >= rep->max) || !m_can_backtrack)
return false;
position = save_pos;
if(position == last)
@ -791,7 +797,7 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_long_set_repeat()
++state_count;
if(match_all_states())
return true;
if(count >= rep->max)
if((count >= rep->max) || !m_can_backtrack)
return false;
position = save_pos;
if(position == last)
@ -821,6 +827,8 @@ bool perl_matcher<BidiIterator, Allocator, traits>::backtrack_till_match(std::si
#pragma warning(push)
#pragma warning(disable:4127)
#endif
if(!m_can_backtrack)
return false;
if((m_match_flags & match_partial) && (position == last))
m_has_partial_match = true;
@ -886,7 +894,9 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_recursion()
repeater_count<BidiIterator>* saved = next_count;
repeater_count<BidiIterator> r(&next_count); // resets all repeat counts since we're recursing and starting fresh on those
next_count = &r;
bool can_backtrack = m_can_backtrack;
bool result = match_all_states();
m_can_backtrack = can_backtrack;
next_count = saved;
if(!result)
@ -983,7 +993,20 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_match()
return true;
}
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_commit()
{
m_can_backtrack = false;
restart = last;
pstate = pstate->next.p;
return true;
}
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_accept()
{
return true;
}
} // namespace BOOST_REGEX_DETAIL_NS
} // namespace boost