diff options
author | Ori Bernstein <ori@eigenstate.org> | 2016-05-23 11:21:55 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2016-05-23 11:21:55 -0700 |
commit | 31247e29fb596b44fdd5c18140bc945b6a4b71ce (patch) | |
tree | c20fc7934cedd42b0682e305bc227629fb048d6f /lib/regex | |
parent | fdafa085a245d4f48f84c6875a6b7cb89b8b5c6c (diff) | |
download | mc-31247e29fb596b44fdd5c18140bc945b6a4b71ce.tar.gz |
Refactor thread matching.
Diffstat (limited to 'lib/regex')
-rw-r--r-- | lib/regex/interp.myr | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/lib/regex/interp.myr b/lib/regex/interp.myr index a203520..c52ed25 100644 --- a/lib/regex/interp.myr +++ b/lib/regex/interp.myr @@ -18,35 +18,28 @@ const exec = {re, str re.str = str re.strp = 0 thr = run(re, true) - if thr != Zthr - m = getmatches(re, thr) - thrfree(re, thr) - cleanup(re) - -> `std.Some m - else - cleanup(re) - -> `std.None - ;; + m = getmatches(re, thr) + cleanup(re) + -> m } const search = {re, str var thr var m + m = `std.None for var i = 0; i < str.len; i++ re.str = str[i:] re.strp = 0 thr = run(re, false) - if thr != Zthr - m = getmatches(re, thr) - thrfree(re, thr) - cleanup(re) - -> `std.Some m - else - cleanup(re) + m = getmatches(re, thr) + match m + | `std.Some _: break + | `std.None: /* nothing */ ;; + cleanup(re) ;; - -> `std.None + -> m } const cleanup = {re @@ -70,6 +63,9 @@ const matchfree = {m const getmatches = {re, thr var ret + if thr == Zthr + -> `std.None + ;; ret = std.slalloc(re.nmatch) for var i = 0; i < re.nmatch; i++ if thr.mstart[i] != -1 && thr.mend[i] != -1 @@ -78,7 +74,8 @@ const getmatches = {re, thr ret[i] = [][:] ;; ;; - -> ret + thrfree(re, thr) + -> `std.Some ret } |