ref: 1259d97bb9e8389611742f55d6c8308734202ae1
parent: 3dde0d66b484358b413dde842959e8a832a6a991
author: Ori Bernstein <[email protected]>
date: Wed Apr 29 18:59:13 EDT 2015
Add converson of error status into failure messages.
--- a/libregex/compile.myr
+++ b/libregex/compile.myr
@@ -8,6 +8,7 @@
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 @@
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 @@
;;
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"
+
+ ;;
+}
+