Skip to content

Commit

Permalink
Upgraded Lua JSON to be compatible with new LPEG
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Jun 26, 2016
1 parent fc1dc73 commit b10833a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
6 changes: 3 additions & 3 deletions lua/json/decode/strings.lua
Expand Up @@ -107,12 +107,12 @@ local function generateLexer(options)
local escapeMatch = doSimpleSub
escapeMatch = escapeMatch + doXSub / decodeX
escapeMatch = escapeMatch + doUniSub / options.decodeUnicode
if options.additionalEscapes then
escapeMatch = escapeMatch + options.additionalEscapes
end
if options.escapeCheck then
escapeMatch = options.escapeCheck * escapeMatch + bad_escape
end
if options.additionalEscapes then
escapeMatch = options.additionalEscapes + escapeMatch
end
local captureString
for i = 1, #quotes do
local cap = buildCaptureString(quotes[i], options.badChars, escapeMatch)
Expand Down
11 changes: 0 additions & 11 deletions lua/json/decode/util.lua
Expand Up @@ -39,16 +39,6 @@ local function unexpected()
local msg = "unexpected character"
return build_report(msg)
end
local function expected(...)
local items = {...}
local msg
if #items > 1 then
msg = "expected one of '" .. table_concat(items, "','") .. "'"
else
msg = "expected '" .. items[1] .. "'"
end
return build_report(msg)
end
local function denied(item, option)
local msg
if option then
Expand Down Expand Up @@ -113,7 +103,6 @@ end

local util = {
unexpected = unexpected,
expected = expected,
denied = denied,
ascii_space = ascii_space,
unicode_space = unicode_space,
Expand Down
17 changes: 6 additions & 11 deletions lua/json/encode.lua
Expand Up @@ -53,17 +53,12 @@ for _,name in ipairs(modulesToLoad) do
loadedModules[name] = mod
end

-- Merges values, assumes all tables are arrays, inner values flattened, optionally constructing output
local function flattenOutput(out, values)
out = not out and {} or type(out) == 'table' and out or {out}
if type(values) == 'table' then
for _, v in ipairs(values) do
out[#out + 1] = v
end
else
out[#out + 1] = values
end
return out
-- NOTE: Nested not found, so assume unsupported until use case arises
local function flattenOutput(out, value)
assert(type(value) ~= 'table')
out = out or {}
out[#out + 1] = value
return out
end

-- Prepares the encoding map from the already provided modules and new config
Expand Down

0 comments on commit b10833a

Please sign in to comment.