-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathalways.lua
54 lines (50 loc) · 1.11 KB
/
always.lua
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
local parser = require("overseer.parser")
local util = require("overseer.parser.util")
local Always = {
desc = "A decorator that always returns SUCCESS",
doc_args = {
{
name = "succeed",
type = "boolean",
desc = "Set to false to always return FAILURE",
default = true,
position_optional = true,
},
{
name = "child",
type = "parser",
desc = "The child parser node",
},
},
examples = {
{
desc = [[An extract node that returns SUCCESS even when it fails]],
code = [[
{"always",
{"extract", "^([^%s].+):(%d+): (.+)$", "filename", "lnum", "text" }
}
]],
},
},
}
function Always.new(succeed, child)
if child == nil then
child = succeed
succeed = true
end
return setmetatable({
child = util.hydrate(child),
succeed = succeed,
}, { __index = Always })
end
function Always:reset()
self.child:reset()
end
function Always:ingest(...)
local st = self.child:ingest(...)
if st == parser.STATUS.RUNNING then
return st
end
return self.succeed and parser.STATUS.SUCCESS or parser.STATUS.FAILURE
end
return Always