some cleanup

This commit is contained in:
nora 2023-07-23 21:49:52 +02:00
parent 5c6ade6cbb
commit 000f17b97e
6 changed files with 22 additions and 30 deletions

View file

@ -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,

View file

@ -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": {

View file

@ -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)
);
`;

View file

@ -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);

View file

@ -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);

View file

@ -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";