summaryrefslogtreecommitdiff
path: root/lib/regex
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2018-03-28 11:09:54 -0700
committerOri Bernstein <ori@markovcorp.com>2018-03-28 11:09:54 -0700
commit654eb21dce9327393d64b13d3eb3cbc8db35fe3b (patch)
tree4b3c2b1f6092b349d9142afcbb4cefcd42c5f9c3 /lib/regex
parentc19f9bc26e3e55fff0ba2bec80c40f43509bf779 (diff)
downloadmc-654eb21dce9327393d64b13d3eb3cbc8db35fe3b.tar.gz
Improve commenting.
Diffstat (limited to 'lib/regex')
-rw-r--r--lib/regex/redump.myr34
1 files changed, 32 insertions, 2 deletions
diff --git a/lib/regex/redump.myr b/lib/regex/redump.myr
index 4a4fe8f..af8e2bf 100644
--- a/lib/regex/redump.myr
+++ b/lib/regex/redump.myr
@@ -68,6 +68,21 @@ const dump = {re, fd
;;
}
+/*
+ * Renders a match in a way that's pleasant to read. There are
+ * two cases here.
+ *
+ * 1) The pattern matched. In this case, we want to show the
+ * regions of the pattern that contributed to the match.
+ *
+ * 2) The pattern did not match. In this case, we want to show
+ * the location of the failed match.
+ *
+ * In both cases, we render a caret that describes the position
+ * of the match. Unfortunately, for the coverage code we don't
+ * have a great way of mapping whole subranges, so the caret can
+ * be slightly truncated. Fixing this isn't worth hte complexity.
+ */
const show = {re, ln, mg
match mg
| `std.Some rl:
@@ -83,11 +98,19 @@ const show = {re, ln, mg
std.put("\t{}\n", re.pat)
caret(re, re.pcidx[re.lastip])
std.put("\t{}\n", ln)
- caret(re, re.strp - 1)
+ showpos(re, re.strp - 1)
;;
}
-const caret = {re, idx
+/*
+ * Simple position carets for failures: Draws out
+ * an arrow of the form:
+ *
+ * ~~~~~^
+ *
+ * from the start of the line.
+ */
+const showpos = {re, idx
std.put("\t")
for var i = 0; i < idx; i++
std.put("~")
@@ -95,6 +118,13 @@ const caret = {re, idx
std.put("^\n")
}
+/*
+ * Coverage carets for success. This tries to output
+ * a '^' for every section of the string that matched.
+ *
+ * (this|that)
+ * ^^^^
+ */
const showcoverage = {re
var hit
var idx