Skip to content

Commit 17c51ee

Browse files
authored
Add InvalidNumberError (#15)
1 parent 0b7801a commit 17c51ee

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/errors.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ export namespace TokenizerErrors {
8484
this.name = "NonFourIndentError";
8585
}
8686
}
87+
88+
export class InvalidNumberError extends BaseTokenizerError {
89+
constructor(line: number, col: number, source: string, start: number, current: number) {
90+
let msg = getFullLine(source, start) + "\n";
91+
let hint = `^ Invalid Number input.`;
92+
const diff = (current - start);
93+
// +1 because we want the arrow to point after the string (where we expect the closing ")
94+
hint = hint.padStart(hint.length + diff - MAGIC_OFFSET + 1, "~");
95+
hint = hint.padStart(hint.length + col - diff, " ");
96+
super(msg + hint, line, col);
97+
this.name = "InvalidNumberError";
98+
}
99+
}
87100

88101
export class InconsistentIndentError extends BaseTokenizerError {
89102
constructor(line: number, col: number, source: string, start: number) {

0 commit comments

Comments
 (0)