Commits

Peter Szilagyi  committed d9f7dfe

omake-server: Tried to tighten up remove_progress_bar for performance.
Also fixed an incorrect backreference and added illustrative tests.

  • Participants
  • Parent commits d7a5d1b

Comments (0)

Files changed (2)

File ocaml/omake/lib/omake.ml

     ; "cp .*\\.a.*"
     ]
 
-  (* Remove status bar from the end of lines *)
+  (* Remove status bar from the beginnings and ends of lines *)
   let remove_progress_bar =
-    let status_regex = Regex.of_string "([^\\[].*)\\[=+\\].*" in
-    fun l -> Regex.rewrite status_regex l ~template:"\\1"
+    let _status_regex = Regex.of_string "([^\\[].*)\\[=+\\].*" in
+    (* Milan's lines start out with a line of all blank spaces followed by
+       ^M. *)
+    let one = "\\[=+ *\\] [0-9]+ / [0-9]+| +" in
+    let status_regex = Regex.of_string (sprintf "(((%s)\r)*)(.*)(%s)?" one one) in
+    fun l -> Regex.rewrite status_regex l ~template:"$4"
+  TEST =
+    remove_progress_bar
+      "[============================================================  ] 04840 / 04841\r                                                                               \r[============================================================  ] 04841 / 04842\r[=======================================                       ] 05010 / 07826\r[========================                                      ] 05053 / 13052\r[=============================                                 ] 06807 / 14348\r[===============================                               ] 08203 / 16405\r[=================================                             ] 09418 / 17458\r[=================================                             ] 09566 / 17458\r[==================================                            ] 09631 / 17458\r[=================================                             ] 10200 / 18846\r[===========================                                   ] 10221 / 23043\r[=============================                                 ] 11016 / 23098\rmake[1]: Leaving directory `/mnt/local/sda1/mstanojevic/repos/live/submissions'"
+    = "make[1]: Leaving directory `/mnt/local/sda1/mstanojevic/repos/live/submissions'"
 
   let spaces_before_text s =
     let n = String.length s in

File ocaml/omake/lib/regex.ml

     rewrite rex ~template:"def" "abc" = "def" (*  *)
   ;;
 
+  let rex = of_string "abc(.*)def"
+  TEST = has_match rex "123abc456def789"
+  TEST = not (has_match rex "defabc")
+  TEST = rewrite rex ~template:"$1" "123abc456def789" = "123456789"
+  TEST =
+    rewrite rex ~template:"\\1" "123abc456def789"
+    = "123\\1789"                       (* literal \1 *)
+  TEST = try ignore (rewrite rex ~template:"$2" "abcdef"); false with _ -> true
+  TEST = "\r" = "
+
 end