base: fixes regression test lua path
[luajson.git] / lua / json / decode / others.lua
blob43ab82e58f2fa662d6b6219acb0c440e5e7b2215
1 --[[
2 Licensed according to the included 'LICENSE' document
3 Author: Thomas Harning Jr <harningt@gmail.com>
4 ]]
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,
22 null = jsonutil.null,
23 undefined = jsonutil.undefined
26 default = nil -- Let the buildCapture optimization take place
27 strict = {
28 allowUndefined = false
31 local function buildCapture(options)
32 options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions
33 local valueCapture = (
34 booleanCapture
35 + nullCapture * lpeg.Cc(options.null)
37 if options.allowUndefined then
38 valueCapture = valueCapture + undefinedCapture * lpeg.Cc(options.undefined)
39 end
40 return valueCapture
41 end
43 function load_types(options, global_options, grammar)
44 local capture = buildCapture(options)
45 util.append_grammar_item(grammar, "VALUE", capture)
46 end