ref: fd3494af3e5209e7e74662bc4066b28f58ff49cc
parent: a32760e295c8d919349e4ee39661b66195a938c8
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jun 14 17:34:31 EDT 2015
Make redump useful for anyone It dumps where a regex failed, useful for testing how regexes behave.
--- a/libregex/redump.myr
+++ b/libregex/redump.myr
@@ -3,15 +3,31 @@
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 @@
| `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")
;;