aboutsummaryrefslogtreecommitdiff
path: root/misctools
diff options
context:
space:
mode:
Diffstat (limited to 'misctools')
-rw-r--r--misctools/gen-unicode-table.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/misctools/gen-unicode-table.js b/misctools/gen-unicode-table.js
index 6ee02f5e8..cd46ac31c 100644
--- a/misctools/gen-unicode-table.js
+++ b/misctools/gen-unicode-table.js
@@ -117,6 +117,52 @@ function generateRangeTable(codePoints) {
return lines.join("\n");
}
+function generateBigSwitchStatement(codePoints) {
+ let lines = [];
+ let index = 0;
+ let latinOffset = 0;
+
+ while (latinOffset < codePoints.length && codePoints[latinOffset] <= 0xff) {
+ latinOffset++;
+ }
+
+ lines.push(`return switch(codepoint) {`);
+
+ // 16-bit code points
+ while (index < codePoints.length && codePoints[index] < 0x1000) {
+ let start = codePoints[index];
+ index++;
+ while (
+ index < codePoints.length &&
+ codePoints[index] < 0x1000 &&
+ codePoints[index] === codePoints[index - 1] + 1
+ ) {
+ index++;
+ }
+ let end = codePoints[index - 1];
+ lines.push(`0x${start.toString(16)}...0x${end.toString(16)},`);
+ }
+
+ // 32-bit code points
+ while (index < codePoints.length) {
+ let start = codePoints[index];
+ index++;
+ while (
+ index < codePoints.length &&
+ codePoints[index] === codePoints[index - 1] + 1
+ ) {
+ index++;
+ }
+ let end = codePoints[index - 1];
+ lines.push(` 0x${start.toString(16)}...0x${end.toString(16)},`);
+ }
+
+ lines.push(` => true,
+ else => false
+};`);
+ return lines.join("\n");
+}
+
fs.writeFileSync(
path.join(__dirname, "..", "src", "js_lexer", "unicode.zig"),
`// This file was automatically generated by ${path.basename(
@@ -134,5 +180,15 @@ pub const id_continue = ${generateRangeTable(idContinueES5OrESNext)}
pub const printable_id_start = ${generateRangeTable(idStartESNext)}
pub const printable_id_continue = ${generateRangeTable(idContinueESNext)}
+
+pub fn isIdentifierStart(comptime Codepoint: type, codepoint: Codepoint) bool{
+ ${generateBigSwitchStatement(idStartES5OrESNext)}
+}
+
+pub fn isIdentifierContinue(comptime Codepoint: type, codepoint: Codepoint) bool{
+ ${generateBigSwitchStatement(idContinueES5OrESNext)}
+}
+
+
`
);