mirror of
https://github.com/bartbes/inifile.git
synced 2024-11-15 23:54:23 +00:00
Make parse return a list of parse errors
Which basically just means unmatched lines. There are no descriptive errors, at least for now, but at least this gives you the option to display warnings or errors.
This commit is contained in:
parent
7051f35bfb
commit
149af030cd
13
inifile.lua
13
inifile.lua
@ -59,8 +59,12 @@ function inifile.parse(name, backend)
|
|||||||
local comments = {}
|
local comments = {}
|
||||||
local sectionorder = {}
|
local sectionorder = {}
|
||||||
local cursectionorder
|
local cursectionorder
|
||||||
|
local lineNumber = 0
|
||||||
|
local errors = {}
|
||||||
|
|
||||||
for line in backends[backend].lines(name) do
|
for line in backends[backend].lines(name) do
|
||||||
|
lineNumber = lineNumber + 1
|
||||||
|
local validLine = false
|
||||||
|
|
||||||
-- Section headers
|
-- Section headers
|
||||||
local s = line:match("^%[([^%]]+)%]$")
|
local s = line:match("^%[([^%]]+)%]$")
|
||||||
@ -69,6 +73,7 @@ function inifile.parse(name, backend)
|
|||||||
t[section] = t[section] or {}
|
t[section] = t[section] or {}
|
||||||
cursectionorder = {name = section}
|
cursectionorder = {name = section}
|
||||||
table.insert(sectionorder, cursectionorder)
|
table.insert(sectionorder, cursectionorder)
|
||||||
|
validLine = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Comments
|
-- Comments
|
||||||
@ -77,6 +82,7 @@ function inifile.parse(name, backend)
|
|||||||
local commentsection = section or comments
|
local commentsection = section or comments
|
||||||
comments[commentsection] = comments[commentsection] or {}
|
comments[commentsection] = comments[commentsection] or {}
|
||||||
table.insert(comments[commentsection], s)
|
table.insert(comments[commentsection], s)
|
||||||
|
validLine = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Key-value pairs
|
-- Key-value pairs
|
||||||
@ -87,6 +93,11 @@ function inifile.parse(name, backend)
|
|||||||
if key and value ~= nil then
|
if key and value ~= nil then
|
||||||
t[section][key] = value
|
t[section][key] = value
|
||||||
table.insert(cursectionorder, key)
|
table.insert(cursectionorder, key)
|
||||||
|
validLine = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if not validLine then
|
||||||
|
table.insert(errors, ("Line %d: Invalid data found '%s'"):format(lineNumber, line))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -96,7 +107,7 @@ function inifile.parse(name, backend)
|
|||||||
comments = comments,
|
comments = comments,
|
||||||
sectionorder = sectionorder,
|
sectionorder = sectionorder,
|
||||||
}
|
}
|
||||||
})
|
}), errors
|
||||||
end
|
end
|
||||||
|
|
||||||
function inifile.save(name, t, backend)
|
function inifile.save(name, t, backend)
|
||||||
|
Loading…
Reference in New Issue
Block a user