Regex: min/max quantifiers can be non greedy as well

This commit is contained in:
Maxime Coste 2017-10-02 15:35:21 +08:00
parent f02b2645da
commit b4f923b7fc

View File

@ -441,7 +441,7 @@ private:
if (*it++ != '}') if (*it++ != '}')
parse_error("expected closing bracket"); parse_error("expected closing bracket");
m_pos = it; m_pos = it;
return {ParsedRegex::Quantifier::RepeatMinMax, true, min, max}; return {ParsedRegex::Quantifier::RepeatMinMax, check_greedy(), min, max};
} }
default: return {ParsedRegex::Quantifier::One}; default: return {ParsedRegex::Quantifier::One};
} }
@ -920,6 +920,23 @@ auto test_regex = UnitTest{[]{
kak_assert(not vm.exec("efg")); kak_assert(not vm.exec("efg"));
} }
{
TestVM vm{R"((a{3,5})a+)"};
kak_assert(vm.exec("aaaaaa", true, true));
kak_assert(StringView{vm.m_captures[2], vm.m_captures[3]} == "aaaaa");
}
{
TestVM vm{R"((a{3,5}?)a+)"};
kak_assert(vm.exec("aaaaaa", true, true));
kak_assert(StringView{vm.m_captures[2], vm.m_captures[3]} == "aaa");
}
{
TestVM vm{R"((a{3,5}?)a)"};
kak_assert(vm.exec("aaaa"));
}
{ {
TestVM vm{R"(\d{3})"}; TestVM vm{R"(\d{3})"};
kak_assert(vm.exec("123")); kak_assert(vm.exec("123"));