summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libregex/compile.myr72
-rw-r--r--libregex/interp.myr39
-rw-r--r--libregex/redump.myr19
-rw-r--r--libstd/dial+posixy.myr1
-rw-r--r--libstd/fmt2.myr15
-rw-r--r--libstd/optparse.myr20
6 files changed, 98 insertions, 68 deletions
diff --git a/libregex/compile.myr b/libregex/compile.myr
index 4081e9f..6199dc2 100644
--- a/libregex/compile.myr
+++ b/libregex/compile.myr
@@ -168,21 +168,21 @@ const rtdump = {rt, ind
var l, h
indent(ind)
- std.put("Range (end = %t) {\n", rt.end)
+ std.f2put("Range (end = {}) {\n", rt.end)
for i = 0; i < rt.ranges.len; i++
indent(ind + 1)
(l, h) = rt.ranges[i]
- std.put("0x%xb-0x%xb: \n", l, h)
+ std.f2put("0x{x}-0x{x}: \n", l, h)
rtdump(rt.link[i], ind + 1)
;;
indent(ind)
- std.put("}\n")
+ std.f2put("}\n")
}
const indent = {ind
var i
for i = 0; i < ind; i++
- std.put("\t")
+ std.f2put("\t")
;;
}
@@ -373,28 +373,28 @@ const idump = {re
->
;;
for i = 0; i < re.proglen; i++
- std.put("%i:\t", i)
+ std.f2put("{}:\t", i)
match re.prog[i]
/* Char matching. Consume exactly one byte from the string. */
- | `Ibyte b: std.put("`Ibyte %ub (%c)\n", b, b castto(char))
+ | `Ibyte b: std.f2put("`Ibyte {} ({})\n", b, b castto(char))
| `Irange (start, end):
- std.put("`Irange (%ub,%ub)", start, end)
+ std.f2put("`Irange ({},{})", start, end)
if std.isalnum(start castto(char)) && std.isalnum(end castto(char))
- std.put("\t/* %c-%c */", start castto(char), end castto(char))
+ std.f2put("\t/* {}-{} */", start castto(char), end castto(char))
;;
- std.put("\n")
+ std.f2put("\n")
/* capture groups */
- | `Ilbra m: std.put("`Ilbra %z\n", m)
- | `Irbra m: std.put("`Irbra %z\n", m)
+ | `Ilbra m: std.f2put("`Ilbra {}\n", m)
+ | `Irbra m: std.f2put("`Irbra {}\n", m)
/* anchors */
- | `Ibol: std.put("`Ibol\n")
- | `Ieol: std.put("`Ieol\n")
- | `Ibow: std.put("`Ibow\n")
- | `Ieow: std.put("`Ieow\n")
+ | `Ibol: std.f2put("`Ibol\n")
+ | `Ieol: std.f2put("`Ieol\n")
+ | `Ibow: std.f2put("`Ibow\n")
+ | `Ieow: std.f2put("`Ieow\n")
/* control flow */
- | `Ifork (lip, rip): std.put("`Ifork (%z,%z)\n", lip, rip)
- | `Ijmp ip: std.put("`Ijmp %z\n", ip)
- | `Imatch id: std.put("`Imatch %z\n", id)
+ | `Ifork (lip, rip): std.f2put("`Ifork ({},{})\n", lip, rip)
+ | `Ijmp ip: std.f2put("`Ijmp {}\n", ip)
+ | `Imatch id: std.f2put("`Imatch {}\n", id)
;;
;;
}
@@ -407,58 +407,58 @@ const dump = {re, t, indent
->
;;
for i = 0; i < indent; i++
- std.put(" ")
+ std.f2put(" ")
;;
match t#
| `Alt (a, b):
- std.put("Alt\n")
+ std.f2put("Alt\n")
dump(re, a, indent + 1)
dump(re, b, indent + 1)
| `Cat (a, b):
- std.put("Cat\n")
+ std.f2put("Cat\n")
dump(re, a, indent + 1)
dump(re, b, indent + 1)
/* repetition */
| `Star a:
- std.put("Star\n")
+ std.f2put("Star\n")
dump(re, a, indent + 1)
| `Rstar a:
- std.put("Rstar\n")
+ std.f2put("Rstar\n")
dump(re, a, indent + 1)
| `Plus a:
- std.put("Plus\n")
+ std.f2put("Plus\n")
dump(re, a, indent + 1)
| `Rplus a:
- std.put("Rplus\n")
+ std.f2put("Rplus\n")
dump(re, a, indent + 1)
| `Quest a:
- std.put("Quest\n")
+ std.f2put("Quest\n")
dump(re, a, indent + 1)
| `Bol:
- std.put("Bol\n")
+ std.f2put("Bol\n")
| `Eol:
- std.put("Eol\n")
+ std.f2put("Eol\n")
| `Bow:
- std.put("Bow\n")
+ std.f2put("Bow\n")
| `Eow:
- std.put("Eow\n")
+ std.f2put("Eow\n")
/* end matches */
| `Byte b:
- std.put("Byte %b\n", b)
+ std.f2put("Byte {}\n", b)
| `Chr c:
- std.put("Char %c\n", c)
+ std.f2put("Char {}\n", c)
| `Ranges rl:
- std.put("Ranges")
+ std.f2put("Ranges")
for r in rl
for i = 0; i < indent + 1; i++
- std.put(" ")
+ std.f2put(" ")
;;
- std.put("\t(%ui-%ui)\n", r[0], r[1])
+ std.f2put("\t({}-{})\n", r[0], r[1])
;;
/* meta */
| `Cap (m, a):
- std.put("Cap %i\n", m)
+ std.f2put("Cap {}\n", m)
dump(re, a, indent + 1)
;;
}
diff --git a/libregex/interp.myr b/libregex/interp.myr
index 36fae53..efd7cf8 100644
--- a/libregex/interp.myr
+++ b/libregex/interp.myr
@@ -81,7 +81,7 @@ const run = {re
thr = re.runq
re.runq = thr.next
- trace(re, thr, "\nrunning tid=%z, ip=%z, s[%z]=%c\n", thr.tid, thr.ip, re.strp, std.decode(re.str[re.strp:]))
+ trace(re, thr, "\nrunning tid={}, ip={}, s[{}]={}\n", thr.tid, thr.ip, re.strp, std.decode(re.str[re.strp:]))
ip = thr.ip
consumed = step(re, thr, -1)
while !consumed
@@ -132,17 +132,17 @@ const step = {re, thr, curip
match re.prog[thr.ip]
/* Char matching. Consume exactly one byte from the string. */
| `Ibyte b:
- trace(re, thr, "\t%z:\tByte %ub (%c)\n", thr.ip, b, b castto(char))
+ trace(re, thr, "\t{}:\tByte {} ({})\n", thr.ip, b, b castto(char))
if !within(re, str)
die(re, thr, "end of string")
elif b != str[re.strp]
die(re, thr, "not right char")
else
thr.ip++
- trace(re, thr, "\t\tmatched %b with %b\n", b, str[re.strp])
+ trace(re, thr, "\t\tmatched {} with {}\n", b, str[re.strp])
;;
| `Irange (start, end):
- trace(re, thr, "\t%z:\tRange (%ub, %ub) /* %c - %c */\n", thr.ip, start, end, start castto(char), end castto(char))
+ trace(re, thr, "\t{}:\tRange ({}, {}) /* {} - {} */\n", thr.ip, start, end, start castto(char), end castto(char))
if !within(re, str) || start > str[re.strp] || end < str[re.strp]
die(re, thr, "bad range")
else
@@ -153,7 +153,7 @@ const step = {re, thr, curip
called again until exactly one byte is consumed from the string.
*/
| `Ibol:
- trace(re, thr, "\t%z:\tBol\n", thr.ip)
+ trace(re, thr, "\t{}:\tBol\n", thr.ip)
if re.strp == 0 || str[re.strp - 1] == '\n' castto(byte)
thr.ip++
-> false
@@ -161,7 +161,7 @@ const step = {re, thr, curip
die(re, thr, "not beginning of line")
;;
| `Ieol:
- trace(re, thr, "\t%z:\tEol\n", thr.ip)
+ trace(re, thr, "\t{}:\tEol\n", thr.ip)
if re.strp == str.len || str[re.strp] == '\n' castto(byte)
thr.ip++
-> false
@@ -170,7 +170,7 @@ const step = {re, thr, curip
;;
/* check for word characters */
| `Ibow:
- trace(re, thr, "\t%z:\tBow\n", thr.ip)
+ trace(re, thr, "\t{}:\tBow\n", thr.ip)
if iswordchar(str[re.strp:]) && (re.strp == 0 || !iswordchar(prevchar(str, re.strp)))
thr.ip++
-> false
@@ -178,7 +178,7 @@ const step = {re, thr, curip
die(re, thr, "not beginning of word")
;;
| `Ieow:
- trace(re, thr, "\t%z:\tEow\n", thr.ip)
+ trace(re, thr, "\t{}:\tEow\n", thr.ip)
if re.strp == str.len && iswordchar(prevchar(str, re.strp))
thr.ip++
-> false
@@ -189,29 +189,29 @@ const step = {re, thr, curip
die(re, thr, "not end of word")
;;
| `Ilbra m:
- trace(re, thr, "\t%z:\tLbra %z\n", thr.ip, m)
- trace(re, thr, "\t\tmatch start = %z\n", re.strp)
+ trace(re, thr, "\t{}:\tLbra {}\n", thr.ip, m)
+ trace(re, thr, "\t\tmatch start = {}\n", re.strp)
thr.mstart[m] = re.strp
thr.ip++
-> false
| `Irbra m:
- trace(re, thr, "\t%z:\tRbra %z\n", thr.ip, m)
+ trace(re, thr, "\t{}:\tRbra {}\n", thr.ip, m)
thr.mend[m] = re.strp
thr.ip++
-> false
| `Ifork (lip, rip):
- trace(re, thr, "\t%z:\tFork (%z, %z)\n", thr.ip, lip, rip)
+ trace(re, thr, "\t{}:\tFork ({}, {})\n", thr.ip, lip, rip)
mstart = std.sldup(thr.mstart)
mend = std.sldup(thr.mend)
fork(re, thr, rip, curip, mstart, mend)
thr.ip = lip
-> false
| `Ijmp ip:
- trace(re, thr, "\t%z:\tJmp %z\n", thr.ip, ip)
+ trace(re, thr, "\t{}:\tJmp {}\n", thr.ip, ip)
thr.ip = ip
-> false
| `Imatch id:
- trace(re, thr, "\t%z:\tMatch\n", thr.ip)
+ trace(re, thr, "\t{}:\tMatch\n", thr.ip)
finish(re, thr)
-> true
;;
@@ -239,7 +239,7 @@ const die = {re, thr, msg
thread is in. We should only decrement
the number of threads for that once.
*/
- trace(re, thr, "\t\tdie %z: %s\n", thr.tid, msg)
+ trace(re, thr, "\t\tdie {}: {}\n", thr.tid, msg)
if !thr.dead
re.nthr--
;;
@@ -247,7 +247,7 @@ const die = {re, thr, msg
}
const finish = {re, thr
- trace(re, thr, "finish %z\n", thr.tid)
+ trace(re, thr, "finish {}\n", thr.tid)
thr.matched = true
re.nthr--
}
@@ -274,7 +274,7 @@ const mkthread = {re, ip
}
const thrfree = {re, thr
- trace(re, thr, "\t\tcleanup %z\n", thr.tid)
+ trace(re, thr, "\t\tcleanup {}\n", thr.tid)
std.slfree(thr.mstart)
std.slfree(thr.mend)
std.free(thr)
@@ -285,8 +285,11 @@ const within = {re, str
}
const trace : (re : regex#, thr : rethread#, msg : byte[:], args : ... -> void) = {re, thr, msg, args
+ var ap
+
if re.debug
- std.putv(msg, std.vastart(&args))
+ ap = std.vastart(&args)
+ std.f2putv(msg, &ap)
;;
}
diff --git a/libregex/redump.myr b/libregex/redump.myr
index ea85d94..416d8a9 100644
--- a/libregex/redump.myr
+++ b/libregex/redump.myr
@@ -13,7 +13,7 @@ const main = {args
cmd = std.optparse(args, &opts)
match regex.dbgcompile(cmd.args[0])
| `std.Fail m:
- std.fatal("unable to compile regex: %s\n", regex.failmsg(m))
+ std.f2fatal("unable to compile regex: {}\n", regex.failmsg(m))
| `std.Ok re:
if cmd.args.len > 1
runall(re, cmd.args)
@@ -33,7 +33,7 @@ const runall = {re, files
dump(re, fd)
bio.close(fd)
| `std.None:
- std.fatal("failed to open %s\n", f)
+ std.f2fatal("failed to open {}\n", f)
;;
;;
}
@@ -42,7 +42,7 @@ const dump = {re, fd
while true
match bio.readln(fd)
| `std.Some ln:
- regex.exec(re, ln)
+ show(regex.exec(re, ln))
std.slfree(ln)
| `std.None:
break
@@ -50,3 +50,16 @@ const dump = {re, fd
;;
}
+const show = {mg
+ var i
+
+ match mg
+ | `std.Some rl:
+ std.f2put("Matched: {}\n", rl[0])
+ for i = 1; i < rl.len; i++
+ std.f2put("group {}: {}\n", i, rl[i])
+ ;;
+ | `std.None:
+ std.f2put("Match failed\n")
+ ;;
+}
diff --git a/libstd/dial+posixy.myr b/libstd/dial+posixy.myr
index 1554cdb..77920b6 100644
--- a/libstd/dial+posixy.myr
+++ b/libstd/dial+posixy.myr
@@ -56,7 +56,6 @@ const dial = {str
var err
err = sys.connect(sock, (&sa) castto(sys.sockaddr#), sizeof(sys.sockaddr_in))
if err < 0
- put("Errno %i\n", -err)
sys.close(sock)
-> `Fail "Failed to bind socket"
;;
diff --git a/libstd/fmt2.myr b/libstd/fmt2.myr
index 5d3511f..bc1de45 100644
--- a/libstd/fmt2.myr
+++ b/libstd/fmt2.myr
@@ -42,6 +42,21 @@ pkg std =
$noret const f2fatalv : (fmt : byte[:], ap : valist# -> void)
;;
+/* same as 'put', but exits the program after printing */
+const f2fatal = {fmt, args
+ var ap
+
+ ap = vastart(&args)
+ f2putv(fmt, &ap)
+ exit(1)
+}
+
+/* same as 'putv', but exits the program after printing */
+const f2fatalv = {fmt, ap
+ f2putv(fmt, ap)
+ exit(1)
+}
+
var fmtmapinited : bool = false
var fmtmap : htab(byte[:], (sb : strbuf#, ap : valist#, opts : byte[:] -> void))#
diff --git a/libstd/optparse.myr b/libstd/optparse.myr
index 4f454b5..888b72f 100644
--- a/libstd/optparse.myr
+++ b/libstd/optparse.myr
@@ -1,7 +1,7 @@
use "alloc.use"
use "die.use"
use "extremum.use"
-use "fmt.use"
+use "fmt2.use"
use "option.use"
use "sleq.use"
use "slpush.use"
@@ -62,7 +62,7 @@ const optparse = {args, def
parsed.opts = slpush(parsed.opts, optnext(&ctx))
;;
if ctx.args.len < def.minargs
- put("error: expected at least %z args, got %i\n", def.minargs, ctx.args.len)
+ f2put("error: expected at least {} args, got {}\n", def.minargs, ctx.args.len)
optusage(ctx.optargs[0], ctx.optdef)
exit(1)
;;
@@ -97,7 +97,7 @@ const optnext = {ctx
optusage(ctx.optargs[0], ctx.optdef)
exit(0)
else
- fatal("unexpected argument '%c'\n", c)
+ f2fatal("unexpected argument '{}'\n", c)
;;
| `Some (true, needed):
/* -arg => '-a' 'rg' */
@@ -111,7 +111,7 @@ const optnext = {ctx
ctx.argidx++
next(ctx)
elif needed
- put("Expected argument for %c\n", c)
+ f2put("Expected argument for {}\n", c)
exit(1)
;;
| `Some (false, _):
@@ -162,15 +162,15 @@ const next = {ctx
}
const optusage = {prog, def
- std.put("usage: %s [-h?] ", prog)
+ std.f2put("usage: {} [-h?] ", prog)
for o in def.opts
- std.put("[-%c%s%s] ", o.opt, sep(o.arg), o.arg)
+ std.f2put("[-{}{}{}] ", o.opt, sep(o.arg), o.arg)
;;
- std.put("%s\n", def.argdesc)
- std.put("\t-h\tprint this help message\n")
- std.put("\t-?\tprint this help message\n")
+ std.f2put("{}\n", def.argdesc)
+ std.f2put("\t-h\tprint this help message\n")
+ std.f2put("\t-?\tprint this help message\n")
for o in def.opts
- std.put("\t-%c%s%s\t%s\n", o.opt, sep(o.arg), o.arg, o.desc)
+ std.f2put("\t-{}{}{}\t{}\n", o.opt, sep(o.arg), o.arg, o.desc)
;;
}