1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:57:35 +00:00

LibRegex: Fix greedy/reluctant modifiers in PosixExtendedParser

Also fixes the issue with assertions causing early termination when
they fail.
This commit is contained in:
AnotherTest 2020-11-19 18:57:39 +03:30 committed by Andreas Kling
parent 45e5661296
commit 92ea9ed4a5
5 changed files with 42 additions and 26 deletions

View file

@ -202,23 +202,23 @@ ALWAYS_INLINE bool PosixExtendedParser::parse_repetition_symbol(ByteCode& byteco
} else if (match(TokenType::Plus)) {
consume();
bool greedy = match(TokenType::Questionmark);
if (greedy)
bool nongreedy = match(TokenType::Questionmark);
if (nongreedy)
consume();
// Note: dont touch match_length_minimum, it's already correct
bytecode_to_repeat.insert_bytecode_repetition_min_one(bytecode_to_repeat, greedy);
bytecode_to_repeat.insert_bytecode_repetition_min_one(bytecode_to_repeat, !nongreedy);
return !has_error();
} else if (match(TokenType::Asterisk)) {
consume();
match_length_minimum = 0;
bool greedy = match(TokenType::Questionmark);
if (greedy)
bool nongreedy = match(TokenType::Questionmark);
if (nongreedy)
consume();
bytecode_to_repeat.insert_bytecode_repetition_any(bytecode_to_repeat, greedy);
bytecode_to_repeat.insert_bytecode_repetition_any(bytecode_to_repeat, !nongreedy);
return !has_error();
@ -226,11 +226,11 @@ ALWAYS_INLINE bool PosixExtendedParser::parse_repetition_symbol(ByteCode& byteco
consume();
match_length_minimum = 0;
bool greedy = match(TokenType::Questionmark);
if (greedy)
bool nongreedy = match(TokenType::Questionmark);
if (nongreedy)
consume();
bytecode_to_repeat.insert_bytecode_repetition_zero_or_one(bytecode_to_repeat, greedy);
bytecode_to_repeat.insert_bytecode_repetition_zero_or_one(bytecode_to_repeat, !nongreedy);
return !has_error();
}