From 000f17b97e85380266f979afd6b0f02c67f7bcb1 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 23 Jul 2023 21:49:52 +0200 Subject: [PATCH] some cleanup --- src/__snapshots__/lexer.test.ts.snap | 18 +++++++++--------- src/ast.ts | 12 ++++++------ src/index.ts | 6 +----- src/lexer.test.ts | 2 +- src/resolve.ts | 10 +++++----- src/typeck.ts | 4 ---- 6 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/__snapshots__/lexer.test.ts.snap b/src/__snapshots__/lexer.test.ts.snap index dbb7117..e4a93be 100644 --- a/src/__snapshots__/lexer.test.ts.snap +++ b/src/__snapshots__/lexer.test.ts.snap @@ -3,7 +3,7 @@ exports[`should tokenize an emtpy function 1`] = ` [ { - "kind": "kw_function", + "kind": "function", "span": { "end": 8, "start": 0, @@ -18,31 +18,31 @@ exports[`should tokenize an emtpy function 1`] = ` }, }, { - "kind": "p_popen", + "kind": "(", "span": { "end": 15, "start": 14, }, }, { - "kind": "p_pclose", + "kind": ")", "span": { "end": 16, "start": 15, }, }, { - "kind": "p_bopen", + "kind": "=", "span": { "end": 18, "start": 17, }, }, { - "kind": "p_bclose", + "kind": ";", "span": { - "end": 19, - "start": 18, + "end": 20, + "start": 19, }, }, ] @@ -59,7 +59,7 @@ exports[`should tokenize hello world 1`] = ` }, }, { - "kind": "p_popen", + "kind": "(", "span": { "end": 6, "start": 5, @@ -74,7 +74,7 @@ exports[`should tokenize hello world 1`] = ` "value": "hello world", }, { - "kind": "p_pclose", + "kind": ")", "span": { "end": 20, "start": 19, diff --git a/src/ast.ts b/src/ast.ts index 750f7e0..3e050fb 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -266,16 +266,16 @@ export type Folder = { export const DEFAULT_FOLDER: Folder = { item(item) { - return super_fold_item(item, this); + return superFoldItem(item, this); }, expr(expr) { - return super_fold_expr(expr, this); + return superFoldExpr(expr, this); }, ident(ident) { return ident; }, type(type) { - return super_fold_type(type, this); + return superFoldType(type, this); }, }; @@ -283,7 +283,7 @@ export function fold_ast(ast: Ast, folder: Folder): Ast { return ast.map((item) => folder.item(item)); } -export function super_fold_item(item: Item, folder: Folder): Item { +export function superFoldItem(item: Item, folder: Folder): Item { switch (item.kind) { case "function": { const args = item.node.args.map(({ name, type, span }) => ({ @@ -307,7 +307,7 @@ export function super_fold_item(item: Item, folder: Folder): Item { } } -export function super_fold_expr(expr: Expr, folder: Folder): Expr { +export function superFoldExpr(expr: Expr, folder: Folder): Expr { const span = expr.span; switch (expr.kind) { case "empty": { @@ -373,7 +373,7 @@ export function super_fold_expr(expr: Expr, folder: Folder): Expr { } } -export function super_fold_type(type: Type, folder: Folder): Type { +export function superFoldType(type: Type, folder: Folder): Type { const span = type.span; switch (type.kind) { case "ident": { diff --git a/src/index.ts b/src/index.ts index 10d9796..09cd0c9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,11 +7,7 @@ import { typeck } from "./typeck"; const input = ` function main() = ( - let a = 0 in - let b = a in - let c = b in - let d = c in - d; + let true = false in print(true) ); `; diff --git a/src/lexer.test.ts b/src/lexer.test.ts index 086ca7b..69c62e4 100644 --- a/src/lexer.test.ts +++ b/src/lexer.test.ts @@ -1,7 +1,7 @@ import { tokenize } from "./lexer"; it("should tokenize an emtpy function", () => { - const input = `function hello() = {}`; + const input = `function hello() = ;`; const tokens = tokenize(input); diff --git a/src/resolve.ts b/src/resolve.ts index 4a4ec15..32244a6 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -5,8 +5,8 @@ import { Identifier, Resolution, fold_ast, - super_fold_expr, - super_fold_item, + superFoldExpr, + superFoldItem, } from "./ast"; import { CompilerError } from "./error"; @@ -87,7 +87,7 @@ export function resolve(ast: Ast): Ast { item.node.returnType && this.type(item.node.returnType); item.node.args.forEach(({ name }) => scopes.push(name)); - const body = super_fold_expr(item.node.body, this); + const body = superFoldExpr(item.node.body, this); item.node.args.forEach(({ name }) => popScope(name)); return { @@ -104,7 +104,7 @@ export function resolve(ast: Ast): Ast { } } - return super_fold_item(item, this); + return superFoldItem(item, this); }, expr(expr) { if (expr.kind === "let") { @@ -124,7 +124,7 @@ export function resolve(ast: Ast): Ast { }; } - return super_fold_expr(expr, this); + return superFoldExpr(expr, this); }, ident(ident) { const res = resolveIdent(ident); diff --git a/src/typeck.ts b/src/typeck.ts index bce1afd..437dcb4 100644 --- a/src/typeck.ts +++ b/src/typeck.ts @@ -1,4 +1,3 @@ -import { check } from "prettier"; import { Ast, COMPARISON_KINDS, @@ -6,7 +5,6 @@ import { EQUALITY_KINDS, Expr, ExprBinary, - ExprCall, ExprUnary, Folder, Identifier, @@ -14,11 +12,9 @@ import { Resolution, Ty, TyFn, - TyVar, Type, binaryExprPrecedenceClass, fold_ast, - super_fold_expr, } from "./ast"; import { CompilerError, Span } from "./error"; import { printTy } from "./printer";