From dd918cb316f254369c095f81294bcc5c4ee69b29 Mon Sep 17 00:00:00 2001 From: Roman Lukash <2893931+RomanLukash340@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:44:38 +0200 Subject: [PATCH] WIP --- simulator/src/jack/listener/error.listener.ts | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/simulator/src/jack/listener/error.listener.ts b/simulator/src/jack/listener/error.listener.ts index 38a6c6da9..88af922ed 100644 --- a/simulator/src/jack/listener/error.listener.ts +++ b/simulator/src/jack/listener/error.listener.ts @@ -1,4 +1,10 @@ -import { ErrorListener, NoViableAltException, RecognitionException, Recognizer, Token } from "antlr4"; +import { + ErrorListener, + NoViableAltException, + RecognitionException, + Recognizer, + Token, +} from "antlr4"; import { JackCompilerError, LexerOrParserError } from "../error.js"; interface LexerNoViableAltException { startIndex: number; @@ -14,21 +20,28 @@ export class CustomErrorListener extends ErrorListener { msg: string, e: RecognitionException | undefined, ) => { - if (offendingSymbol != null || e != null && e.offendingToken != null) { - const t = offendingSymbol ?? e!.offendingToken as Token; + if (offendingSymbol != null || (e != null && e.offendingToken != null)) { + const t = offendingSymbol ?? (e!.offendingToken as Token); this.errors.push(new LexerOrParserError(line, t.start, t.stop + 1, msg)); } else if (e instanceof NoViableAltException) { - this.errors.push(new LexerOrParserError(line, e.startToken.start, e.startToken.stop + 1, msg)); - + this.errors.push( + new LexerOrParserError( + line, + e.startToken.start, + e.startToken.stop + 1, + msg, + ), + ); } //antlr doesn't provide a class for LexerNoViableAltException atm. Once https://github.com/antlr/antlr4/pull/4711 is release we can change it - else if (e != null && 'startIndex' in e) { + else if (e != null && "startIndex" in e) { const err = e as LexerNoViableAltException; - this.errors.push(new LexerOrParserError(line, err.startIndex, err.startIndex + 1, msg)); + this.errors.push( + new LexerOrParserError(line, err.startIndex, err.startIndex + 1, msg), + ); } else { console.error("Don't know how to handle this error"); throw new Error("Don't know how to handle this error"); } }; } -