-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cbf7ae
commit 139f2d2
Showing
5 changed files
with
78 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Err, LexerError } from "ic10" | ||
|
||
export class TokenError extends Err { | ||
constructor(public error: LexerError) { | ||
//@ts-ignore | ||
super("", "tokenError", error.line.index, error.line.index, error.line.start, error.line.end) | ||
switch (this.error.type) { | ||
case "UNEXPECTED_TOKEN": | ||
if (this.error.expected === undefined) { | ||
this.message = `Unexpected token ${this.error.received}` | ||
break | ||
} else { | ||
if (this.error.expected.length > 1) { | ||
this.message = `Unexpected token ${this.error.received}, expected ${this.error.expected?.join(", ")}` | ||
break | ||
} else { | ||
this.message = `Unexpected token ${this.error.received}, expected ${this.error.expected[0]}` | ||
break | ||
} | ||
} | ||
case "MISSING_TOKEN": | ||
if (this.error.expected === undefined) { | ||
this.message = "Missing token" | ||
break | ||
} | ||
if (this.error.expected.length > 1) { | ||
this.message = `Missing tokens ${this.error.expected?.join(", ")}` | ||
break | ||
} else { | ||
this.message = `Missing token ${this.error.expected[0]}` | ||
break | ||
} | ||
case "UNRECOGNIZED_INSTRUCTION": | ||
const token = this.error.token?.value | ||
if (token === undefined) { | ||
this.message = "You can't use instruction in this place" | ||
} else { | ||
this.message = `You can't use ${this.error.token?.value} instruction in this place` | ||
} | ||
if (this.error.expected) { | ||
this.message += `, expected ${this.error.expected.join(", ")}` | ||
} | ||
break | ||
} | ||
|
||
if (this.error.suggested) { | ||
this.message += `, did you mean ${this.error.suggested}?` | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters