ref: acd48d382119e8d1dbf58b827c809b61bf5d0ecd
parent: 25bfea9b4ab857720f4d184fb2f7e1c42c3fdae5
author: Ori Bernstein <[email protected]>
date: Sun Oct 27 09:35:28 EDT 2013
Start of support for character ranges.
--- a/compile.myr
+++ b/compile.myr
@@ -421,16 +421,34 @@
}
const chrclass = {re
+ var r
var t
matchc(re, '[')
+ t = rangematch(re)
+ while peekc(re) != ']'
+ r = rangematch(re)
+ t = mk(`Alt (t, r))
+ ;;
if !matchc(re, ']')
- -> `Fail (`Earlystop)
+ free(t)
+ -> `Fail (`Earlystop)
+ else
+ -> `Some t
;;
+}
- t = std.alloc()
- t# = `Class (0, 1)
- -> `Some t
+const rangematch = {re
+ var lo
+ var hi
+
+ lo = getc(re)
+ if matchc(re, '-')
+ hi = getc(re)
+ -> mk(`Class (lo, hi))
+ else
+ -> mk(`Chr lo)
+ ;;
}
const matchc = {re, c
--- a/main.myr
+++ b/main.myr
@@ -3,9 +3,9 @@
const main = {
var found
- match regex.compile("(.)bc")
+ match regex.compile("[a-z0-9]*bc")
`std.Success re:
- found = regex.exec(re, "世bc")
+ found = regex.exec(re, "a123bc")
std.put("Found = %t: len = %z\n", found, re.strp)
-> 0
;;