1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:07:34 +00:00

LibRegex: Implement an ECMA262 Regex quirk with negative lookarounds

This implements the quirk defined by "Note 3" in section "Canonicalize"
(https://tc39.es/ecma262/#sec-runtime-semantics-canonicalize-ch).

Crosses off another quirk from #6042.
This commit is contained in:
Ali Mohammad Pur 2022-01-21 14:30:47 +03:30 committed by Ali Mohammad Pur
parent bfe8f312f3
commit c11be92e23
4 changed files with 54 additions and 16 deletions

View file

@ -254,6 +254,20 @@ private:
size_t ensure_total_number_of_capturing_parenthesis();
void enter_capture_group_scope() { m_capture_groups_in_scope.empend(); }
void exit_capture_group_scope()
{
auto last = m_capture_groups_in_scope.take_last();
m_capture_groups_in_scope.last().extend(move(last));
}
void clear_all_capture_groups_in_scope(ByteCode& stack)
{
for (auto& index : m_capture_groups_in_scope.last())
stack.insert_bytecode_clear_capture_group(index);
};
// ECMA-262's flavour of regex is a bit weird in that it allows backrefs to reference "future" captures, and such backrefs
// always match the empty string. So we have to know how many capturing parenthesis there are, but we don't want to always
// parse it twice, so we'll just do so when it's actually needed.