From 46a571be93eba5689afd19ea473d24ac82e3af65 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sun, 15 Mar 2026 11:05:56 +0000 Subject: [PATCH] Add error message for unhandled states and actions --- asm.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/asm.js b/asm.js index 9297868..5036c66 100644 --- a/asm.js +++ b/asm.js @@ -754,9 +754,15 @@ class Parser { *handle(src) { let action; for (const token of this.tokenizer.handle(src)) { - if (action = this.handlers[this.state](token)) { - yield action; + const handler = this.handlers[this.state]; + if (handler == undefined) { + console.error(`ERROR: Unhandled state ${this.state}`); + this.state = State.TOP; + continue; } + + if (action = handler(token)) + yield action; } } } @@ -955,8 +961,13 @@ export class Assembler { push(chunk) { const text = this.decoder.decode(chunk, { stream: true }); - for (const action of this.parser.handle(text)) - this.handlers[action.type](action); + for (const action of this.parser.handle(text)) { + const handler = this.handlers[action.type]; + if (handler == undefined) + console.error("ERROR: Unhandled action", action); + else + handler(action); + } } lookup_block(symbol) {