aboutsummaryrefslogtreecommitdiff
path: root/nomsu.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-03 17:23:46 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-03 17:23:46 -0800
commitb2ddc1d7687591b4cbc686d274cf3b1f67c3ce1e (patch)
tree7e74997e30b29c639d6bc8b3f420dcd94e57e17e /nomsu.lua
parentcd4196d36553530eac385dd909426509fa9aaeec (diff)
Added support for \000 and \x00 style byte literals.
Diffstat (limited to 'nomsu.lua')
-rw-r--r--nomsu.lua13
1 files changed, 8 insertions, 5 deletions
diff --git a/nomsu.lua b/nomsu.lua
index a0be840..d902f61 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -45,9 +45,14 @@ local STRING_ESCAPES = {
f = "\f",
r = "\r"
}
-local ESCAPE_CHAR = (P("\\") * S("ntbavfr")) / function(s)
- return STRING_ESCAPES[s:sub(2, 2)]
+local DIGIT, HEX = R('09'), R('09', 'af', 'AF')
+local ESCAPE_CHAR = (P("\\") * S("xX") * C(HEX * HEX)) / function(self)
+ return string.char(tonumber(self, 16))
end
+ESCAPE_CHAR = ESCAPE_CHAR + ((P("\\") * C(DIGIT * (DIGIT ^ -2))) / function(self)
+ return string.char(tonumber(self))
+end)
+ESCAPE_CHAR = ESCAPE_CHAR + ((P("\\") * C(S("ntbavfr"))) / STRING_ESCAPES)
local OPERATOR_CHAR = S("'~`!@$^&*-+=|<>?/")
local UTF8_CHAR = (R("\194\223") * R("\128\191") + R("\224\239") * R("\128\191") * R("\128\191") + R("\240\244") * R("\128\191") * R("\128\191") * R("\128\191"))
local IDENT_CHAR = R("az", "AZ", "09") + P("_") + UTF8_CHAR
@@ -1395,9 +1400,7 @@ end)]]):format(concat(lua_bits, "\n"))
local self = _class_0
self.def_number = 0
self.unescape_string = function(self, str)
- return str:gsub("\\(.)", (function(c)
- return STRING_ESCAPES[c] or c
- end))
+ return Cs(((P("\\\\") / "\\") + (P("\\\"") / '"') + ESCAPE_CHAR + P(1)) ^ 0):match(str)
end
self.comma_separated_items = function(self, open, items, close)
local bits = {