mirror of
https://github.com/nmap/nmap.git
synced 2025-12-11 02:09:03 +00:00
Make Json:parseValue handle any kind of value, without taking a
parameter to control whether only top-level structures are allowed. Instead, move the special top-level code out to the Json:parseStart function.
This commit is contained in:
@@ -197,30 +197,29 @@ end
|
|||||||
function Json:errors()
|
function Json:errors()
|
||||||
return self.error ~= nil
|
return self.error ~= nil
|
||||||
end
|
end
|
||||||
-- This is where the parsing begins.
|
-- Parses a top-level JSON structure (object or array).
|
||||||
--@return the parsed object or puts error messages in self.error
|
--@return the parsed object or puts error messages in self.error
|
||||||
function Json:parseStart()
|
function Json:parseStart()
|
||||||
return self:parseValue(true)
|
-- The top level of JSON only allows an object or an array. Only inside
|
||||||
|
-- of the outermost container can other types appear.
|
||||||
|
self:eatWhiteSpace()
|
||||||
|
local c = self:peek()
|
||||||
|
if c == '{' then
|
||||||
|
return self:parseObject()
|
||||||
|
elseif c == '[' then
|
||||||
|
return self:parseArray()
|
||||||
|
else
|
||||||
|
self:syntaxerror(("JSON must start with object or array (started with %s)"):format(c))
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Parses a value
|
-- Parses a value
|
||||||
--@param first if this is the first time the input is read,
|
|
||||||
-- the value must be array or object, otherwise a syntax error will
|
|
||||||
-- be triggered
|
|
||||||
--@return the parsed value
|
--@return the parsed value
|
||||||
function Json:parseValue(first)
|
function Json:parseValue()
|
||||||
|
|
||||||
-- If first is set to true, this is the first
|
|
||||||
-- object received. Therefore, this must be
|
|
||||||
-- either an Object or Array ( first chars { or [ )
|
|
||||||
|
|
||||||
self:eatWhiteSpace()
|
self:eatWhiteSpace()
|
||||||
local c = self:peek()
|
local c = self:peek()
|
||||||
|
|
||||||
if(first and c ~= '{' and c ~= '[') then
|
|
||||||
self:syntaxerror(("Json must start with object or array (started with %s)"):format(c))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local value
|
local value
|
||||||
if c == '{' then
|
if c == '{' then
|
||||||
value = self:parseObject()
|
value = self:parseObject()
|
||||||
|
|||||||
Reference in New Issue
Block a user