From 17c51ee6d8b26416fab1f058eea1059b3e32809c Mon Sep 17 00:00:00 2001 From: JJtan <95962077+JJtan2002@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:52:40 +0800 Subject: [PATCH] Add InvalidNumberError (#15) --- src/errors.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/errors.ts b/src/errors.ts index 422a859..537a322 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -84,6 +84,19 @@ export namespace TokenizerErrors { this.name = "NonFourIndentError"; } } + + export class InvalidNumberError extends BaseTokenizerError { + constructor(line: number, col: number, source: string, start: number, current: number) { + let msg = getFullLine(source, start) + "\n"; + let hint = `^ Invalid Number input.`; + const diff = (current - start); + // +1 because we want the arrow to point after the string (where we expect the closing ") + hint = hint.padStart(hint.length + diff - MAGIC_OFFSET + 1, "~"); + hint = hint.padStart(hint.length + col - diff, " "); + super(msg + hint, line, col); + this.name = "InvalidNumberError"; + } + } export class InconsistentIndentError extends BaseTokenizerError { constructor(line: number, col: number, source: string, start: number) {