diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-11-16 17:57:40 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-11-16 17:58:45 +0800 |
commit | 4442a7ca616464d1fe2550b0c5794217c319cff3 (patch) | |
tree | c2ea1eab414f17f66b721f37cf896d91c6514c7d /src/json/decode.lua | |
parent | ee833ef51ed879b40aae1ce255a659e91d0b4781 (diff) | |
download | lua-language-server-4442a7ca616464d1fe2550b0c5794217c319cff3.zip |
修正解析json的BUG
Diffstat (limited to 'src/json/decode.lua')
-rw-r--r-- | src/json/decode.lua | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/json/decode.lua b/src/json/decode.lua index c220622d..42510cab 100644 --- a/src/json/decode.lua +++ b/src/json/decode.lua @@ -1,5 +1,6 @@ local lpeg = require 'lpeglabel' local save_sort +local table_pack = table.pack local P = lpeg.P local S = lpeg.S @@ -49,6 +50,15 @@ local hashmt = { rawset(self, i, k) rawset(self, k, v) end, + __debugger_extand = function (self) + local list = {} + for k, v in pairs(self) do + k = tostring(k) + list[#list+1] = k + list[k] = v + end + return list + end, } local tointeger = math.tointeger @@ -56,9 +66,12 @@ local tonumber = tonumber local setmetatable = setmetatable local rawset = rawset local function HashTable(patt) - return Ct(patt) / function (hash) + return C(patt) / function (_, ...) + local hash = table_pack(...) + local n = hash.n + hash.n = nil if save_sort then - local max = #hash // 2 + local max = n // 2 for i = 1, max do local key, value = hash[2*i-1], hash[2*i] hash[key] = value @@ -70,13 +83,13 @@ local function HashTable(patt) end return setmetatable(hash, hashmt) else - local max = #hash // 2 + local max = n // 2 for i = 1, max do local a = 2*i-1 local b = 2*i local key, value = hash[a], hash[b] hash[key] = value - hash[a] =nil + hash[a] = nil hash[b] = nil end return hash |