瀏覽代碼

[eval] print regex strings nicely when debugging

closes #7858
Simon Krajewski 6 年之前
父節點
當前提交
f78dd86365
共有 3 個文件被更改,包括 6 次插入3 次删除
  1. 1 0
      src/macro/eval/evalPrinting.ml
  2. 4 3
      src/macro/eval/evalStdLib.ml
  3. 1 0
      src/macro/eval/evalValue.ml

+ 1 - 0
src/macro/eval/evalPrinting.ml

@@ -125,6 +125,7 @@ and s_value depth v =
 	| VVector vv -> s_vector (depth + 1) vv
 	| VInstance {ikind=IDate d} -> s_date d
 	| VInstance {ikind=IPos p} -> create_ascii ("#pos(" ^ Lexer.get_error_pos (Printf.sprintf "%s:%d:") p ^ ")") (* STODO: not ascii? *)
+	| VInstance {ikind=IRegex r} -> r.r_rex_string
 	| VInstance i -> (try call_to_string () with Not_found -> s_hash i.iproto.ppath)
 	| VObject o -> (try call_to_string () with Not_found -> s_object (depth + 1) o)
 	| VLazy f -> s_value depth (!f())

+ 4 - 3
src/macro/eval/evalStdLib.ml

@@ -755,9 +755,10 @@ module StdEReg = struct
 			| c -> failwith ("Unsupported regexp option '" ^ String.make 1 c ^ "'")
 		) (ExtString.String.explode opt) in
 		let flags = `UTF8 :: `UCP :: flags in
-		let r = try regexp ~flags r with Error error -> failwith (string_of_pcre_error error) in
+		let rex = try regexp ~flags r with Error error -> failwith (string_of_pcre_error error) in
 		let pcre = {
-			r = r;
+			r = rex;
+			r_rex_string = create_ascii (Printf.sprintf "~/%s/%s" r opt);
 			r_global = !global;
 			r_string = "";
 			r_groups = [||]
@@ -3019,7 +3020,7 @@ let init_empty_constructors builtins =
 	Hashtbl.add h key_Array (fun () -> encode_array_instance (EvalArray.create [||]));
 	Hashtbl.add h key_eval_Vector (fun () -> encode_vector_instance (Array.make 0 vnull));
 	Hashtbl.add h key_Date (fun () -> encode_instance key_Date ~kind:(IDate 0.));
-	Hashtbl.add h key_EReg (fun () -> encode_instance key_EReg ~kind:(IRegex {r = Pcre.regexp ""; r_global = false; r_string = ""; r_groups = [||]}));
+	Hashtbl.add h key_EReg (fun () -> encode_instance key_EReg ~kind:(IRegex {r = Pcre.regexp ""; r_rex_string = create_ascii "~//"; r_global = false; r_string = ""; r_groups = [||]}));
 	Hashtbl.add h key_String (fun () -> encode_string "");
 	Hashtbl.add h key_haxe_Utf8 (fun () -> encode_instance key_haxe_Utf8 ~kind:(IUtf8 (UTF8.Buf.create 0)));
 	Hashtbl.add h key_haxe_ds_StringMap (fun () -> encode_instance key_haxe_ds_StringMap ~kind:(IStringMap (StringHashtbl.create ())));

+ 1 - 0
src/macro/eval/evalValue.ml

@@ -79,6 +79,7 @@ end
 
 type vregex = {
 	r : Pcre.regexp;
+	r_rex_string : vstring;
 	r_global : bool;
 	mutable r_string : string;
 	mutable r_groups : Pcre.substrings array;