feat(regexp): 迁移到 regress 引擎(backref/lookaround/命名组/v-flag)+ 手动 \$ 展开 replace + exec 捕获组数组

This commit is contained in:
爱特每羊队
2026-08-07 21:29:22 +08:00
parent cbb139e956
commit bf4d4a508d
7 changed files with 208 additions and 90 deletions
+2
View File
@@ -11,3 +11,5 @@ oxide_parser = { path = "../oxide_parser" }
oxide_bytecode = { path = "../oxide_bytecode" }
oxide_ir = { path = "../oxide_ir" }
regex.workspace = true
regress.workspace = true
+5 -6
View File
@@ -36,6 +36,7 @@ impl Emitter {
fn emit_string_literal_expression(
&self, s: &oxide_parser::StringLiteral, ctx: &mut CompileCtx,
) -> Result<u32, String> {
eprintln!("[DBG] string literal value={:?}", s.value.as_str());
let idx = ctx.add_constant(Constant::String(s.value.to_string()));
let r = ctx.alloc_reg();
ctx.inst(Inst::load_const(Operand::Reg(r), idx));
@@ -68,12 +69,8 @@ impl Emitter {
let pattern = raw_str[1..last_slash].to_string();
let flags = raw_str[last_slash + 1..].to_string();
// 非法正则字面量须在编译期报 SyntaxError(负面测试期望编译失败)。
if regex::RegexBuilder::new(&pattern)
.case_insensitive(flags.contains('i'))
.multi_line(flags.contains('m'))
.build()
.is_err()
{
// 用 regress(ECMAScript 语法)校验,避免误报 backreference/lookaround 等合法模式。
if regress::Regex::with_flags(&pattern, flags.as_str()).is_err() {
return Err(format!(
"SyntaxError: Invalid regular expression: /{pattern}/{flags}"
));
@@ -100,3 +97,5 @@ impl Emitter {
}
}
}