regex string-pattern API + test-harness host-call-fn mock
Ported from loops/sx-vm-extensions 4ab9db05 + 8ec36b31. - sx_primitives.ml (shared serving binary): regex-replace/split/match/etc. accept a raw pattern string (auto-compiled) as well as a compiled regex dict. Fixes (regex-replace "[0-9]" "_" s) / (regex-split "[ \t]+" s) which required a dict. - run_tests.ml (test harness only): bind host-call-fn (= apply) + host-call-fn-raising / host-new-function / host-iter? / host-to-list in the mock DOM block. Recovers 712 hyperscript behavioral tests that died on "Undefined symbol: host-call-fn" (run_tests --jit 1073 → 361 failures). No serving impact (test binary only). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2306,7 +2306,13 @@ let () =
|
||||
| Some r -> r
|
||||
| None -> raise (Eval_error "regex: handle not found"))
|
||||
| _ -> raise (Eval_error "regex: missing id"))
|
||||
| _ -> raise (Eval_error "regex: expected regex dict")
|
||||
| String s ->
|
||||
(* Accept a raw pattern string: auto-compile it. Lets regex-split /
|
||||
regex-match-all / regex-test / etc. take a pattern directly, not only
|
||||
a pre-compiled regex dict from regex-compile. *)
|
||||
(try (Re.compile (Re.Pcre.re s), s, "")
|
||||
with _ -> raise (Eval_error ("regex: invalid pattern " ^ s)))
|
||||
| _ -> raise (Eval_error "regex: expected regex dict or pattern string")
|
||||
in
|
||||
let group_to_dict g input =
|
||||
let d = Hashtbl.create 4 in
|
||||
@@ -2368,6 +2374,14 @@ let () =
|
||||
| _ -> raise (Eval_error "regex-match-all: (regex string)"));
|
||||
register "regex-replace" (fun args ->
|
||||
match args with
|
||||
| [String pattern; String replacement; String input] ->
|
||||
(* string API: (regex-replace pattern replacement input) — replace ALL
|
||||
matches of a raw pattern. Disambiguated from the compiled-regex API
|
||||
below by the first arg being a String rather than a regex Dict. *)
|
||||
(try
|
||||
let re = Re.Pcre.re pattern |> Re.compile in
|
||||
String (Re.replace_string re ~by:replacement input)
|
||||
with _ -> String input)
|
||||
| [rx; String s; String replacement] ->
|
||||
let (re, _, flags) = regex_of_value rx in
|
||||
let expand g =
|
||||
|
||||
Reference in New Issue
Block a user