write prInt

This commit is contained in:
nora 2023-07-30 23:05:57 +02:00
parent d9868e3111
commit 7f65dc0277
8 changed files with 155 additions and 40 deletions

View file

@ -47,16 +47,17 @@ function renderError(input: string, e: CompilerError) {
throw Error(`Span out of bounds: ${e.span.start}..${e.span.end}`);
}
const lineIdx = lineSpans.indexOf(line);
const lineNo = lineIdx + 1;
console.error(`error: ${e.message}`);
console.error(`${lineIdx} | ${spanToSnippet(input, line)}`);
console.error(`${lineNo} | ${spanToSnippet(input, line)}`);
const startRelLine =
e.span.start === Number.MAX_SAFE_INTEGER ? 0 : e.span.start - line.start;
const spanLength = min(e.span.end, line.end) - e.span.start;
console.error(
`${" ".repeat(String(lineIdx).length)} ${" ".repeat(
`${" ".repeat(String(lineNo).length)} ${" ".repeat(
startRelLine
)}${"^".repeat(spanLength)}`
);