From 672a453f6cfe71891290496d6a7fcbe84b43e04b Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Tue, 10 Mar 2026 17:53:58 +0000 Subject: [PATCH] Add string support to tokenizer --- asm.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/asm.js b/asm.js index 9cdb05e..a6683fd 100644 --- a/asm.js +++ b/asm.js @@ -9,9 +9,11 @@ class Tokenizer { constructor() { this.delims = new Set([" ", "\r", "\n", "\t"]); this.skips = new Set([" ", "\r", "\t"]); - this.comment_start = ";" + this.comment_start = ";"; + this.string_quote = '"'; this.buffer = []; this.comment = false; + this.string = false; } skip() { @@ -19,11 +21,31 @@ class Tokenizer { this.buffer = idx == -1 ? [] : this.buffer.slice(idx); } + next_string() { + const idx = this.buffer.findIndex((cp) => cp == this.string_quote); + if (idx == -1) { + this.string = true; + } else { + const string = this.buffer.slice(0, idx).join(""); + this.buffer = this.buffer.slice(idx + 1); + this.string = false; + return { string: string }; + } + } + next() { + if (this.string) + return this.next_string(); + this.skip(); if (this.buffer[0] == LINE_END) return this.buffer.shift(); + if (this.buffer[0] == this.string_quote) { + this.buffer.shift(); + return this.next_string(); + } + const idx = this.buffer.findIndex((cp) => this.delims.has(cp)); if (idx != -1) { const token = this.buffer.slice(0, idx).join("");