mirror of https://github.com/rxi/json.lua.git
Renamed 'keyword' -> 'literal'
parent
83164fb45c
commit
3845cef229
18
json.lua
18
json.lua
|
@ -128,9 +128,9 @@ end
|
||||||
local space_chars = create_set(" ", "\t", "\r", "\n")
|
local space_chars = create_set(" ", "\t", "\r", "\n")
|
||||||
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
|
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
|
||||||
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
|
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
|
||||||
local keywords = create_set("true", "false", "null")
|
local literals = create_set("true", "false", "null")
|
||||||
|
|
||||||
local keyword_map = {
|
local literal_map = {
|
||||||
[ "true" ] = true,
|
[ "true" ] = true,
|
||||||
[ "false" ] = false,
|
[ "false" ] = false,
|
||||||
[ "null" ] = nil,
|
[ "null" ] = nil,
|
||||||
|
@ -254,13 +254,13 @@ local function parse_number(str, i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function parse_keyword(str, i)
|
local function parse_literal(str, i)
|
||||||
local x = next_char(str, i, delim_chars)
|
local x = next_char(str, i, delim_chars)
|
||||||
local word = str:sub(i, x - 1)
|
local word = str:sub(i, x - 1)
|
||||||
if not keywords[word] then
|
if not literals[word] then
|
||||||
decode_error(str, i, "invalid keyword '" .. word .. "'")
|
decode_error(str, i, "invalid literal '" .. word .. "'")
|
||||||
end
|
end
|
||||||
return keyword_map[word], x
|
return literal_map[word], x
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -341,9 +341,9 @@ local char_func_map = {
|
||||||
[ "8" ] = parse_number,
|
[ "8" ] = parse_number,
|
||||||
[ "9" ] = parse_number,
|
[ "9" ] = parse_number,
|
||||||
[ "-" ] = parse_number,
|
[ "-" ] = parse_number,
|
||||||
[ "t" ] = parse_keyword,
|
[ "t" ] = parse_literal,
|
||||||
[ "f" ] = parse_keyword,
|
[ "f" ] = parse_literal,
|
||||||
[ "n" ] = parse_keyword,
|
[ "n" ] = parse_literal,
|
||||||
[ "[" ] = parse_array,
|
[ "[" ] = parse_array,
|
||||||
[ "{" ] = parse_object,
|
[ "{" ] = parse_object,
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ test("numbers", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
test("keywords", function()
|
test("literals", function()
|
||||||
assert( json.decode("true") == true )
|
assert( json.decode("true") == true )
|
||||||
assert( json.encode(true) == "true" )
|
assert( json.encode(true) == "true" )
|
||||||
assert( json.decode("false") == false )
|
assert( json.decode("false") == false )
|
||||||
|
|
Loading…
Reference in New Issue