Added support for \000 and \x00 style byte literals.
This commit is contained in:
parent
cd4196d365
commit
b2ddc1d768
13
nomsu.lua
13
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 = {
|
||||
|
@ -41,7 +41,10 @@ lpeg.setmaxstack 10000 -- whoa
|
||||
{:P,:R,:V,:S,:Cg,:C,:Cp,:B,:Cmt} = lpeg
|
||||
|
||||
STRING_ESCAPES = n:"\n", t:"\t", b:"\b", a:"\a", v:"\v", f:"\f", r:"\r"
|
||||
ESCAPE_CHAR = (P("\\")*S("ntbavfr")) / (s)->STRING_ESCAPES[s\sub(2,2)]
|
||||
DIGIT, HEX = R('09'), R('09','af','AF')
|
||||
ESCAPE_CHAR = (P("\\")*S("xX")*C(HEX*HEX)) / => string.char(tonumber(@, 16))
|
||||
ESCAPE_CHAR += (P("\\")*C(DIGIT*(DIGIT^-2))) / => string.char(tonumber @)
|
||||
ESCAPE_CHAR += (P("\\")*C(S("ntbavfr"))) / STRING_ESCAPES
|
||||
OPERATOR_CHAR = S("'~`!@$^&*-+=|<>?/")
|
||||
UTF8_CHAR = (
|
||||
R("\194\223")*R("\128\191") +
|
||||
@ -698,7 +701,7 @@ end)]])\format(concat(lua_bits, "\n"))
|
||||
return concat(bits, "\n")
|
||||
|
||||
@unescape_string: (str)=>
|
||||
str\gsub("\\(.)", ((c)-> STRING_ESCAPES[c] or c))
|
||||
Cs(((P("\\\\")/"\\") + (P("\\\"")/'"') + ESCAPE_CHAR + P(1))^0)\match(str)
|
||||
|
||||
@comma_separated_items: (open, items, close)=>
|
||||
bits = {open}
|
||||
|
Loading…
Reference in New Issue
Block a user