Use \x in assembly strings
This commit is contained in:
Родитель
aeef549d4d
Коммит
c98b868c8c
31
ast/lexer.ts
31
ast/lexer.ts
|
@ -154,19 +154,26 @@ module TDev.AST {
|
|||
case 'j': c = ''; break;
|
||||
case 'z': c = '\u0000'; break;
|
||||
case '_': c = '_'; break;
|
||||
case 'u':
|
||||
{
|
||||
var hex = input.slice(inputPos + len, inputPos + len + 4);
|
||||
var charCode = parseInt(hex, 16);
|
||||
if (isNaN(charCode)) {
|
||||
error("invalid unicode sequence");
|
||||
sb += "\\";
|
||||
} else {
|
||||
c = String.fromCharCode(charCode);
|
||||
len += 4;
|
||||
}
|
||||
break;
|
||||
case 'x':
|
||||
var hex = input.slice(inputPos + len, inputPos + len + 2);
|
||||
if (!/^[a-f0-9]+$/i.test(hex)) {
|
||||
error("invalid \\x sequence");
|
||||
sb += "\\";
|
||||
} else {
|
||||
c = String.fromCharCode(parseInt(hex, 16));
|
||||
len += 2;
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
var hex = input.slice(inputPos + len, inputPos + len + 4);
|
||||
if (!/^[a-f0-9]+$/i.test(hex)) {
|
||||
error("invalid unicode sequence");
|
||||
sb += "\\";
|
||||
} else {
|
||||
c = String.fromCharCode(parseInt(hex, 16));
|
||||
len += 4;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (/[A-Za-z0-9]/.test(c)) {
|
||||
error("invalid escape sequence");
|
||||
|
|
|
@ -629,7 +629,23 @@ module TDev.AST.Bytecode
|
|||
|
||||
stringLiteral(s:string)
|
||||
{
|
||||
return "\"" + s.replace(/\\/g, "\\\\").replace(/\"/g, "\\\"").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\u0000/g, "\\z") + "\""
|
||||
var r = "\""
|
||||
for (var i = 0; i < s.length; ++i) {
|
||||
// TODO generate warning when seeing high character ?
|
||||
var c = s.charCodeAt(i) & 0xff
|
||||
var cc = String.fromCharCode(c)
|
||||
if (cc == "\\" || cc == "\"")
|
||||
r += "\\" + cc
|
||||
else if (cc == "\n")
|
||||
r += "\\n"
|
||||
else if (c <= 0xf)
|
||||
r += "\\x0" + c.toString(16)
|
||||
else if (c < 32 || c > 127)
|
||||
r += "\\x" + c.toString(16)
|
||||
else
|
||||
r += cc;
|
||||
}
|
||||
return r + "\""
|
||||
}
|
||||
|
||||
emitString(s:string, needsSeqId = true):string
|
||||
|
|
Загрузка…
Ссылка в новой задаче