something's rotten in the state of vermiparous

This commit is contained in:
Theis Pieter Hollebeek 2025-10-10 21:46:08 +02:00
parent 35af0d5847
commit 46d1fc128c

View File

@ -1,5 +1,6 @@
const KEYWORDS = ["asset", "code"]; const KEYWORDS = ["asset", "code"];
const MIN_KW_LENGTH = Math.min(...KEYWORDS.map((x) => x.length)); const MIN_KW_LENGTH = Math.min(...KEYWORDS.map((x) => x.length));
const MAX_KW_LENGTH = Math.max(...KEYWORDS.map((x) => x.length));
const SEMICOLON_CHARCODE = ";".charCodeAt(0); const SEMICOLON_CHARCODE = ";".charCodeAt(0);
function isKeyword(buffer) { function isKeyword(buffer) {
@ -15,7 +16,6 @@ export class Vermiparous {
static en(code, assets) { static en(code, assets) {
const ret = []; const ret = [];
for (const asset of assets) { for (const asset of assets) {
console.log(asset);
ret.push(...strToBytes("asset")); ret.push(...strToBytes("asset"));
ret.push(...strToBytes(asset.name.length.toString())); ret.push(...strToBytes(asset.name.length.toString()));
ret.push(...strToBytes(";")); ret.push(...strToBytes(";"));
@ -41,11 +41,10 @@ export class Vermiparous {
let idx = 0; let idx = 0;
while (idx < bytes.length) { while (idx < bytes.length) {
buffer.push(bytes[idx]); buffer.push(bytes[idx]);
if (buffer.length < MIN_KW_LENGTH) { if (buffer.length >= MAX_KW_LENGTH) {
++idx; throw new Error("unreachable: something went wrong !");
continue;
} }
if (!isKeyword(buffer)) { if (buffer.length < MIN_KW_LENGTH || !isKeyword(buffer)) {
++idx; ++idx;
continue; continue;
} }