Match Op declaration order in switches

This commit is contained in:
Maxime Coste 2024-03-22 20:05:43 +11:00
parent 2dd69b3d96
commit 7e75c9a1df
2 changed files with 14 additions and 14 deletions

View File

@ -1088,6 +1088,12 @@ String dump_regex(const CompiledRegex& program)
case CompiledRegex::AnyCharExceptNewLine: case CompiledRegex::AnyCharExceptNewLine:
res += "anything but newline\n"; res += "anything but newline\n";
break; break;
case CompiledRegex::CharClass:
res += format("character class {}\n", inst.param.character_class_index);
break;
case CompiledRegex::CharType:
res += format("character type {}\n", to_underlying(inst.param.character_type));
break;
case CompiledRegex::Jump: case CompiledRegex::Jump:
res += format("jump {}\n", inst.param.jump_target); res += format("jump {}\n", inst.param.jump_target);
break; break;
@ -1101,12 +1107,6 @@ String dump_regex(const CompiledRegex& program)
case CompiledRegex::Save: case CompiledRegex::Save:
res += format("save {}\n", inst.param.save_index); res += format("save {}\n", inst.param.save_index);
break; break;
case CompiledRegex::CharClass:
res += format("character class {}\n", inst.param.character_class_index);
break;
case CompiledRegex::CharType:
res += format("character type {}\n", to_underlying(inst.param.character_type));
break;
case CompiledRegex::LineAssertion: case CompiledRegex::LineAssertion:
res += format("line {}\n", inst.param.line_start ? "start" : "end");; res += format("line {}\n", inst.param.line_start ? "start" : "end");;
break; break;

View File

@ -413,6 +413,14 @@ private:
if (pos != config.end and cp != '\n') if (pos != config.end and cp != '\n')
return consumed(); return consumed();
return failed(); return failed();
case CompiledRegex::CharClass:
if (pos == config.end)
return failed();
return m_program.character_classes[inst.param.character_class_index].matches(cp) ? consumed() : failed();
case CompiledRegex::CharType:
if (pos == config.end)
return failed();
return is_ctype(inst.param.character_type, cp) ? consumed() : failed();
case CompiledRegex::Jump: case CompiledRegex::Jump:
thread.inst = inst.param.jump_target; thread.inst = inst.param.jump_target;
break; break;
@ -440,14 +448,6 @@ private:
m_saves[thread.saves].pos[inst.param.save_index] = pos; m_saves[thread.saves].pos[inst.param.save_index] = pos;
m_saves[thread.saves].valid_mask |= (1 << inst.param.save_index); m_saves[thread.saves].valid_mask |= (1 << inst.param.save_index);
break; break;
case CompiledRegex::CharClass:
if (pos == config.end)
return failed();
return m_program.character_classes[inst.param.character_class_index].matches(cp) ? consumed() : failed();
case CompiledRegex::CharType:
if (pos == config.end)
return failed();
return is_ctype(inst.param.character_type, cp) ? consumed() : failed();
case CompiledRegex::LineAssertion: case CompiledRegex::LineAssertion:
if (not (inst.param.line_start ? is_line_start(pos, config) : is_line_end(pos, config))) if (not (inst.param.line_start ? is_line_start(pos, config) : is_line_end(pos, config)))
return failed(); return failed();