2 Licensed according to the included 'LICENSE' document
3 Author: Thomas Harning Jr <harningt@gmail.com>
5 local lpeg
= require("lpeg")
6 local jsonutil
= require("json.util")
7 local util
= require("json.decode.util")
9 -- Container module for other JavaScript types (bool, null, undefined)
10 module("json.decode.others")
12 -- For null and undefined, use the util.null value to preserve null-ness
13 local booleanCapture
=
14 lpeg
.P("true") * lpeg
.Cc(true)
15 + lpeg
.P("false") * lpeg
.Cc(false)
17 local nullCapture
= lpeg
.P("null")
18 local undefinedCapture
= lpeg
.P("undefined")
20 local defaultOptions
= {
21 allowUndefined
= true,
23 undefined
= jsonutil
.undefined
26 default
= nil -- Let the buildCapture optimization take place
28 allowUndefined
= false
31 local function buildCapture(options
)
32 options
= options
and jsonutil
.merge({}, defaultOptions
, options
) or defaultOptions
33 local valueCapture
= (
35 + nullCapture
* lpeg
.Cc(options
.null
)
37 if options
.allowUndefined
then
38 valueCapture
= valueCapture
+ undefinedCapture
* lpeg
.Cc(options
.undefined
)
43 function load_types(options
, global_options
, grammar
)
44 local capture
= buildCapture(options
)
45 util
.append_grammar_item(grammar
, "VALUE", capture
)