/** * Copyright (c) 2026 The xterm.js authors. All rights reserved. * @license MIT */ // @ts-check import { writeFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; const __dirname = dirname(fileURLToPath(import.meta.url)); const root = join(__dirname, '..'); // Import compiled transition table const { VT500_TRANSITION_TABLE } = await import(join(root, 'out/common/parser/EscapeSequenceParser.js')); const table = VT500_TRANSITION_TABLE.table; let out = '/* Auto-generated by bin/gen_parser_transition_table.mjs - do not edit */\n'; out += `#ifndef PARSER_TRANSITION_TABLE_H\n#define PARSER_TRANSITION_TABLE_H\n\n`; out += `#include \n\n`; out += `#define PARSER_TABLE_SIZE ${table.length}\n\n`; out += `static const uint16_t PARSER_TRANSITION_TABLE[PARSER_TABLE_SIZE] = {\n`; for (let i = 0; i < table.length; i++) { if (i % 16 === 0) out += ' '; out += `0x${table[i].toString(16)}`; out += i < table.length - 1 ? ', ' : ''; if (i % 16 === 15) out += '\n'; } if (table.length % 16 !== 0) out += '\n'; out += `};\n\n#endif\n`; const headerPath = join(root, 'src/common/parser/wasm/transition_table.h'); writeFileSync(headerPath, out); console.info(`Wrote ${headerPath} (${table.length} entries)`);