forked from purescript/purescript-strings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegex.lua
More file actions
92 lines (80 loc) · 1.62 KB
/
Regex.lua
File metadata and controls
92 lines (80 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-- module Data.String.Regex
local Regex = {}
error("Not implemented: Data.String.Regex")
--[[
Regex["showRegex'"] = function (r)
return "" + r
end
Regex["regex'"] = function (s1)
return function (s2)
return new RegExp(s1, s2)
end
end
Regex.source = function (r)
return r.source
end
Regex.flags = function (r)
return {
multiline: r.multiline,
ignoreCase: r.ignoreCase,
global: r.global,
sticky: !!r.sticky,
unicode: !!r.unicode
end
end
Regex.test = function (r)
return function (s)
return r.test(s)
end
end
Regex._match = function (just)
return function (nothing)
return function (r)
return function (s)
var m = s.match(r)
if (m == null) {
return nothing
} else {
var list = []
for (var i = 0; i < m.length; i++) {
list.push(m[i] == null ? nothing : just(m[i]))
}
return just(list)
}
end
end
end
end
Regex.replace = function (r)
return function (s1)
return function (s2)
return s2.replace(r, s1)
end
end
end
Regex["replace'"] = function (r)
return function (f)
return function (s2)
return s2.replace(r, function (match)
return f(match)(Array.prototype.splice.call(arguments, 1, arguments.length - 3))
})
end
end
end
Regex._search = function (just)
return function (nothing)
return function (r)
return function (s)
var result = s.search(r)
return result === -1 ? nothing : just(result)
end
end
end
end
Regex.split = function (r)
return function (s)
return s.split(r)
end
end
return Regex
]]