summaryrefslogtreecommitdiff
path: root/lib/regex/redump.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/regex/redump.myr')
-rw-r--r--lib/regex/redump.myr32
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/regex/redump.myr b/lib/regex/redump.myr
index ddc9b33..3f843ea 100644
--- a/lib/regex/redump.myr
+++ b/lib/regex/redump.myr
@@ -76,10 +76,13 @@ const show = {re, ln, mg
for var i = 1; i < rl.len; i++
std.put("\tgroup {}: {}\n", i, rl[i])
;;
+ std.put("coverage:\n")
+ std.put("\t{}\n", re.pat)
+ showcoverage(re)
| `std.None:
- std.put("Match failed:\n")
+ std.put("Match failed at {}:\n", re.lastip)
std.put("\t{}\n", re.pat)
- caret(re, re.pcidx[re.lastip] - 1)
+ caret(re, re.pcidx[re.lastip])
std.put("\t{}\n", ln)
caret(re, re.strp - 1)
;;
@@ -93,3 +96,28 @@ const caret = {re, idx
std.put("^\n")
}
+const showcoverage = {re
+ var hit
+ var idx
+
+ hit = std.slzalloc(re.pat.len)
+ for var ip = 0; ip < re.proglen; ip++
+ if !std.bshas(re.traces[re.lastthr], ip)
+ continue
+ ;;
+ idx = re.pcidx[ip]
+ if idx >= 0 && idx < hit.len
+ hit[idx] = true
+ ;;
+ ;;
+
+ std.put("\t")
+ for h in hit
+ if h
+ std.put("^")
+ else
+ std.put(" ")
+ ;;
+ ;;
+ std.put("\n")
+}