Skip to content

Commit

Permalink
better parsing error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone committed Jan 19, 2024
1 parent a1ea483 commit ce0f859
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/cli/commands/typecheck.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync } from "fs";
import { unsafeParse } from "../../parser";
import { parse } from "../../parser";
import { typecheck } from "../../typecheck/typecheck";
import { typeErrorPPrint } from "../../typecheck/pretty-printer";
import { prelude } from "../../typecheck/prelude";
Expand All @@ -14,8 +14,15 @@ export function typecheckCmd(path: string) {
const f = readFileSync(path);

const src = f.toString();
const untyped = unsafeParse(src);
const [, errors] = typecheck(untyped, prelude);
const parseResult = parse(src);
if (!parseResult.ok) {
console.log(
`${FgRed}Parsing error:${Reset} ${parseResult.matchResult.message!}`,
);
return;
}

const [, errors] = typecheck(parseResult.value, prelude);

for (const error of errors) {
const msg = typeErrorPPrint(error);
Expand Down

0 comments on commit ce0f859

Please sign in to comment.