Skip to content

Commit

Permalink
Tidied up JSON Lua code so comments work better in Crimson Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Aug 30, 2010
1 parent a6559b8 commit bdb4fda
Show file tree
Hide file tree
Showing 19 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lua/json.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local decode = require("json.decode")
local encode = require("json.encode")
local util = require("json.util")
Expand Down
4 changes: 2 additions & 2 deletions lua/json/decode.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local lpeg = require("lpeg")
local error = error
Expand Down Expand Up @@ -110,7 +110,7 @@ Options:
object => object decode options
initialObject => whether or not to require the initial object to be a table/array
allowUndefined => whether or not to allow undefined values
]]
--]]
function getDecoder(mode)
mode = mode == true and strict or mode or default
local decoder = mode == nil and defaultDecoder or prebuilt_decoders[mode]
Expand Down
2 changes: 1 addition & 1 deletion lua/json/decode/array.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local lpeg = require("lpeg")
local util = require("json.decode.util")
Expand Down
2 changes: 1 addition & 1 deletion lua/json/decode/calls.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local lpeg = require("lpeg")
local tostring = tostring
local pairs, ipairs = pairs, ipairs
Expand Down
4 changes: 2 additions & 2 deletions lua/json/decode/number.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local lpeg = require("lpeg")
local tonumber = tonumber
local merge = require("json.util").merge
Expand Down Expand Up @@ -43,7 +43,7 @@ strict = {
frac: match fraction portion (.0)
exp: match exponent portion (e1)
DEFAULT: nan, inf, frac, exp
]]
--]]
local function buildMatch(options)
options = options and merge({}, defaultOptions, options) or defaultOptions
local ret = int
Expand Down
2 changes: 1 addition & 1 deletion lua/json/decode/object.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local lpeg = require("lpeg")
local util = require("json.decode.util")
Expand Down
2 changes: 1 addition & 1 deletion lua/json/decode/others.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local lpeg = require("lpeg")
local jsonutil = require("json.util")
local util = require("json.decode.util")
Expand Down
2 changes: 1 addition & 1 deletion lua/json/decode/strings.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local lpeg = require("lpeg")
local util = require("json.decode.util")
local merge = require("json.util").merge
Expand Down
2 changes: 1 addition & 1 deletion lua/json/decode/util.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local lpeg = require("lpeg")
local select = select
local pairs, ipairs = pairs, ipairs
Expand Down
10 changes: 5 additions & 5 deletions lua/json/encode.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local type = type
local assert, error = assert, error
local getmetatable, setmetatable = getmetatable, setmetatable
Expand All @@ -21,7 +21,7 @@ module("json.encode")
List of encoding modules to load.
Loaded in sequence such that earlier encoders get priority when
duplicate type-handlers exist.
]]
--]]
local modulesToLoad = {
"strings",
"number",
Expand Down Expand Up @@ -76,7 +76,7 @@ end
--[[
Encode a value with a given encoding map and state
]]
--]]
local function encodeWithMap(value, map, state)
local t = type(value)
local encoderList = assert(map[t], "Failed to encode value, unhandled type: " .. t)
Expand Down Expand Up @@ -110,7 +110,7 @@ end
Retreive an initial encoder instance based on provided options
the initial encoder is responsible for initializing state
State has at least these values configured: encode, check_unique, already_encoded
]]
--]]
function getEncoder(options)
options = options and util_merge({}, defaultOptions, options) or defaultOptions
local encode = getBaseEncoder(options)
Expand Down Expand Up @@ -147,7 +147,7 @@ end
encoder
check_unique -- used by inner encoders to make sure value is unique
already_encoded -- used to unmark a value as unique
]]
--]]
function encode(data, options)
return getEncoder(options)(data)
end
Expand Down
6 changes: 3 additions & 3 deletions lua/json/encode/array.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local jsonutil = require("json.util")
local type = type
Expand Down Expand Up @@ -31,7 +31,7 @@ strict = nil
is an array... may result in false positives (should check some values
before it)
* It is a contiguous list of values with zero string-based keys
]]
--]]
function isArray(val, options)
local externalIsArray = options and options.isArray
Expand Down Expand Up @@ -65,7 +65,7 @@ end
--[[
Cleanup function to unmark a value as in the encoding process and return
trailing results
]]
--]]
local function unmarkAfterEncode(tab, state, ...)
state.already_encoded[tab] = nil
return ...
Expand Down
4 changes: 2 additions & 2 deletions lua/json/encode/calls.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local jsonutil = require("json.util")
local table_concat = table.concat
Expand Down Expand Up @@ -30,7 +30,7 @@ strict = nil
Must have parameters in the 'callData' field of the metatable
name == name of the function call
parameters == array of parameters to encode
]]
--]]
function getEncoder(options)
options = options and util_merge({}, defaultOptions, options) or defaultOptions
local function encodeCall(value, state)
Expand Down
2 changes: 1 addition & 1 deletion lua/json/encode/number.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local tostring = tostring
local assert = assert
local util = require("json.util")
Expand Down
6 changes: 3 additions & 3 deletions lua/json/encode/object.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local pairs = pairs
local assert = assert
Expand All @@ -22,14 +22,14 @@ strict = nil
--[[
Cleanup function to unmark a value as in the encoding process and return
trailing results
]]
--]]
local function unmarkAfterEncode(tab, state, ...)
state.already_encoded[tab] = nil
return ...
end
--[[
Encode a table as a JSON Object ( keys = strings, values = anything else )
]]
--]]
local function encodeTable(tab, options, state)
-- Make sure this value hasn't been encoded yet
state.check_unique(tab)
Expand Down
2 changes: 1 addition & 1 deletion lua/json/encode/others.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local tostring = tostring
local assert = assert
Expand Down
4 changes: 2 additions & 2 deletions lua/json/encode/output.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local type = type
local assert, error = assert, error
local table_concat = table.concat
Expand All @@ -27,7 +27,7 @@ local TABLE_INNER_WRITER = ""
nextValues can output a max of two values to throw into the data stream
expected to be called until nil is first return value
value separator should either be attached to v1 or in innerValue
]]
--]]
local function defaultTableCompositeWriter(nextValues, beginValue, closeValue, innerValue, composite, encode, state)
if type(nextValues) == 'string' then
local fun = output_utility.prepareEncoder(defaultTableCompositeWriter, nextValues, innerValue, TABLE_VALUE_WRITER, TABLE_INNER_WRITER)
Expand Down
2 changes: 1 addition & 1 deletion lua/json/encode/output_utility.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local setmetatable = setmetatable
local assert, loadstring = assert, loadstring
Expand Down
2 changes: 1 addition & 1 deletion lua/json/encode/strings.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local string_char = string.char
local pairs = pairs
Expand Down
4 changes: 2 additions & 2 deletions lua/json/util.lua
@@ -1,7 +1,7 @@
--[[
Licensed according to the included 'LICENSE' document
Author: Thomas Harning Jr <harningt@gmail.com>
]]
--]]
local type = type
local print = print
local tostring = tostring
Expand Down Expand Up @@ -73,7 +73,7 @@ local ArrayMT = {}
Return's true if the metatable marks it as an array..
Or false if it has no array component at all
Otherwise nil to get the normal detection component working
]]
--]]
function IsArray(value)
if type(value) ~= 'table' then return false end
local ret = getmetatable(value) == ArrayMT
Expand Down

0 comments on commit bdb4fda

Please sign in to comment.