strict ts + fixes

This commit is contained in:
Yura Dupyn 2026-02-07 14:57:01 +01:00
parent 1b406899e0
commit d45207342c
9 changed files with 15 additions and 12 deletions

View file

@ -1,3 +1,4 @@
// AI GENERATED
import { Expr, Pattern, ProductPattern, Literal, FieldAssignment, FieldPattern } from '../value';
export function exprToString(expr: Expr): string {

View file

@ -1,3 +1,4 @@
// AI GENERATED
import * as readline from 'readline';
import * as fs from 'fs';
import { parse, ParseError } from '../parser/parser';
@ -155,7 +156,6 @@ function getErrorMessage(err: ParseError): string {
case "UnicodeUnclosed": return "Unicode escape missing closing brace '}'.";
case "UnicodeOverflow": return `Unicode code point ${err.reason.value.toString(16)} is out of bounds.`;
}
return "Invalid escape sequence.";
// Context specific errors
case "ExpectedExpression": return "Expected an expression here.";

View file

@ -1,5 +1,4 @@
// src/debug/value_string.ts
// AI GENERATED
import { Value, Env, Closure, EnvFrame } from '../value';
import { exprToString, productPatternToString } from './expr_show';

View file

@ -1,3 +1,4 @@
// AI GENERATED
import { SourceText } from "./source_text";
import { Cursor, scanString, scanNumber } from "./cursor";
import { Result } from "../result";

View file

@ -147,16 +147,12 @@ export function scanNumber(cursor: Cursor): Result<{ value: number, span: Span }
const startNumberLocation = cursor.currentLocation();
let c: CodePoint;
// 1. Optional Sign
c = cursor.peek();
if (c === char("-")) {
if (cursor.peek() === char("-")) {
cursor.next();
}
// 2. Integer Part
c = cursor.peek();
const integerPartDigitCount = cursor.consumeWhile(isDigit);
if (integerPartDigitCount === 0) {
return Result.error({
@ -238,7 +234,10 @@ export function scanString(cursor: Cursor): Result<{ value: string, span: Span }
// 2. Escape Sequences
const escapeStart = cursor.currentLocation();
cursor.next(); // consume backslash
const escaped = cursor.peek();
if (cursor.eof()) {
return Result.error({ tag: "UnexpectedEOF", span: cursor.makeSpan(start) });
}
const escaped = cursor.peek() as CodePoint; // it can't be `undefined`
switch (escaped) {
case char('n'): value += '\n'; cursor.next(); break;

View file

@ -97,7 +97,7 @@ export type PatternStartToken =
function rawIdentifier(cursor: Cursor): string {
const start = cursor.currentIndex;
while (!cursor.eof()) {
const c = cursor.peek();
const c = cursor.peek() as CodePoint;
if (DELIMITER_SET.has(c) || isWhitespace(c)) {
break;

View file

@ -5,7 +5,7 @@ export type CodePointIndex = number; // index into array of code-points
export type CodePoint = number; // could also name it `UnicodeCodePoint`. Basically for `s: string` we have `s.codePointAt(i: index): char`.
export function char(c: string): CodePoint {
return c.codePointAt(0)
return c.codePointAt(0) as CodePoint;
}
export type CodePointRef = {

View file

@ -333,7 +333,7 @@ export function eval_start(program: Program, e: Expr): Result<Value> {
return Result.ok(eval_expr(program, Env.nil(), e));
} catch (err) {
if (typeof err === "object" && (err as any).kind === "RuntimeError") {
return Result.error(err.error as RuntimeError);
return Result.error((err as ThrownRuntimeError).error);
} else {
throw err;
}

View file

@ -9,6 +9,9 @@
"sourceMap": true,
"baseUrl": ".",
"outDir": "dist",
"strict": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"moduleResolution": "node",
"resolveJsonModule": true
}