a helper to add patterns without increasing indent
This commit is contained in:
parent
11171f80d9
commit
9c102c6f74
|
@ -4,20 +4,21 @@ load_results = function(filename)
|
||||||
local f, err = App.open_for_reading(filename)
|
local f, err = App.open_for_reading(filename)
|
||||||
if err then error(err) end
|
if err then error(err) end
|
||||||
for line in f:lines() do
|
for line in f:lines() do
|
||||||
local subject, object = line:match('^%s*(%S+)%s+beat%s+(%S+)%s*$')
|
local _ = -- turn rest of loop (a single giant expr) into a statement to satisfy the Lua parser
|
||||||
table.insert(Global_state.results, {subject, object})
|
do_if_match(line, '^%s*(%S+)%s+beat%s+(%S+)%s*$', function(subject, object)
|
||||||
if subject == nil then
|
table.insert(Global_state.results, {subject, object})
|
||||||
|
if results[subject] == nil then
|
||||||
|
results[subject] = {}
|
||||||
|
end
|
||||||
|
results[subject][object] = 2
|
||||||
|
if results[object] == nil then
|
||||||
|
results[object] = {}
|
||||||
|
end
|
||||||
|
results[object][subject] = 0
|
||||||
|
end)
|
||||||
|
or
|
||||||
error('incorrect format: '..line)
|
error('incorrect format: '..line)
|
||||||
end
|
|
||||||
if results[subject] == nil then
|
|
||||||
results[subject] = {}
|
|
||||||
end
|
|
||||||
results[subject][object] = 2
|
|
||||||
if results[object] == nil then
|
|
||||||
results[object] = {}
|
|
||||||
end
|
|
||||||
results[object][subject] = 0
|
|
||||||
end
|
end
|
||||||
f:close()
|
f:close()
|
||||||
return results
|
return results
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
do_if_match = function(line, pat, f)
|
||||||
|
local captures = {line:match(pat)}
|
||||||
|
if #captures == 0 then return end
|
||||||
|
f(unpack(captures))
|
||||||
|
return true
|
||||||
|
end
|
Loading…
Reference in New Issue