diff options
author | Ori Bernstein <ori@eigenstate.org> | 2015-04-29 22:59:13 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2015-04-29 22:59:13 -0700 |
commit | 8d76103efae5aa0c028fc036c05b73b85878a781 (patch) | |
tree | 3bd0a87e6ad6530ac10ec2044f75490ff99b9587 | |
parent | ff18725b46d903e6dcedd0c6262aea47fe6c8869 (diff) | |
download | mc-8d76103efae5aa0c028fc036c05b73b85878a781.tar.gz |
Add converson of error status into failure messages.
-rw-r--r-- | libregex/compile.myr | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/libregex/compile.myr b/libregex/compile.myr index 898c28f..eac43d3 100644 --- a/libregex/compile.myr +++ b/libregex/compile.myr @@ -8,6 +8,7 @@ pkg regex = const compile : (re : byte[:] -> std.result(regex#, status)) const dbgcompile : (re : byte[:] -> std.result(regex#, status)) const free : (re : regex# -> void) + const failmsg : (st : status -> byte[:]) ;; type parseresult = union @@ -692,12 +693,12 @@ const chrclass = {re neg = true ;; rl = rangematch(re, [][:]) - while peekc(re) != ']' + while peekc(re) != ']' && re.pat.len > 0 rl = rangematch(re, rl) ;; if !matchc(re, ']') std.slfree(rl) - -> `Fail (`Incomplete) + -> `Fail `Unbalanced ;; std.sort(rl, {a, b; @@ -835,3 +836,17 @@ const astfree = {t ;; std.free(t) } + +const failmsg = {st + match st + | `Noimpl: -> "no implementation" + | `Incomplete: -> "regex ended before input fully parsed" + | `Unbalanced: -> "unbalanced bracket" + | `Emptyparen: -> "empty parentheses" + | `Badrep: -> "invalid repetition" + | `Badrange: -> "invalid range" + | `Badescape: -> "invalid escape code" + + ;; +} + |