Skip to content

Commit ad7db61

Browse files
committed
Allow pretokenise decoder to decode raw strings - fix espruino/EspruinoWebIDE#297
1 parent a857e74 commit ad7db61

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

plugins/pretokenise.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,21 @@
225225
var ch = code.charCodeAt(i);
226226
if (needSpaceBetween(lastCh, ch))
227227
resultCode += " ";
228-
if (ch>=LEX_OPERATOR_START && ch<LEX_OPERATOR_START+TOKENS.length) {
229-
resultCode += TOKENS[ch-LEX_OPERATOR_START];
228+
if (ch>=LEX_OPERATOR_START) {
229+
if (ch==LEX_RAW_STRING8) { // decode raw strings
230+
var len = code.charCodeAt(i+1);
231+
resultCode += JSON.stringify(code.substring(i+2, i+2+len));
232+
i+=1+len;
233+
} else if (ch==LEX_RAW_STRING16) {
234+
var len = code.charCodeAt(i+1) | (code.charCodeAt(i+2)<<8);
235+
resultCode += JSON.stringify(code.substring(i+3, i+3+len));
236+
i+=2+len;
237+
} else if (ch<LEX_OPERATOR_START+TOKENS.length) // decoded other tokens
238+
resultCode += TOKENS[ch-LEX_OPERATOR_START];
239+
else {
240+
console.warn("Unexpected pretokenised string code:", ch);
241+
resultCode += code[i];
242+
}
230243
} else resultCode += code[i];
231244
lastCh = ch;
232245
}

0 commit comments

Comments
 (0)