blob: 5fe7eb3b450c973bdcb46951d692bea9b7304dc6 (
plain)
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
|
return function(utf8)
local matchers = {
any = function()
return [[
add(function(ctx) -- any
ctx.result.finish = ctx.pos - 1
ctx:done()
end)
]]
end,
toend = function(ctx)
return [[
add(function(ctx) -- toend
ctx.result.finish = ctx.pos - 1
ctx.modified = true
if ctx.pos == utf8len(ctx.str) + 1 then ctx:done() end
end)
]]
end,
}
local len = utf8.raw.len
local function default()
return matchers.any()
end
local function parse(regex, c, bs, ctx)
local functions
local skip = 0
if bs == len(regex) and c == '$' then
functions = matchers.toend()
skip = 1
end
return functions, skip
end
return {
parse = parse,
default = default,
}
end
|