-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.lua
52 lines (39 loc) · 992 Bytes
/
parser.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
parser = {}
parser.seperator = ","
function parser.getKey(line)
return line.split(" = ")[0]
end
function parser.getValue(line)
return line.split(" = ")[1]
end
function parser.getType(line)
if string.match(line, ",") then return "a" end
if not string.match(line, ",") then return "s" end
end
function parser.stringToArray(data)
local array = {}
for item in string.gmatch(data, "[^" .. parser.seperator .. "]+") do
table.insert(array, item)
end
return array
end
function parser.readLines(file)
local file = io.open(file, "r")
local lines = file:lines()
file:close()
return lines
end
function parser.Parse(faction_file)
local lines = parser.readLines(faction_file)
local DATA = {}
for line in pairs(lines) do
local key = parser.getKey(line)
local value = parser.getValue(line)
if parser.getType(value) == "s" then
DATA[key] = value
elseif parser.getType(value) == "a" then
local array = parser.stringToArray(value)
DATA[key] = array
end
end
end