Commit 3b79a942

3b79a9421070Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

case/when with a regex condition

A when /re/ clause against a string subject now matches via sp_re_match_p instead of strcmp'ing against the regex's fallthrough value. Reuses the regex-literal table.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
3b79a9421070
Parent
0f74f04c3fac

src/codegen.cmodifiedView file

@@ -3585,7 +3585,11 @@
35853585 for (int j = 0; j < wc; j++) {
35863586 if (j) buf_puts(b, " || ");
35873587 if (pred >= 0) {
3588- if (pt == TY_STRING) {
3588+ int reidx = re_lit_index(c, conds[j]);
3589+ if (reidx >= 0 && pt == TY_STRING) {
3590+ buf_printf(b, "sp_re_match_p(sp_re_pat_%d, _t%d)", reidx, t);
3591+ }
3592+ else if (pt == TY_STRING) {
35893593 buf_printf(b, "sp_str_eq(_t%d, ", t); emit_expr(c, conds[j], b); buf_puts(b, ")");
35903594 }
35913595 else {