diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2013-07-14 10:01:25 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2013-07-14 10:01:25 +0200 |
commit | e00d066f7a7cb1ffd8df94d90e16565c3dedeec7 (patch) | |
tree | c9893c780ccc05c8f5402b8bf09caf361cbeea86 /lualibs-util-jsn.lua | |
parent | f2f35fe3d8a1c5ce74ddbb8eef3cad2b18a379dc (diff) | |
download | lualibs-e00d066f7a7cb1ffd8df94d90e16565c3dedeec7.tar.gz |
sync with Context as of 2013-07-14
Diffstat (limited to 'lualibs-util-jsn.lua')
-rw-r--r-- | lualibs-util-jsn.lua | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lualibs-util-jsn.lua b/lualibs-util-jsn.lua index 29587cd..bbe25d8 100644 --- a/lualibs-util-jsn.lua +++ b/lualibs-util-jsn.lua @@ -42,8 +42,20 @@ local dquote = P('"') local whitespace = lpeg.patterns.whitespace local optionalws = whitespace^0 -local escape = C(P("\\u") / "0x" * S("09","AF","af")) / function(s) return utfchar(tonumber(s)) end -local jstring = dquote * Cs((escape + (1-dquote))^0) * dquote +local escapes = { + -- ["\\"] = "\\", -- lua will escape these + -- ["/"] = "/", -- no need to escape this one + ["b"] = "\010", + ["f"] = "\014", + ["n"] = "\n", + ["r"] = "\r", + ["t"] = "\t", +} + +local escape_un = C(P("\\u") / "0x" * S("09","AF","af")) / function(s) return utfchar(tonumber(s)) end +local escape_bs = P([[\]]) / "" * (P(1) / escapes) -- if not found then P(1) is returned i.e. the to be escaped char + +local jstring = dquote * Cs((escape_un + escape_bs + (1-dquote))^0) * dquote local jtrue = P("true") * Cc(true) local jfalse = P("false") * Cc(false) local jnull = P("null") * Cc(nil) |