summaryrefslogtreecommitdiff
path: root/libregex
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-06-14 21:34:31 -0700
committerOri Bernstein <ori@eigenstate.org>2015-06-15 01:19:24 -0700
commitfd3494af3e5209e7e74662bc4066b28f58ff49cc (patch)
tree11493ba04cd8c5145bb4f948bd6a51695f4d3d82 /libregex
parenta32760e295c8d919349e4ee39661b66195a938c8 (diff)
downloadmc-fd3494af3e5209e7e74662bc4066b28f58ff49cc.tar.gz
Make redump useful for anyone
It dumps where a regex failed, useful for testing how regexes behave.
Diffstat (limited to 'libregex')
-rw-r--r--libregex/redump.myr37
1 files changed, 27 insertions, 10 deletions
diff --git a/libregex/redump.myr b/libregex/redump.myr
index 47df80d..1152831 100644
--- a/libregex/redump.myr
+++ b/libregex/redump.myr
@@ -3,15 +3,31 @@ use bio
use regex
const main = {args
- var cmd, opts
+ var cmd, comp
+ var verbose
var fd
- opts = [
+ verbose = false
+ cmd = std.optparse(args, &[
.argdesc = "regex [inputs...]",
- .minargs = 1
- ]
- cmd = std.optparse(args, &opts)
- match regex.dbgcompile(cmd.args[0])
+ .minargs = 1,
+ .maxargs = 1,
+ .opts = [
+ [.opt='v', .desc="dump verbose regex output"]
+ ][:],
+ ])
+ for opt in cmd.opts
+ match opt
+ | ('v', _): verbose = true
+ | _: std.fatal("Unknown argument")
+ ;;
+ ;;
+ if verbose
+ comp = regex.dbgcompile(cmd.args[0])
+ else
+ comp = regex.compile(cmd.args[0])
+ ;;
+ match comp
| `std.Fail m:
std.fatal("unable to compile regex: {}\n", regex.failmsg(m))
| `std.Ok re:
@@ -57,13 +73,14 @@ const show = {re, ln, mg
| `std.Some rl:
std.put("Matched: {}\n", rl[0])
for i = 1; i < rl.len; i++
- std.put("group {}: {}\n", i, rl[i])
+ std.put("\tgroup {}: {}\n", i, rl[i])
;;
| `std.None:
- std.put("Match failed\n")
- std.put("{}\n", ln)
+ std.put("Match failed:\n")
+ std.put("\t{}\n", ln)
+ std.put("\t")
for i = 0; i < re.strp - 1; i++
- std.put(" ")
+ std.put("~")
;;
std.put("^\n")
;;