mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-15 00:45:04 +01:00
start implememting crate loading
This commit is contained in:
parent
a0599342ea
commit
b3b0bc2e6f
12 changed files with 249 additions and 165 deletions
|
|
@ -23,19 +23,19 @@ export class CompilerError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
export function withErrorHandler(input: string, f: () => void): void {
|
||||
export function withErrorPrinter(input: string, filename: string, f: () => void): void {
|
||||
try {
|
||||
f();
|
||||
} catch (e) {
|
||||
if (e instanceof CompilerError) {
|
||||
renderError(input, e);
|
||||
renderError(input, filename, e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function renderError(input: string, e: CompilerError) {
|
||||
function renderError(input: string, filename: string, e: CompilerError) {
|
||||
const lineSpans = lines(input);
|
||||
const line =
|
||||
e.span.start === Number.MAX_SAFE_INTEGER
|
||||
|
|
@ -49,6 +49,8 @@ function renderError(input: string, e: CompilerError) {
|
|||
const lineIdx = lineSpans.indexOf(line);
|
||||
const lineNo = lineIdx + 1;
|
||||
console.error(`error: ${e.message}`);
|
||||
console.error(` --> ${filename}:${lineNo}`);
|
||||
|
||||
|
||||
console.error(`${lineNo} | ${spanToSnippet(input, line)}`);
|
||||
const startRelLine =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue