2 Licensed according to the included 'LICENSE' document
3 Author: Thomas Harning Jr <harningt@gmail.com>
5 local lpeg
= require("lpeg")
7 local pairs
, ipairs
= pairs
, ipairs
8 local tonumber = tonumber
9 module("json.decode.util")
11 space
= lpeg
.S(" \n\r\t\f")
13 identifier
= lpeg
.R("AZ","az","__") * lpeg
.R("AZ","az", "__", "09") ^
0
15 hex
= lpeg
.R("09","AF","af")
19 cpp
= lpeg
.P("//") * (1 - lpeg
.P("\n"))^
0 * lpeg
.P("\n"),
20 c
= lpeg
.P("/*") * (1 - lpeg
.P("*/"))^
0 * lpeg
.P("*/")
23 comment
= comments
.cpp
+ comments
.c
25 ignored
= (space
+ comment
)^
0
27 VALUE
, TABLE
, ARRAY
= 2, 3, 4
30 for k
,v
in pairs(t
) do
36 function merge(t
, ...)
37 for i
= 1,select('#', ...) do
38 local currentTable
= select(i
, ...)
40 for k
,v
in pairs(currentTable
) do
51 for _
, v
in ipairs(inits
) do
56 -- Current depth is persistent
57 -- If more complex depth management needed, a new system would need to be setup
58 local currentDepth
= 0
60 function buildDepthLimit(limit
)
64 inits
[#inits
+ 1] = init
66 local function incDepth(s
, i
)
67 currentDepth
= currentDepth
+ 1
68 return currentDepth
< limit
and i
or false
70 local function decDepth(s
, i
)
71 currentDepth
= currentDepth
- 1
74 return {incDepth
, decDepth
}
78 -- Parse the lpeg version skipping patch-values
79 -- LPEG <= 0.7 have no version value... so 0.7 is value
80 DecimalLpegVersion
= lpeg
.version
and tonumber(lpeg
.version():match("^(%d+%.%d+)")) or 0.7