Skip to content

Commit

Permalink
cleaned up error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
AjaniBilby committed May 20, 2024
1 parent dda114f commit 8689ae5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
11 changes: 9 additions & 2 deletions source/compiler/codegen/expression/helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as Syntax from "~/bnf/syntax.d.ts";
import { red } from "https://deno.land/[email protected]/fmt/colors.ts";

import { AssertUnreachable, LatentOffset } from "~/helper.ts";
import { BasePointerType, LinearType } from "~/compiler/codegen/expression/type.ts";
Expand Down Expand Up @@ -60,9 +61,15 @@ export function ResolveLinearType(ctx: Context, type: LinearType, ref: Reference
if (strict) {
const errs = type.getCompositionErrors();
if (errs) {
console.error(`Unable to compose value due to some arguments being uninitialized since: ${errs.map(x => x.start.toString()).join(", ")}\n`
const range = ref.clone();
for (const err of errs) {
range.span(err);
}

console.error(`${red("Error")}: Unable to compose value due to some arguments being uninitialized since: ${errs.map(x => x.start.toString()).join(", ")}\n`
+ errs.map(x => SourceView(ctx.file.path, ctx.file.name, x, true)).join("")
+ SourceView(ctx.file.path, ctx.file.name, ref, false)
+ SourceView(ctx.file.path, ctx.file.name, ref, true)
+ ` ${ctx.file.name} ${range.toString()}\n`
);

ctx.file.markFailure();
Expand Down
8 changes: 5 additions & 3 deletions source/compiler/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ import { File } from "~/compiler/file.ts"
export default class Package {
project: Project;
files: File[];
name: string;
cwd: string;

failed: boolean;

constructor(project: Project, base: string) {
constructor(project: Project, base: string, name: string = "~") {
this.project = project;
this.failed = false;
this.files = [];

this.name = name;
this.cwd = dirname(base);
}

import(filePath: string) {
const name = relative(this.cwd, filePath);
const data = Deno.readTextFileSync(filePath);
const file = new File(this, filePath, name, data);
const file = new File(this, filePath, `${this.name}/${relative(this.cwd, filePath)}`, data);
this.files.push(file);

return file;
Expand Down
4 changes: 2 additions & 2 deletions source/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ function SingleLine(path: string, name: string, range: ReferenceRange, compact?:
line = line.trimStart();
pad -= line.length;

const margin = `${range.start.line} │ `;
const margin = ` ${range.start.line} │ `;
const underline = "\n"
+ " ".repeat(margin.length + range.start.col - pad)
+ "^".repeat(Math.max(1, range.end.col - range.start.col))
+ "\n";

const body = margin + line + underline;
return compact ? body : ` ${name}: ${range.toString()}\n`;
return compact ? body : `${body} ${name}: ${range.toString()}\n`;
}

function MultiLine(path: string, name: string, range: ReferenceRange, compact?: boolean) {
Expand Down

0 comments on commit 8689ae5

Please sign in to comment.