From e00d066f7a7cb1ffd8df94d90e16565c3dedeec7 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 14 Jul 2013 10:01:25 +0200 Subject: sync with Context as of 2013-07-14 --- lualibs-util-jsn.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lualibs-util-jsn.lua') 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) -- cgit v1.2.3